public static boolean isDisjoint ( Collection < Range > ranges ) { List < Range > rangesList = new ArrayList < Range > ( ranges . size ( ) ) ; rangesList . addAll ( ranges ) ; Collections . sort ( rangesList ) ; for ( int i = 0 ; i < rangesList . size ( ) - 1 ; i ++ ) { Range rCurrent = rangesList . get ( i ) ; Range rNext = rangesList . get ( i + 1 ) ; if ( rCurrent . overlapsWith ( rNext ) ) { return false ; } } return true ; }
Checks weather the given set of ranges are disjoint i . e . none of the ranges overlap .