/** * returns the node with the given suffix * * @param suffix the suffix to look for * @return null if unsuccessful otherwise the corresponding node */ public TrieNode find(String suffix) { TrieNode result; Character c; String newSuffix; TrieNode child; c = suffix.charAt(0); newSuffix = suffix.substring(1); child = m_Children.get(c); if (child == null) { result = null; } else if (newSuffix.length() == 0) { result = child; } else { result = child.find(newSuffix); } return result; }
/** * returns the node with the given suffix * * @param suffix the suffix to look for * @return null if unsuccessful otherwise the corresponding node */ public TrieNode find(String suffix) { TrieNode result; Character c; String newSuffix; TrieNode child; c = suffix.charAt(0); newSuffix = suffix.substring(1); child = m_Children.get(c); if (child == null) { result = null; } else if (newSuffix.length() == 0) { result = child; } else { result = child.find(newSuffix); } return result; }
/** * returns the common prefix for all the nodes starting with the node for * the specified prefix. Can be null if initial prefix is not found. The * result includes this node, unless it's the root node or a STOP node. * Using the empty string means starting with this node. * * @param startPrefix the prefix of the node to start the search from * @return the result of the search, null if startPrefix cannot be found */ public String getCommonPrefix(String startPrefix) { String result; TrieNode startNode; if (startPrefix.length() == 0) { startNode = this; } else { startNode = find(startPrefix); } if (startNode == null) { result = null; } else { result = startPrefix + startNode.determineCommonPrefix(""); } return result; }
/** * returns the common prefix for all the nodes starting with the node for * the specified prefix. Can be null if initial prefix is not found. The * result includes this node, unless it's the root node or a STOP node. * Using the empty string means starting with this node. * * @param startPrefix the prefix of the node to start the search from * @return the result of the search, null if startPrefix cannot be found */ public String getCommonPrefix(String startPrefix) { String result; TrieNode startNode; if (startPrefix.length() == 0) { startNode = this; } else { startNode = find(startPrefix); } if (startNode == null) { result = null; } else { result = startPrefix + startNode.determineCommonPrefix(""); } return result; }
/** * returns all stored strings that match the given prefix * * @param prefix the prefix that all strings must have * @return all strings that match the prefix */ public Vector<String> getWithPrefix(String prefix) { Vector<String> result; TrieNode node; TrieIterator iter; result = new Vector<String>(); if (containsPrefix(prefix)) { node = m_Root.find(prefix); iter = new TrieIterator(node); while (iter.hasNext()) { result.add(iter.next()); } } return result; }
/** * returns all stored strings that match the given prefix * * @param prefix the prefix that all strings must have * @return all strings that match the prefix */ public Vector<String> getWithPrefix(String prefix) { Vector<String> result; TrieNode node; TrieIterator iter; result = new Vector<String>(); if (containsPrefix(prefix)) { node = m_Root.find(prefix); iter = new TrieIterator(node); while (iter.hasNext()) { result.add(iter.next()); } } return result; }