return new CalendarInterval(Math.min(i1.getStart(),i2.getStart()),Math.max(i1.getEnd(),i2.getEnd()));
}
public boolean add(Object o) {
HasStartAndEnd toAdd=(HasStartAndEnd)o;
SortedSet set=headSet(o);
if (set.size()>0){
HasStartAndEnd interval=(HasStartAndEnd)set.last();
if (interval.getEnd()>=toAdd.getStart())
toAdd=mergeIntervals(toAdd,interval);
}
set=tailSet(o);
if (set.size()>0){
HasStartAndEnd interval=(HasStartAndEnd)set.first();
if (toAdd.getEnd()>=interval.getStart())
toAdd=mergeIntervals(toAdd,interval);
}
return super.add(toAdd);
}