/** * @effects: returns the upper bound of the highest range of this, or null if this represents an * empty set of intervals. */ public Object max() { if( intervals.isEmpty() ) { return null; } return ((Interval) intervals.get( intervals.size() - 1 )).end(); }
/** * @effects: removes from this all of the numbers represented by <code>il</code>. */ public void removeIntervalList( GenericIntervalList il ) { Iterator iter = il.intervals.iterator(); while( iter.hasNext() ) { Interval i = (Interval) iter.next(); removeIntervalInternal( i.start(), i.incStart(), i.end(), i.incEnd() ); } canonicalize(); }
/** * @effects: adds to this all of numbers reprsented by <code>il</code>. */ public void addIntervalList( GenericIntervalList il ) { Iterator iter = il.intervals.iterator(); while( iter.hasNext() ) { Interval i = (Interval) iter.next(); addIntervalInternal( i.start(), i.incStart(), i.end(), i.incEnd() ); } canonicalize(); }
private void removeIntervalInternal( Object start, boolean incStart, Object end, boolean incEnd ) { ListIterator iter = intervals.listIterator(); Interval toRemove = new Interval( start, incStart, end, incEnd ); while( iter.hasNext() ) { Interval curr = (Interval) iter.next(); if( curr.overlaps( toRemove ) ) { iter.remove(); if( valueSpace.compare( start, curr.start() ) > 0 ) { iter.add( new Interval( curr.start(), curr.incStart(), start, !incStart ) ); if( valueSpace.compare( end, curr.end() ) < 0 ) { iter.add( new Interval( end, !incEnd, curr.end(), curr.incEnd() ) ); } } else { if( valueSpace.compare( end, curr.end() ) < 0 ) { iter.add( new Interval( end, !incEnd, curr.end(), curr.incEnd() ) ); } } } } }