public List < TrieNode > search ( String path ) { List < TrieNode > terminal = new ArrayList <> ( ) ; TrieNode current = this ; if ( current . mIsTerminal ) { terminal . add ( current ) ; } for ( String component : path . split ( "/" ) ) { if ( current . mChildren . containsKey ( component ) ) { current = current . mChildren . get ( component ) ; if ( current . mIsTerminal ) { terminal . add ( current ) ; } } else { break ; } } return terminal ; }
Traverses the trie along the path components until the traversal cannot proceed any more .