private String determineLongestPrefixInMDAG ( String str ) { MDAGNode currentNode = sourceNode ; int numberOfChars = str . length ( ) ; int onePastPrefixEndIndex = 0 ; //Loop through the characters in str, using them in sequence to _transition //through the MDAG until the currently processing node doesn't have a _transition //labeled with the current processing char, or there are no more characters to process. for ( int i = 0 ; i < numberOfChars ; i ++ , onePastPrefixEndIndex ++ ) { char currentChar = str . charAt ( i ) ; if ( currentNode . hasOutgoingTransition ( currentChar ) ) currentNode = currentNode . transition ( currentChar ) ; else break ; } ///// return str . substring ( 0 , onePastPrefixEndIndex ) ; }
Determines the longest prefix of a given String that is the prefix of another String previously added to the MDAG .