public static void replaceTask(JobPlan object, ObjectBroker Objbroker) throws IOException {
    String[] Patterns = consistencyUtils.getUpdatePattern(ProcessSpecificCLI.U_REPTASK);
    String OldValue = Patterns[0];
    String NewValue = Patterns[1];

    Iterator<JobPlanTask> TaskIt = object.taskIterator();
    while (TaskIt.hasNext()) {
      JobPlanTask oriTask = TaskIt.next();
      if (oriTask.getTaskName().contains(OldValue)) {

        String NewTaskName = oriTask.getTaskName().replace(OldValue, NewValue);
        // make sure its a valid object?

        boolean NewTaskexists = true;
        List<SearchResultItem> items = Objbroker.searches.searchObject(NewTaskName);
        if (items.isEmpty()) {
          System.out.println(
              " -- Error: Trying to replace with non-existant task: "
                  + NewTaskName
                  + " (Hint: Pattern for replacement may be incorrect?)");
          NewTaskexists = false;
        }
        if (NewTaskexists) {
          JobPlanTask jptask = Objbroker.jobPlans.getTaskFromName(NewTaskName);
          // [ Origin Task Type | Origin Task Name | Origin Task position ] => [ New Task Type | New
          // Task Name | New Task position ]
          System.out.println(
              "\t ++ UPDATE: Replace Task from JobPlan : "
                  + " [ "
                  + oriTask.getType()
                  + " | "
                  + oriTask.getTaskName()
                  + " | {"
                  + oriTask.getX()
                  + ","
                  + oriTask.getY()
                  + "} ] => "
                  + " [ "
                  + jptask.getType()
                  + " | "
                  + jptask.getTaskName()
                  + " | {"
                  + oriTask.getX()
                  + ","
                  + oriTask.getY()
                  + "} ]");
          object.replaceTask(oriTask, jptask);
        }
      }
    }
  }
 public static void addTask(JobPlan object, ObjectBroker Objbroker) throws IOException {
   List<SearchResultItem> items =
       Objbroker.searches.searchExecutableObjects(ProcessSpecificCLI.U_ADDTASK);
   if (items.isEmpty()) {
     System.out.println(" %% No Task Found Matching Pattern: " + ProcessSpecificCLI.U_ADDTASK);
   } else {
     for (int g = 0; g < items.size(); g++) {
       JobPlanTask jptask = Objbroker.jobPlans.getTaskFromName(items.get(g).getName());
       jptask.setX(g + 1);
       jptask.setY(2);
       System.out.println(
           "\t ++ UPDATE: Add Task to JobPlan: [ "
               + jptask.getTaskName()
               + " | "
               + jptask.getType()
               + " | {"
               + jptask.getX()
               + ","
               + jptask.getY()
               + "} ]");
       object.addTask(jptask);
       object.format();
     }
   }
 }
 public static void delTaskDepLatest(JobPlan object, ObjectBroker Objbroker) {
   ArrayList<JobPlanTask> selectedTasks = GetMatchingTaskList(object, Objbroker);
   for (int i = 0; i < selectedTasks.size(); i++) {
     JobPlanTask jptask = selectedTasks.get(i);
     jptask.dependencies().setAtTheLatest(false);
     System.out.println(
         "\t ++ UPDATE: Remove Latest Option on Task Dependency: [ {"
             + jptask.getTaskName()
             + "("
             + jptask.getLnr()
             + ") | "
             + jptask.getType()
             + " | {"
             + jptask.getX()
             + ","
             + jptask.getY()
             + "} ]");
   }
 }
  public static void removeTask(WorkflowLoop object, ObjectBroker Objbroker) {
    Iterator<JobPlanTask> TaskIt = object.iterator();
    ArrayList<JobPlanTask> TasksToRemove = new ArrayList<JobPlanTask>();

    while (TaskIt.hasNext()) {
      JobPlanTask task = TaskIt.next();
      try {
        if (task.getTaskName().matches(ProcessSpecificCLI.U_REMTASK)) {
          System.out.println(
              "\t ++ UPDATE: Remove Task from JobPlan: [ "
                  + task.getTaskName()
                  + " | "
                  + task.getType()
                  + " | {"
                  + task.getX()
                  + ","
                  + task.getY()
                  + "} ]");
          TasksToRemove.add(task);
          // object.removeTask(task);
        }
      } catch (PatternSyntaxException e) {
        System.out.println(
            " -- Internal Error. The Regular Expression Used for one of the Filters is invalid - See Error Below: "
                + e.getDescription());
        System.out.println("\t\t" + e.toString());
        System.out.println(
            " %% HINT: '*' and '+' are NOT valid Regular Expressions on their own. '*' marks '0 or more' and '+' marks '1 or more', but you need to specify a preceeding character or string");
        System.out.println(
            " %% HINT: Ex: invalid expressions: '*ABC*', '*.123', '+DEF'. Valid expressions: '.*ABC.*', '.*.123', '.+DEF' ");

        System.exit(999);
      }
    }
    // seems like the for loop below could have been included in the while loop above? it cant
    // because it creates a problem of concurrence of requests (due to the fact that the removeTask
    // method uses also an iterator!!)
    for (int j = 0; j < TasksToRemove.size(); j++) {
      object.removeTask(TasksToRemove.get(j));
    }
  }
  public static void addTaskAtPosition(JobPlan object, ObjectBroker Objbroker) throws IOException {

    String[] RawVals = ProcessSpecificCLI.U_ADDTASKATPOSITION.split(","); // splits ["TASK","1","2"]
    String TaskName = RawVals[0].replace("[", "");
    String PosX = RawVals[1];
    int iPosX = Integer.parseInt(PosX);
    String PosY = RawVals[2].replace("]", "");
    int iPosY = Integer.parseInt(PosY);
    System.out.println(" ++ Adding Task: " + TaskName + " at: [" + iPosX + "," + iPosY + "]");
    JobPlanTask jptask = Objbroker.jobPlans.getTaskFromName(TaskName);
    jptask.setX(iPosX);
    jptask.setY(iPosY);
    System.out.println(
        "\t ++ UPDATE: Add Task to JobPlan: [ "
            + jptask.getTaskName()
            + " | "
            + jptask.getType()
            + " | {"
            + jptask.getX()
            + ","
            + jptask.getY()
            + "} ]");
    object.addTask(jptask);
  }