warn ("found task " + parent.getUID () + " verb " + parent.getVerb() + " that had no plan element.");
warn ("found task " + reservedParent.getUID () + " verb " + reservedParent.getVerb() + " that had no plan element.");
  protected void dealWithReservedTask (Task task, Task reservedTask) {    // preconditions    if (isReservedTask (task))      error ("arg - task "  + task.getUID () + " is a reserved task.");    if (!isReservedTask (reservedTask))      error ("arg - task "  + reservedTask.getUID () + " is not a reserved task.");    /** this is unnecessary now, since check done in processTasks */    /*    if (!ownWorkflow (reservedTask)) {    error ("huh? reserved task " + reservedTask.getUID () + " not a member of it's own workflow " + reservedTask.getWorkflow () +    "\nuids " + uidsWorkflow(reservedTask));    error ("assuming it will be removed -- returning.");    return;    }    */    NewWorkflow tasksWorkflow = (NewWorkflow) reservedTask.getWorkflow ();    if (tasksWorkflow == null) {      error ("huh? reservedTask " + reservedTask.getUID () + " workflow is null?");      return;    }    int numTasksBefore = numTasksInWorkflow (tasksWorkflow);    // real code starts here ---    Date best          = prefHelper.getBestDate (task);    Date reservedBest  = prefHelper.getBestDate (reservedTask);    long daysLeft      = (reservedBest.getTime()-best.getTime())/MILLIS_PER_DAY;    Date reservedReady = (Date) prepHelper.getIndirectObject (reservedTask, START);    long currentDays   = (reservedBest.getTime()-reservedReady.getTime())/MILLIS_PER_DAY;    if (isInfoEnabled ()) {      info (getName() + ".dealWithReservedTask - applying actual " + task.getUID () + " best " + best +            " to reserved " + reservedTask.getUID() + " reserved ready " + reservedReady + " to best " + reservedBest);      info ("\t" + reportContentTypes (task, reservedTask));    }    double factor = (double)daysLeft/(double)currentDays;    if (factor > 0) {      Asset deliveredAsset =          getTrimmedDirectObject (reservedTask.getDirectObject(), factor);      NewTask replacement =          (NewTask) expandHelper.makeSubTask (ldmf,                                              reservedTask.getPlan(),                                              reservedTask.getParentTaskUID(),                                              reservedTask.getVerb(),                                              reservedTask.getPrepositionalPhrases(),                                              deliveredAsset,                                              reservedTask.getPreferences(),                                              reservedTask.getPriority(),                                              reservedTask.getSource());      replacement.setContext(reservedTask.getContext());      if (isInfoEnabled ())        info ("Reserved task " + reservedTask.getUID () +              " current days " + currentDays +              " daysLeft " + daysLeft +              " replacing asset weights.");      if (isInfoEnabled ())        info ("on task " + replacement.getUID() + " replacing start prep date " + reservedReady +              " with " + best + " - also becomes early date for task.");      prepHelper.replacePrepOnTask (replacement,                                    prepHelper.makePrepositionalPhrase(ldmf,START,best));      prefHelper.replacePreference (replacement,                                    prefHelper.makeEndDatePreference(ldmf,                                                                     best,                                                                     reservedBest,                                                                     prefHelper.getLateDate(reservedTask)));      replacement.setWorkflow(tasksWorkflow);      tasksWorkflow.addTask (replacement);      publishAdd (replacement);      if (isInfoEnabled ()) {        info ("Publishing replacement " + replacement.getUID() + " in workflow "+ tasksWorkflow.getUID() +              " start " + best + " best " + reservedBest);      }      if (best.getTime () != ((Date)prepHelper.getIndirectObject(replacement, START)).getTime()) {        error ("replacement start " + prepHelper.getIndirectObject(replacement, START) + " != " + best);      }      if (!taskInWorkflow(replacement, tasksWorkflow)) {        error ("huh? after adding to workflow, replacement " + replacement.getUID () + " is not in workflow " + tasksWorkflow + "?");      }    }    else {      if (isInfoEnabled ())        info ("Removing reserved task " + reservedTask.getUID () + " since weight is zero. Days Left was " + daysLeft +              ", current days was " + currentDays + " parent was " + reservedTask.getParentTaskUID());    }    tasksWorkflow.removeTask (reservedTask);    publishRemove(reservedTask);    if (taskInWorkflow(reservedTask, tasksWorkflow))      error ("huh? after removing, reserved task " + reservedTask.getUID () + " is still a member of workflow " + tasksWorkflow);    int numTasksAfter = numTasksInWorkflow (tasksWorkflow);    if (numTasksAfter == 0) {      final Task reservedCopy = reservedTask;      if (isInfoEnabled ()) {        info ("looking for parent of task " + reservedTask.getUID () + " verb " + reservedTask.getVerb());      }      Collection parents = blackboard.query (new UnaryPredicate () {        public boolean execute (Object obj) {          if (obj instanceof Task) {            return (((Task) obj).getUID().equals (reservedCopy.getParentTaskUID()));          }          else return false;        }      }      );      if (!parents.isEmpty()) { // I guess if the task is being removed, the parent could be missing from the blackboard        Task parent = (Task) parents.iterator ().next();        PlanElement exp = parent.getPlanElement();        if (exp == null) {          if (isWarnEnabled ()) {            warn ("found task " + parent.getUID () + " verb " + parent.getVerb() + " that had no plan element.");          }        }        else {          publishRemove(exp);          if (isInfoEnabled ()) {            info ("removing expansion of task " + exp.getTask().getUID());          }          //	  AllocationResult ar = new AllocationResult(1.0, true, exp.getEstimatedResult().getAspectValueResults());          AllocationResult ar = makeSuccessfulDisposition(parent);          Disposition disposition =              ldmf.createDisposition(parent.getPlan(), parent, ar);          publishAdd (disposition);          if (isInfoEnabled ())            info (" task " + parent.getUID () + " verb " + parent.getVerb() + " - will get a DISPOSITION, since workflow now empty.");        }      }    }    if (factor < 0.00000001 && (numTasksAfter != numTasksBefore-1))      error ("Reserved task " + reservedTask.getUID() + "'s workflow had " + numTasksBefore + " should have " + (numTasksBefore-1) +             " but has " + numTasksAfter);    else if (factor > 0 && (numTasksAfter != numTasksBefore))      error ("Reserved task " + reservedTask.getUID() + "'s workflow had " + numTasksBefore + " != numTaskAfter, which is " + numTasksAfter);  }