if (logger.isDebugEnabled() && debugAgent()) { logger.debug(inventoryPlugin.getSupplyType() + " Item: " +
if (logger.isInfoEnabled() && debugAgent()) { logger.info(inventoryPlugin.getSupplyType() + " Item: " +
  private void reconcilePredictions(Collection demandTasks, Collection committedPreds, String item) {    UnaryPredicate itemPred = new ItemPredicate(item);    List sortedTasks = filterItems(itemPred, demandTasks);    List sortedPreds = filterItems(itemPred, committedPreds);    if (! sortedPreds.isEmpty()) {      if (logger.isDebugEnabled() && debugAgent()) {        logger.debug(inventoryPlugin.getSupplyType() + " Item: " +                     taskUtils.getTaskItemName((Task) sortedPreds.get(0))                     + ": Number of tasks in the gap -->  Predictions:  "                     + sortedPreds.size()                     + " \t DemandTasks: " + sortedTasks.size());      }      // if there are no demand tasks, then remove the predictions cause we have nothing to reconcile against.      if (sortedTasks.isEmpty()) {        for (Iterator iterator = sortedPreds.iterator(); iterator.hasNext();) {          Task predTask = (Task) iterator.next();          if (logger.isDebugEnabled() && debugAgent()) {            logger.debug(inventoryPlugin.getSupplyType() + "Removing prediction for Item: " +                         taskUtils.getTaskItemName(predTask) + " end date " + taskUtils.getEndTime(predTask));          }          inventoryPlugin.publishRemove(predTask);        }      }    }    int i = 0;    int j = 0;    int size = sortedPreds.size();    int lastIndex = sortedTasks.size() -1;    for(i = 0; i <= lastIndex; i++) {      Task task = (Task) sortedTasks.get(i);      long endTime = taskUtils.getEndTime(task);      double quantity = 0.0;      long maxEndTime = endTime;      List taskPhasedValues = new ArrayList();      // let's try priming the task to except auxiliary queries      setAuxiliaryQueryOnTask(task);      ArrayList pUids = new ArrayList();      while (j < size) {        Task pred = (Task) sortedPreds.get(j);        long predEndTime = taskUtils.getEndTime(pred);        if (predEndTime > endTime && i < lastIndex) {          break;        }        PlanElement pe = pred.getPlanElement();        AllocationResult ar = pe.getEstimatedResult();        if (! ar.isSuccess()) {          // prediction failed no reconcilation needed          if (logger.isDebugEnabled()) {            logger.debug("Found a failed prediction, no reconcilation");          }          j++;          continue;        }        List phasedResults = ar.getPhasedAspectValueResults();        taskPhasedValues.addAll(phasedResults);        for (Iterator phaseIter = phasedResults.iterator(); phaseIter.hasNext();) {          AspectValue[] aspectValues = (AspectValue[]) phaseIter.next();          for (int l = 0; l < aspectValues.length; l++) {            AspectValue aspectValue = aspectValues[l];            switch (aspectValue.getAspectType()) {              case AspectType.QUANTITY:                quantity += aspectValue.getValue();                break;              case AspectType.END_TIME:                maxEndTime = Math.max(maxEndTime, aspectValue.longValue());                break;              default: logger.warn("Unexpected aspect type " + aspectValue.getAspectType());            }          }        }        pUids.add(pred.getUID().toString());        j++;      }      AspectValue[] rollup = { AspectValue.newAspectValue(AspectType.END_TIME, maxEndTime),                               AspectValue.newAspectValue(AspectType.QUANTITY, quantity)};      AllocationResult ar = new AllocationResult(1.0, true, rollup, taskPhasedValues);      // store the uid of the reconciled predictions on the actual task      // so that we can remove the predictions later if the actual task gets replanned.      for (int p = 0; p < pUids.size(); p++) {        String s = (String) pUids.get(p);        ar.addAuxiliaryQueryInfo(p, s);        if (logger.isDebugEnabled() && debugAgent()) {          logger.debug(inventoryPlugin.getSupplyType() + " add a aux query on the AR  " + j + " pred uid " + s +                       " task uid is " + task.getUID());        }      }      if (logger.isDebugEnabled() && debugAgent()) {        logger.debug(inventoryPlugin.getSupplyType() + " - Published new disposition on task " + task.getUID()                     + " end Time " + new Date(endTime) + " new quantity " + quantity + "\nOriginal data " +                     printTask(task) + " for ITEM "+ item);      }      if (task.getPlanElement() != null) {        if (logger.isDebugEnabled() && debugAgent()) {          logger.debug(inventoryPlugin.getSupplyType() + " - demand task has a plan element " + printTask(task));          inventoryPlugin.publishRemove(task.getPlanElement());        }      }      Disposition disp = inventoryPlugin.getPlanningFactory().createDisposition(task.getPlan(), task, ar);      inventoryPlugin.publishAdd(disp);    }  }