public static SortedSet reduce ( SortedSet locations ) { SortedSet newSet = new TreeSet ( ) ; Iterator it = locations . iterator ( ) ; while ( it . hasNext ( ) ) { LocationRange next = ( LocationRange ) it . next ( ) ; if ( newSet . size ( ) == 0 ) { newSet . add ( next ) ; continue ; } if ( next . getStartLocation ( ) . compareTo ( next . getEndLocation ( ) ) >= 0 ) { continue ; } // Try to reduce the set by joining adjacent ranges or eliminating // overlap. LocationRange last = ( LocationRange ) newSet . last ( ) ; if ( next . getStartLocation ( ) . compareTo ( last . getEndLocation ( ) ) <= 0 ) { if ( last . getEndLocation ( ) . compareTo ( next . getEndLocation ( ) ) <= 0 ) { newSet . remove ( last ) ; newSet . add ( new LocationRangeImpl ( last , next ) ) ; } continue ; } newSet . add ( next ) ; } return newSet ; }
Reduces a set of LocationRange objects .