if (TaskUtils.getStartTime(published_task) == TaskUtils.getEndTime(published_task)) { if (logger.isWarnEnabled()) { logger.warn("diffProjections is setting a PUBLISHED task where the start time equals the end time " + new Date(TaskUtils.getStartTime(published_task)) + "\nPublished task -> " + published_task + "\n New task -> " + new_task);
if (published_task != null) { if (TaskUtils.getStartTime(published_task) == TaskUtils.getEndTime(published_task)) { if (logger.isWarnEnabled()) { logger.warn("diffProjections is setting a PUBLISHED task where the start time equals the end time " + new Date(TaskUtils.getStartTime(published_task)) + "\nPublished task -> " + published_task + "\n New task -> " + new_task); }
  protected Collection diffProjections(Schedule published_schedule, Schedule newtask_schedule, TimeSpan timespan) {    // Only diff new projections against published tasks during this TimeSpan    published_schedule = ScheduleUtils.trimObjectSchedule(published_schedule, timespan);    // Check for an empty schedule    if (newtask_schedule.isEmpty()) {      // Rescind any tasks that were not accounted for      if(logger.isDebugEnabled()) {        logger.debug("publishChangeProjection(), New Task Schedule empty: "+newtask_schedule);      }      Enumeration e = published_schedule.getAllScheduleElements();      while (e.hasMoreElements()) {        Task task = (Task) ((ObjectScheduleElement) e.nextElement()).getObject();	if(logger.isDebugEnabled()) {          logger.debug(printProjection("********** Removing task --> \n", task));	}        publishRemoveFromExpansion(task);      }      return Collections.EMPTY_LIST;    }    List add_tasks = new ArrayList();    // Remove from the published schedule of tasks  all tasks that occur BEFORE now but not overlapping now    // These historical tasks should not be changed    long now = dfPlugin.currentTimeMillis();    ObjectScheduleElement ose;    Iterator historical_tasks =        published_schedule.getEncapsulatedScheduleElements(TimeSpan.MIN_VALUE, now).iterator();    while (historical_tasks.hasNext()) {      ose = (ObjectScheduleElement)historical_tasks.next();      ((NewSchedule)published_schedule).removeScheduleElement(ose);    }    // Examine the new task and published task that straddle NOW    Task published_task = null;    Task new_task = null;    Collection c = newtask_schedule.getScheduleElementsWithTime(now);    if (!c.isEmpty()) {      ose = (ObjectScheduleElement)c.iterator().next();      new_task = (Task)ose.getObject();      ((NewSchedule)newtask_schedule).removeScheduleElement(ose);    }    c =  published_schedule.getScheduleElementsWithTime(now);    if (!c.isEmpty()) {      ose = (ObjectScheduleElement)c.iterator().next();      published_task = (Task)ose.getObject();      ((NewSchedule)published_schedule).removeScheduleElement(ose);    }    if (published_task != null && new_task != null) {      // Depending upon whether the rate is equal set the end time of the published task to the start or      // end time of the new task      Rate new_rate = getTaskUtils().getRate(new_task);      if (new_rate.equals(getTaskUtils().getRate(published_task))) {        // check end times not the same        synchronized ( new_task ) {          ((NewTask)published_task).setPreference(new_task.getPreference(AspectType.END_TIME));          if (TaskUtils.getStartTime(published_task) == TaskUtils.getEndTime(published_task)) {            if (logger.isWarnEnabled()) {              logger.warn("diffProjections is setting a PUBLISHED task where the start time equals the end time " +                  new Date(TaskUtils.getStartTime(published_task)) +                  "\nPublished task -> " + published_task + "\n New task -> " + new_task);            } // synch          }        }        if(logger.isDebugEnabled()) {          logger.debug( printProjection("extend old end", published_task));        }        dfPlugin.publishChange(published_task);      } else {        // check to make sure start_time is not before now        // long that is the maximum of now and the start_time        long when = Math.max(now, TaskUtils.getStartTime(new_task));        setEndTimePreference((NewTask) published_task, when);        if (TaskUtils.getStartTime(published_task) == TaskUtils.getEndTime(published_task)) {          if (logger.isWarnEnabled()) {            logger.warn("diffProjections is setting a PUBLISHED task where the start time equals the end time " +                new Date(TaskUtils.getStartTime(published_task)) +                "\nPublished task -> " + published_task + "\n New task -> " + new_task);          }        }        if(logger.isDebugEnabled()) {          logger.debug(printProjection("truncate old end 1", published_task));        }        dfPlugin.publishChange(published_task);        setStartTimePreference((NewTask) new_task, when);        if (TaskUtils.getStartTime(new_task) == TaskUtils.getEndTime(new_task)) {          if (logger.isWarnEnabled()) {            logger.warn("diffProjections is setting a NEW task where the start time equals the end time " +                new Date(TaskUtils.getStartTime(new_task)) +                "\nPublished task -> " + published_task + "\n New task -> " + new_task);          }        }        if(logger.isDebugEnabled()) {          logger.debug(printProjection("truncate new start 1", new_task));        }        add_tasks.add(new_task);      }    } else if (new_task != null) {      setStartTimePreference((NewTask) new_task, now);       if (TaskUtils.getStartTime(new_task) == TaskUtils.getEndTime(new_task)) {        if (logger.isWarnEnabled()) {          logger.warn("diffProjections is setting a NEW task where the start time equals the end time " +              new Date(TaskUtils.getStartTime(new_task)) +              "\nPublished task -> " + published_task + "\n New task -> " + new_task);        }      }      if(logger.isDebugEnabled()) {        logger.debug(printProjection("truncate new start 2", new_task));      }      add_tasks.add(new_task);    } else if (published_task != null) {      setEndTimePreference((NewTask) published_task, now);      if (TaskUtils.getStartTime(published_task) == TaskUtils.getEndTime(published_task)) {        if (logger.isWarnEnabled()) {          logger.warn("diffProjections is setting a PUBLISHED task where the start time equals the end time " +              new Date(TaskUtils.getStartTime(published_task)) +              "\nPublished task -> " + published_task + "\n New task -> " + new_task);        }      }      dfPlugin.publishChange(published_task);      if(logger.isDebugEnabled()) {        logger.debug(printProjection("truncate old end 2", published_task));      }    }    // 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.    // When start time of schedule is equal to TimeSpan.MIN_VALUE, schedule is empty    long start;    while (!newtask_schedule.isEmpty()) {      start = newtask_schedule.getStartTime();      ose = (ObjectScheduleElement)ScheduleUtils.getElementWithTime(newtask_schedule, start);      if (ose != null) {        new_task = (Task)ose.getObject();        ((NewSchedule)newtask_schedule).removeScheduleElement(ose);      }      else {        if(logger.isErrorEnabled()) {	  logger.error("publishChangeProjection(), Bad Schedule: "+newtask_schedule);	}        return Collections.EMPTY_LIST;      }      // Get overlapping schedule elements from start to end of new task      c = published_schedule.getScheduleElementsWithTime(start);      if (!c.isEmpty()) {        // change the task to look like new task        ose = (ObjectScheduleElement)c.iterator().next();        published_task = (Task)ose.getObject();        ((NewSchedule)published_schedule).removeScheduleElement(ose);        if(logger.isDebugEnabled()) {          logger.debug(" Comparing plublished task  "+dfPlugin.getTaskUtils().taskDesc(published_task)+              " with \n"+dfPlugin.getTaskUtils().taskDesc(new_task));        }        published_task = TaskUtils.changeTask(published_task, new_task);        if (TaskUtils.getStartTime(published_task) == TaskUtils.getEndTime(published_task)) {          if (logger.isWarnEnabled()) {            logger.warn("diffProjections is setting a PUBLISHED task where the start time equals the end time " +                new Date(TaskUtils.getStartTime(published_task)) +                "\nPublished task -> " + published_task + "\n New task -> " + new_task);          }        }        if (published_task != null) {          if(logger.isDebugEnabled()) {            logger.debug(printProjection("********** Replaced task with ---> \n", published_task));          }          dfPlugin.publishChange(published_task);        }      }      else {        // no task exists that covers this timespan, publish it        add_tasks.add(new_task);        if (TaskUtils.getStartTime(new_task) == TaskUtils.getEndTime(new_task)) {          if (logger.isWarnEnabled()) {            logger.warn("diffProjections is setting a NEW task where the start time equals the end time " +                new Date(TaskUtils.getStartTime(new_task)) +                "\nPublished task -> " + published_task + "\n New task -> " + new_task);          }        }      }    }    // Rescind any tasks that were not accounted for    Enumeration e = published_schedule.getAllScheduleElements();    while (e.hasMoreElements()) {      Task task = (Task) ((ObjectScheduleElement) e.nextElement()).getObject();      if(logger.isDebugEnabled()) {        logger.debug(printProjection("********** Removing task --> \n", task));      }      publishRemoveFromExpansion(task);    }    return add_tasks;  }