private static < T extends Comparable < T > > List < Interval < T > > combine ( Partition < T > p1 , Partition < T > p2 ) throws MIDDException { Set < EndPoint < T >> boundSet = new HashSet < EndPoint < T > > ( ) ; //collect all bounds and remove duplicated items for ( Interval < T > interval : p1 . getIntervals ( ) ) { boundSet . add ( interval . getLowerBound ( ) ) ; boundSet . add ( interval . getUpperBound ( ) ) ; } for ( Interval < T > interval : p2 . getIntervals ( ) ) { boundSet . add ( interval . getLowerBound ( ) ) ; boundSet . add ( interval . getUpperBound ( ) ) ; } //sorting the bounds List < EndPoint < T > > sortedBounds = new ArrayList < EndPoint < T > > ( boundSet ) ; Collections . sort ( sortedBounds ) ; List < Interval < T > > tempPartition = new ArrayList < Interval < T > > ( ) ; // Generate new intervals for ( int i = 0 ; i < sortedBounds . size ( ) - 1 ; i ++ ) { EndPoint < T > lowBound = sortedBounds . get ( i ) ; EndPoint < T > upBound = sortedBounds . get ( i + 1 ) ; tempPartition . add ( new Interval < T > ( lowBound ) ) ; tempPartition . add ( new Interval < T > ( lowBound , upBound ) ) ; } // add the last end-point if ( sortedBounds . size ( ) > 0 ) { EndPoint < T > lastBound = sortedBounds . get ( sortedBounds . size ( ) - 1 ) ; tempPartition . add ( new Interval < T > ( lastBound ) ) ; } else { log . warn ( "empty sortedBound" ) ; } return tempPartition ; }
Create a list of intervals from two partitions