@ SuppressWarnings ( "unchecked" ) public < T > T [ ] getSpans ( int queryStart , int queryEnd , Class < T > kind ) { if ( kind == null ) return ArrayUtils . emptyArray ( kind ) ; int spanCount = mSpanCount ; Object [ ] spans = mSpans ; int [ ] starts = mSpanStarts ; int [ ] ends = mSpanEnds ; int [ ] flags = mSpanFlags ; int gapstart = mGapStart ; int gaplen = mGapLength ; int count = 0 ; T [ ] ret = null ; T ret1 = null ; for ( int i = 0 ; i < spanCount ; i ++ ) { int spanStart = starts [ i ] ; if ( spanStart > gapstart ) { spanStart -= gaplen ; } if ( spanStart > queryEnd ) { continue ; } int spanEnd = ends [ i ] ; if ( spanEnd > gapstart ) { spanEnd -= gaplen ; } if ( spanEnd < queryStart ) { continue ; } if ( spanStart != spanEnd && queryStart != queryEnd ) { if ( spanStart == queryEnd ) continue ; if ( spanEnd == queryStart ) continue ; } // Expensive test, should be performed after the previous tests if ( ! kind . isInstance ( spans [ i ] ) ) continue ; if ( count == 0 ) { // Safe conversion thanks to the isInstance test above ret1 = ( T ) spans [ i ] ; count ++ ; } else { if ( count == 1 ) { // Safe conversion, but requires a suppressWarning ret = ( T [ ] ) Array . newInstance ( kind , spanCount - i + 1 ) ; ret [ 0 ] = ret1 ; } int prio = flags [ i ] & SPAN_PRIORITY ; if ( prio != 0 ) { int j ; for ( j = 0 ; j < count ; j ++ ) { int p = getSpanFlags ( ret [ j ] ) & SPAN_PRIORITY ; if ( prio > p ) { break ; } } System . arraycopy ( ret , j , ret , j + 1 , count - j ) ; // Safe conversion thanks to the isInstance test above ret [ j ] = ( T ) spans [ i ] ; count ++ ; } else { // Safe conversion thanks to the isInstance test above ret [ count ++ ] = ( T ) spans [ i ] ; } } } if ( count == 0 ) { return ArrayUtils . emptyArray ( kind ) ; } if ( count == 1 ) { // Safe conversion, but requires a suppressWarning ret = ( T [ ] ) Array . newInstance ( kind , 1 ) ; ret [ 0 ] = ret1 ; return ret ; } if ( count == ret . length ) { return ret ; } // Safe conversion, but requires a suppressWarning T [ ] nret = ( T [ ] ) Array . newInstance ( kind , count ) ; System . arraycopy ( ret , 0 , nret , 0 , count ) ; return nret ; }
Return an array of the spans of the specified type that overlap the specified range of the buffer . The kind may be Object . class to get a list of all the spans regardless of type .