if (interval.getStart() == 0) // ignore degenerate range
return;
if (interval.getStart() == interval.getEnd())
return;
AbstractContourBucket bucket = null;
long intervalDuration = 0;
// System.out.println("--interval " + new java.util.Date(interval.getStart()) + " - " + new java.util.Date(interval.getEnd()));
// if beginning a replacement interval
if (replacementGenerator.isCurrentActive() && replacementGenerator.currentStart() == interval.getStart()) {
intervalDuration = workCalendar.compare(replacementGenerator.getEnd(),replacementGenerator.getStart(), false); // get duration of new region
// if inserting during a non-working time, need to adjust assignment calendar
if (intervalDuration == 0) {
assignment.addCalendarTime(interval.getStart(),interval.getEnd());
}
//need to shift start to make room for new ones
if (interval.getStart() < assignment.getStart()) {
assignment.setStart(interval.getStart());
}
IntervalValue replacementIntervalValue = (IntervalValue)replacementGenerator.current();
bucket = PersonalContourBucket.getInstance(intervalDuration,replacementIntervalValue.getValue()); // make a new bucket
activeDate = replacementGenerator.currentEnd(); // ignore everything in the future until active date
} else if (interval.getStart() >= activeDate) { // use contour bucket
intervalDuration = workCalendar.compare(interval.getEnd(),interval.getStart(), false);
if (intervalDuration == 0) // don't treat degenerate cased
return;
if (contourBucketIntervalGenerator.current() == null) { // if not active, then insert dead time
bucket =PersonalContourBucket.getInstance(intervalDuration,0); // make a new non-workingbucket
} else {
bucket = (AbstractContourBucket) contourBucketIntervalGenerator.current();
if (intervalDuration != bucket.getBucketDuration(assignmentWork)) // try to use existing bucket
bucket = PersonalContourBucket.getInstance(intervalDuration,bucket.getUnits()); // make a new bucket
}
}
if (bucket == null) // if no bucket, then do nothing
return;
// merge with previous if units are identical
if (previous != null && previous.getUnits() == bucket.getUnits()) {
collection.remove(previous);
bucket = PersonalContourBucket.getInstance(bucket.getBucketDuration(assignmentWork) + previous.getBucketDuration(assignmentWork),previous.getUnits());
}
collection.add(bucket);
previous = bucket; // for merge
}