public static Span [ ] dropOverlappingSpans ( final Span [ ] spans ) { final List < Span > sortedSpans = new ArrayList < Span > ( spans . length ) ; Collections . addAll ( sortedSpans , spans ) ; Collections . sort ( sortedSpans ) ; final Iterator < Span > it = sortedSpans . iterator ( ) ; Span lastSpan = null ; while ( it . hasNext ( ) ) { Span span = it . next ( ) ; if ( lastSpan != null ) { if ( lastSpan . intersects ( span ) ) { it . remove ( ) ; span = lastSpan ; } } lastSpan = span ; } return sortedSpans . toArray ( new Span [ sortedSpans . size ( ) ] ) ; }
Removes spans with are intersecting or crossing in anyway .