Exemplo n.º 1
0
 /**
  * Edits a title. Allows for both add and/or replacement. Disable add and/or replace with null;
  * you cannot disable both - you will get an error.
  *
  * @param wiki The wiki object to use
  * @param append Set to true to append text, set to false to prepend text. Newlines not
  *     automatically inserted. Param is ignored if <code>add</code> is null.
  * @param reason The edit summary to use
  * @param add The text to add. Optional param: set to null to disable.
  * @param replace The text to replace, as a regex. Optional param: set to null to disable
  * @param replacement The replacement text for anything matching <code>replace</code>. Ignored if
  *     replace is null.
  * @param titles Pages to edit
  * @return A list of titles we couldn't process.
  */
 public static ArrayList<String> edit(
     Wiki wiki,
     boolean append,
     String reason,
     String add,
     String replace,
     String replacement,
     ArrayList<String> titles) {
   ColorLog.fyi(wiki, "Preparing edit pages");
   ArrayList<Task> tl = new ArrayList<>();
   for (String s : titles)
     tl.add(
         new Task(s, null, reason) {
           public boolean doJob(Wiki wiki) {
             if (replace == null && add == null)
               return FError.printErrAndRet(
                   String.format("CAction: Add and replace in '%s' are null!. Skip.", title),
                   false);
             else if (replace == null) return WAction.addText(wiki, title, add, reason, append);
             else {
               if (replacement == null)
                 return FError.printErrAndRet(
                     String.format(
                         "CAction: Replace OP requested but replacement in '%s' is null!. Skip.",
                         title),
                     false);
               text = wiki.getPageText(title).replaceAll(replace, replacement);
               if (add != null) text = append ? text + add : add + text;
               return WAction.edit(wiki, title, text, reason, false);
             }
           }
         });
   return Task.toString(wiki.submit(tl, 3));
 }
Exemplo n.º 2
0
  public void run() {
    if (!checkRealizeable()) {
      System.out.println("Project is not realizeable, quitting");
      System.exit(1);
    }

    int t = 0;
    ArrayList<Task> active_tasks = findTaskWithIndegreeZero();
    System.out.println("---------------- Starting project from");
    for (Task task : active_tasks) {
      System.out.println(task.toString());
      task.start(t);
    }
    boolean finished = false;
    while (true) {

      ArrayList<Task> to_be_removed = new ArrayList<>();
      ArrayList<Task> to_be_added = new ArrayList<>();
      for (Task task : active_tasks) {

        if (task.isFinished(t)) {
          for (Edge edge : task.outEdges) {
            if (edge.w.tell_finished_prerequisite(t)) {
              to_be_added.add(edge.w);
            }
          }
          to_be_removed.add(task);
        }
      }
      active_tasks.removeAll(to_be_removed);
      active_tasks.addAll(to_be_added);
      int current_staff = 0;

      for (Task task : active_tasks) {
        current_staff += task.staff;
      }
      System.out.println("Current staff: " + Integer.toString(current_staff));

      if (active_tasks.size() == 0) {
        for (Task task : tasks) {
          if (task.finished_at == -1) {
            System.out.println("Task " + Integer.toString(task.id) + " was not able to finish!");
          }
        }
        break;
      }
      t++;
      System.out.println(" ");
      System.out.println("t: " + Integer.toString(t));
    }
    minimum_completion_time = t;
    System.out.println(
        "*** Shortest possible execution time is "
            + Integer.toString(minimum_completion_time)
            + " ***");

    setSlack();
  }
Exemplo n.º 3
0
 /**
  * Deletes pages. Maximum concurrent threads = 20.
  *
  * @param wiki The wiki object to use
  * @param reason The log summary to use
  * @param titles The page(s) to delete.
  * @return A list of pages we didn't delete.
  */
 public static ArrayList<String> delete(Wiki wiki, String reason, ArrayList<String> titles) {
   ColorLog.fyi(wiki, "Preparing to delete pages");
   ArrayList<Task> tl = new ArrayList<>();
   for (String s : titles)
     tl.add(
         new Task(s, null, reason) {
           public boolean doJob(Wiki wiki) {
             return WAction.delete(wiki, title, reason);
           }
         });
   return Task.toString(wiki.submit(tl, 20));
 }
Exemplo n.º 4
0
  @Override
  public String toString() {

    String tempString = "";

    int i = 0;
    for (Task task : this) {
      if (i != 0) tempString += ", ";
      tempString += "{" + task.toString() + "}";
      i++;
    }

    tempString = "LinkedTaskList{" + tempString + "}";

    return tempString;
  }
