/** * @requires: end >= start * * @effects: creates a new IntervalList containing the range from <code>start</code> to * <code>end</code>. */ public GenericIntervalList( Object start, Object end, ValueSpace comp ) { valueSpace = comp; intervals = new LinkedList(); intervals.add( new Interval( start, true, end, true ) ); }
private void addIntervalInternal( Object start, boolean incStart, Object end, boolean incEnd ) { intervals.add( new Interval( start, incStart, end, incEnd ) ); }
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() ) ); } } } } }
return new Interval( newStart, newIncStart, newEnd, newIncEnd );
return new Interval( newStart, newIncStart, newEnd, newIncEnd );
/** * @requires: end >= start * * @effects: removes from this all of the numbers which are not between <code>start</code> and * <code>end</code>. */ public void restrictToInterval( Object start, boolean incStart, Object end, boolean incEnd ) { restrictToInterval( new Interval( start, incStart, end, incEnd ) ); }