while (defPhasesIt.hasNext()) { AllocPhase currentPhase = (AllocPhase) defPhasesIt.next(); if (currentPhase.startBucket > lastBucket) {   long lastTime = thePG.convertBucketToTime(lastBucket); AllocPhase betweenPhase = new AllocPhase(lastBucket, getBestBucketQty(lastTime)); betweenPhase.endBucket = currentPhase.startBucket; allPhases.add(betweenPhase); } allPhases.add(currentPhase); lastBucket = currentPhase.endBucket; }  if (lastBucket < taskEndBucket) { long lastTime = thePG.convertBucketToTime(lastBucket); AllocPhase lastPhase = new AllocPhase(lastBucket, getBestBucketQty(lastTime)); lastPhase.endBucket = taskEndBucket; allPhases.add(lastPhase);
while (rateBlocksIt.hasNext()) { ConstantRateBlock currentBlock = (ConstantRateBlock) rateBlocksIt.next(); allPhases.addAll(currentBlock.generateAllAllocationPhases(task,thePG));
    public Collection generateAllAllocationPhases() {      Iterator defPhasesIt = allocated.iterator();      long taskStartTime = getTaskUtils().getStartTime(task);      int taskStartBucket = thePG.convertTimeToBucket(taskStartTime, false);      long taskEndTime = getTaskUtils().getEndTime(task);      int taskEndBucket = thePG.convertTimeToBucket(taskEndTime, true);      int lastBucket = taskStartBucket;      ArrayList allPhases = new ArrayList();      while (defPhasesIt.hasNext()) {        AllocPhase currentPhase = (AllocPhase) defPhasesIt.next();        if (currentPhase.startBucket > lastBucket) {          /*if ((inventoryPlugin.getClusterId().toString().indexOf("2-NLOS-BTY") >= 0) &&             (task.getDirectObject().getTypeIdentificationPG().getTypeIdentification().indexOf("155mm-DPICM") >= 0)) {            System.out.println("Got a Phase after the end time of the task..." +                               " qty of phase is " + currentPhase.amount + " " +                               task.getUID() + " late phase starts on " +                               new Date(thePG.convertBucketToTime(currentPhase.startBucket)));          }*/          //TODO - EPD This best quantity fill in code causes lots of problems!!!!          long lastTime = thePG.convertBucketToTime(lastBucket);          AllocPhase betweenPhase = new AllocPhase(lastBucket, getBestBucketQty(lastTime));          betweenPhase.endBucket = currentPhase.startBucket;          allPhases.add(betweenPhase);        }        allPhases.add(currentPhase);        lastBucket = currentPhase.endBucket;      }      if (lastBucket < taskEndBucket) {        long lastTime = thePG.convertBucketToTime(lastBucket);        AllocPhase lastPhase = new AllocPhase(lastBucket, getBestBucketQty(lastTime));        lastPhase.endBucket = taskEndBucket;        allPhases.add(lastPhase);      }      return allPhases;    }