Exemplo n.º 5
0
  private void given(Task... tasks) {
    givenEmptyTodoMVCPage();
    StringBuilder jsStringBuilder =
        new StringBuilder("localStorage.setItem(\"todos-troopjs\", \"[");
    int i = 0;
    for (Task task : tasks) {
      String taskData = task.toString();
      if (i < tasks.length - 1) {
        jsStringBuilder.append(taskData).append(", ");
      } else if (i == tasks.length - 1) {
        jsStringBuilder.append(taskData);
      }
      i++;
    }
    jsStringBuilder.append("]\")");

    executeJavaScript(jsStringBuilder.toString());
    getWebDriver().navigate().refresh();
  }
Exemplo n.º 6
0
  private void updateTask(Task task) {
    boolean needUpdate = false;
    Task remote = new Task(task);
    try {
      dbAccessor.getDbObject(task, task.getUuid());
    } catch (InvalidKeyException e) {
      Log.d(TAG, "There are no local task " + task.getUuid());
      needUpdate = true;
    }
    if (!needUpdate && remote.getGlobalUpdated() > task.getGlobalUpdated()) {
      needUpdate = true;
      Log.d(TAG, "Local task is too old - " + task.getUuid());
    }

    if (needUpdate) {
      Log.d(TAG, "Should update task " + remote.getUuid());
      dbAccessor.setDbObject(remote);
    } else {
      Log.d(TAG, "Should NOT update task " + remote.getUuid());
      Log.d(TAG, "Local task - " + task.toString());
    }
  }
Exemplo n.º 7
0
 public String _toString() {
   if (runtime == null) return StringUtil.lastSubstring(super.toString(), ".") + "," + "<orphan>";
   else
     return StringUtil.lastSubstring(super.toString(), ".")
         + "--"
         + state
         + (sleepOn == null || sleepOn == this
             ? ""
             : " on "
                 + sleepOn
                 + (waitPack != null && waitPack.target != null ? "(waiting/locking)" : ""))
         + (state == State_SLEEPING ? " until " + wakeUpTime : "")
         + "--"
         + "context="
         + mainContext()
         + "--"
         + "next_task="
         + (nextTask != null ? nextTask.toString() : "<null>")
         + "--"
         + (currentContext == mainContext ? "" : "--currentContext=" + _currentContext())
         + (returnPort == null ? "" : "--return_port=" + returnPort)
         + (sendingPort == null ? "" : "--sending_port=" + sendingPort);
 }
Exemplo n.º 8
0
 public String info(String prefix_) {
   if (runtime == null)
     return StringUtil.lastSubstring(prefix_ + super.toString(), ".") + "," + "<orphan>";
   StringBuffer sb_ =
       new StringBuffer(
           prefix_
               + StringUtil.lastSubstring(super.toString(), ".")
               + ", "
               + state
               + (sleepOn == null || sleepOn == this
                   ? ""
                   : " on "
                       + sleepOn
                       + (waitPack != null && waitPack.target != null ? "(waiting/locking)" : ""))
               + (state == State_SLEEPING ? " until " + wakeUpTime : "")
               + "\n"
               + prefix_
               + "Context="
               + mainContext()
               + (mainContext == null ? ", " : "\n" + prefix_)
               + "Next_Task="
               + (nextTask != null ? nextTask.toString() : "<null>")
               + "\n");
   if (currentContext != mainContext)
     sb_.append(prefix_ + "CurrentContext: " + _currentContext() + "\n");
   if (returnPort != null) sb_.append(prefix_ + "return_port: " + returnPort + "\n");
   if (sendingPort != null) sb_.append(prefix_ + "sending_port: " + sendingPort + "\n");
   sb_.append(prefix_ + "Locks: " + locks());
   sb_.append(prefix_ + "#arrivals: " + totalNumEvents + "\n");
   sb_.append(prefix_ + "last_sleepOn: " + lastsleepon + "\n");
   sb_.append(
       prefix_
           + "last_wkUp_thread: "
           + (lastwakeupthread == null ? null : currentThread(lastwakeupthread))
           + "\n");
   return sb_.toString();
 }
Exemplo n.º 9
0
 public void printAllTasks() {
   for (Task task : tasks) {
     System.out.println(task.toString());
   }
 }