private final ByteBuffer advance ( ) { if ( position == 0 ) { return null ; } while ( position > 0 ) { final int lastIndex = position - 1 ; final int arc = arcs [ lastIndex ] ; if ( arc == 0 ) { // Remove the current node from the queue. position -- ; continue ; } // Go to the next arc, but leave it on the stack // so that we keep the recursion depth level accurate. arcs [ lastIndex ] = fsa . getNextArc ( arc ) ; // Expand buffer if needed. final int bufferLength = this . buffer . length ; if ( lastIndex >= bufferLength ) { this . buffer = Arrays . copyOf ( buffer , bufferLength + EXPECTED_MAX_STATES ) ; this . bufferWrapper = ByteBuffer . wrap ( buffer ) ; } buffer [ lastIndex ] = fsa . getArcLabel ( arc ) ; if ( ! fsa . isArcTerminal ( arc ) ) { // Recursively descend into the arc's node. pushNode ( fsa . getEndNode ( arc ) ) ; } if ( fsa . isArcFinal ( arc ) ) { bufferWrapper . clear ( ) ; bufferWrapper . limit ( lastIndex + 1 ) ; return bufferWrapper ; } } return null ; }
Advances to the next available final state .