public List < String > splitMatches ( String text , int minSize ) { TrieNode node = inner . root ( ) ; List < String > matches = new ArrayList <> ( ) ; String accumulator = "" ; for ( int i = 0 ; i < text . length ( ) ; i ++ ) { short prevDepth = node . getDepth ( ) ; TrieNode prevNode = node ; node = node . getContinuation ( text . charAt ( i ) ) ; if ( null == node ) node = inner . root ( ) ; if ( ! accumulator . isEmpty ( ) && ( node . getDepth ( ) < prevDepth || ( prevNode . hasChildren ( ) && node . getDepth ( ) == prevDepth ) ) ) { if ( accumulator . length ( ) > minSize ) { matches . add ( accumulator ) ; node = ( ( Optional < TrieNode > ) inner . root ( ) . getChild ( text . charAt ( i ) ) ) . orElse ( inner . root ( ) ) ; } accumulator = "" ; } else if ( ! accumulator . isEmpty ( ) ) { accumulator += text . charAt ( i ) ; } else if ( accumulator . isEmpty ( ) && node . getDepth ( ) > prevDepth ) { accumulator = node . getString ( ) ; } } List < String > tokenization = new ArrayList <> ( ) ; for ( String match : matches ) { int index = text . indexOf ( match ) ; assert ( index >= 0 ) ; if ( index > 0 ) tokenization . add ( text . substring ( 0 , index ) ) ; tokenization . add ( text . substring ( index , index + match . length ( ) ) ) ; text = text . substring ( index + match . length ( ) ) ; } tokenization . add ( text ) ; return tokenization ; }
Split matches list .