rootplan.add(tsk);
if (tsk.beforeCommitment(currentDate())) { rootplan.add(tsk); } else if (logger.isInfoEnabled()) { logger.info("New task arrived past commitment date (" + tsk.getCommitmentDate() + "), not adding " + tsk); }
  public void execute(Directive dir, Collection changes) {    if (dir instanceof Task) {      Task tsk = (Task) dir;      try {        Task existingTask = logplan.findTask(tsk);        // We don't know about this task        if (existingTask == null) {          if (tsk.isDeleted()) {            // Ignore received deleted tasks            if (logger.isDebugEnabled()) {              logger.debug("Ignoring new, but deleted task from another node " + tsk.getUID());            }          } else {            // Add it to our blackboard            if (logger.isDebugEnabled()) {              logger.debug("Received new task from another node " + tsk.getUID());            }            rootplan.add(tsk);          }        } else if (tsk.isDeleted()) {          if (existingTask.isDeleted()) {            if (logger.isDebugEnabled()) {              logger.debug("Removing deleted task " + tsk.getUID());            }            rootplan.remove(existingTask); // Complete the removal          } else {            // Whoops! We must have restarted and reverted to a            // pre-deletion state.            if (logger.isDebugEnabled()) {              logger.debug("Received deleted task, but blackboard task is undeleted "                           + tsk.getUID());            }          }        } else if (tsk == existingTask) {          // This never happens any more because a new task is created          // for each transmission          if (logger.isWarnEnabled()) {            logger.warn("Received task instance already on blackboard " + tsk.getUID());          }          rootplan.change(existingTask, changes);        } else {          // Update task from received task          boolean changedTask = false;          Preference[] newPreferences = ((TaskImpl) tsk).getPreferencesAsArray();          Preference[] existingPreferences = ((TaskImpl) existingTask).getPreferencesAsArray();          if (logger.isDebugEnabled()) {            logger.debug("Comparing " + tsk);          }          if (!java.util.Arrays.equals(newPreferences, existingPreferences)) {            if (logger.isDebugEnabled()) {              logger.debug("Preferences differ "                           + newPreferences +                           "!="                           + existingPreferences);            }            ((NewTask) existingTask).setPreferences(tsk.getPreferences());            changedTask = true;          } else {            if (logger.isDebugEnabled()) {              logger.debug("Preferences compare equal "                           + newPreferences                           + "=="                           + existingPreferences);            }          }          for (Enumeration e = existingTask.getPrepositionalPhrases(); e.hasMoreElements(); ) {            existingPhrases.add(e.nextElement());          }          for (Enumeration e = tsk.getPrepositionalPhrases(); e.hasMoreElements(); ) {            newPhrases.add(e.nextElement());          }	  boolean match = false;	  if (newPhrases.size() == existingPhrases.size()) {	    for (Iterator existingIterator = existingPhrases.iterator();		 existingIterator.hasNext();) {	      Object existingPhrase = existingIterator.next();	      match = false;	      for (Iterator newIterator = newPhrases.iterator();		   newIterator.hasNext();) {		if (newIterator.next().equals(existingPhrase)) {		  match = true;		  break;		}	      }	      	      if (match == false) {		break;	      }	    }	  }		           if (!match) {            ((NewTask) existingTask).setPrepositionalPhrases(tsk.getPrepositionalPhrases());            changedTask = true;            if (logger.isDebugEnabled()) {              logger.debug("Phrases differ " + newPhrases + "!=" + existingPhrases);            }          } else {            if (logger.isDebugEnabled()) {              logger.debug("Phrases compare equal " + newPhrases + "==" + existingPhrases);            }          }                      existingPhrases.clear();          newPhrases.clear();          Context existingContext = existingTask.getContext();          Context tskContext = tsk.getContext();          if (logger.isWarnEnabled()) {            if (existingContext == null) {              logger.warn("existingTask has null context: " + existingTask);            }            if (tskContext == null) {              logger.warn("received Task has null context: " + tsk);            }          }          if (((existingContext != null) && !existingContext.equals(tskContext)) ||	      ((existingContext == null) && (tskContext != null))) {            ((NewTask) existingTask).setContext(tskContext);            changedTask = true;            if (logger.isDebugEnabled()) {              logger.debug("Contexts differ: "                           + tskContext                           + "!="                           + existingContext);            }          }          if (!existingTask.getVerb().equals(tsk.getVerb())) {            ((NewTask) existingTask).setVerb(tsk.getVerb());            changedTask = true;            if (logger.isDebugEnabled()) {              logger.debug("Verbs differ "                           + tsk.getVerb()                           + "!="                           + existingTask.getVerb());            }          }           if (changedTask) {            rootplan.change(existingTask, changes);          } else {            PlanElement pe = existingTask.getPlanElement();            if (pe != null) {	      if (logger.isDebugEnabled()) {		logger.debug("Unchanged task with PE. Check shouldDoNotification");	      }	      // Cause a notification / estAR to be (re)sent (see bug 3338)	      if (((PEforCollections)pe).shouldDoNotification()) {		if (logger.isDebugEnabled()) {		  logger.debug("Got PE.shouldDoNotification. Invoke NotificationLP to send the notification.");		}		NotificationLP.checkValues(pe, changes, rootplan, logplan, ldmf, self);	      } else {		if (logger.isDebugEnabled()) {		  logger.debug("Unchanged task, PE doesnt DoNotification. Do nothing (old would have done a pubChange). PE " + pe.getUID());		}	      }              //rootplan.change(pe, changes);	// Cause estimated result to be resent            }          }        }      } catch (SubscriberException se) {        logger.error("Could not add Task to LogPlan: " + tsk, se);      }    }  }