/** * Returns copy of this object.<br> * <b>NOTE:</b> this method clones the entries * * @return the copy object */ public SingleProfile copy() { SingleProfile copy = new SingleProfile(); for (ProfileEntry entry : avail.values()) { copy.add(entry.clone(entry.getTime())); } return copy; }
/** * Includes a time slot in this availability profile. This is useful if your scheduling strategy * cancels a job and you want to update the availability profile. * * @param startTime the start time of the time slot. * @param finishTime the finish time of the time slot. * @param list the list of ranges of PEs in the slot. * @return <tt>true</tt> if the slot was included; <tt>false</tt> otherwise. */ public boolean addTimeSlot(double startTime, double finishTime, PERangeList list) { startTime = Math.max(startTime, currentTime()); if (finishTime <= startTime) { return false; } Iterator<ProfileEntry> it = avail.itValuesFromPrec(startTime); ProfileEntry last = it.next(); ProfileEntry newAnchor = null; if (last.getTime() < startTime) { newAnchor = last.clone(startTime); last = newAnchor; } ProfileEntry nextEntry = null; while (it.hasNext()) { nextEntry = it.next(); if (nextEntry.getTime() > finishTime) { break; } // Remove duplicate entries. That is, entries whose PE ranges // are the same. This minimises the number of entries required if (nextEntry.getTime() < finishTime && last.getAvailRanges().equals(nextEntry.getAvailRanges())) { it.remove(); } else { last.getAvailRanges().addAll(list.clone()); last = nextEntry; } } if (last.getTime() < finishTime) { add(last.clone(finishTime)); last.getAvailRanges().addAll(list.clone()); } if (newAnchor != null) { add(newAnchor); } return true; }