public static RangeSet split ( Collection < RangeSet > rangeSets ) { RangeSet result = new RangeSet ( ) ; SortedSet < Integer > ss = new TreeSet < Integer > ( ) ; for ( RangeSet rs : rangeSets ) { for ( CharRange r : rs ) { ss . add ( r . getFrom ( ) ) ; ss . add ( r . getTo ( ) ) ; } } Iterator < Integer > i = ss . iterator ( ) ; if ( i . hasNext ( ) ) { int from = i . next ( ) ; while ( i . hasNext ( ) ) { int to = i . next ( ) ; if ( from != to ) { for ( RangeSet rs : rangeSets ) { if ( rs . contains ( from , to ) ) { result . add ( from , to ) ; break ; } } } from = to ; } } return result ; }
Converts a possibly overlapping collection of RangesSet s into a non overlapping RangeSet that accepts the same characters .