LogisticsInventoryPG thePG = (LogisticsInventoryPG)inv. searchForPropertyGroup(LogisticsInventoryPG.class);
  public void compareRefillProjections(ArrayList newRefillProjs,                                        ArrayList oldRefillProjs,                                       Inventory inv) {    // Check for an empty schedule    if ((newRefillProjs == null) || newRefillProjs.isEmpty()) {      // Rescind any tasks that were not accounted for      logger.debug("publishChangeProjection(), New Task List empty: "+newRefillProjs);      Iterator list  = oldRefillProjs.iterator();      while (list.hasNext()) {        Task oldRefill = (Task)list.next();        logger.debug("DIFF ********** Removing task --> \n"+getTaskUtils().taskDesc(oldRefill));        if (oldRefill != null) {	  // clean out the reference in the maintain inventory workflow	  ((NewWorkflow)oldRefill.getWorkflow()).removeTask(oldRefill);          inventoryPlugin.publishRemove(oldRefill);        }      }      return;    }    Schedule publishedSchedule = getTaskUtils().newObjectSchedule(oldRefillProjs);    Schedule newTaskSchedule = getTaskUtils().newObjectSchedule(newRefillProjs);    // Compare new tasks to previously scheduled tasks, if a published task is found that    // spans the new task's start time then adjust the published task (if needed) and publish    // the change.  If no task is found than add new_task to list of tasks to be published.    long start;    Task new_task=null, published_task=null;    ObjectScheduleElement ose=null;    Collection c=null;    while (!newTaskSchedule.isEmpty()) {      start = newTaskSchedule.getStartTime();      ose = (ObjectScheduleElement)ScheduleUtils.getElementWithTime(newTaskSchedule, start);      if (ose != null) {        new_task = (Task)ose.getObject();        ((NewSchedule)newTaskSchedule).removeScheduleElement(ose);      }      else {        logger.error("publishChangeProjection(), Bad Schedule: "+newTaskSchedule);        return;      }      // Get overlapping schedule elements from start to end of new task      c = publishedSchedule.getScheduleElementsWithTime(start);      if (!c.isEmpty()) {        // change the task to look like new task        ose = (ObjectScheduleElement)c.iterator().next();        published_task = (Task)ose.getObject();        ((NewSchedule)publishedSchedule).removeScheduleElement(ose);        logger.debug(" Comparing plublished task  "+getTaskUtils().taskDesc(published_task)+                     " with \n"+getTaskUtils().taskDesc(new_task));        published_task = getTaskUtils().changeTask(published_task, new_task);        if (published_task != null) {          logger.debug("DIFF ********** Replaced task with ---> \n"+ getTaskUtils().taskDesc(published_task));          inventoryPlugin.publishChange(published_task);        }      }      else {        // no task exists that covers this timespan, publish it        // apply the Task to the LogisticsInventoryBG        logger.debug("No task exists that covers this timespan, publish task "+                     getTaskUtils().taskDesc(new_task));        LogisticsInventoryPG thePG = (LogisticsInventoryPG)inv.          searchForPropertyGroup(LogisticsInventoryPG.class);        thePG.addRefillProjection(new_task);        // hook the task in with the MaintainInventory workflow and publish        inventoryPlugin.publishRefillTask(new_task, inv);      }    }    // Rescind any tasks that were not accounted for    Enumeration e = publishedSchedule.getAllScheduleElements();    while (e.hasMoreElements()) {      Task task = (Task) ((ObjectScheduleElement) e.nextElement()).getObject();      logger.debug("DIFF ********** Removing task --> \n"+getTaskUtils().taskDesc(task));      ((NewWorkflow)task.getWorkflow()).removeTask(task);      inventoryPlugin.publishRemove(task);    }  }