private void removeDuplicates ( NavigableMap < Double , SegmentWithRange > result ) { Segment last = null ; for ( Iterator < SegmentWithRange > iterator = result . descendingMap ( ) . values ( ) . iterator ( ) ; iterator . hasNext ( ) ; ) { SegmentWithRange current = iterator . next ( ) ; if ( current . getSegment ( ) . equals ( last ) ) { iterator . remove ( ) ; } last = current . getSegment ( ) ; } }
This combines consecutive entries in the map that refer to the same segment . This happens following a merge because the preceeding segments are replaced one at a time .