/** * 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; }
/** * determines the common prefix of the nodes. * * @param currentPrefix the common prefix found so far * @return the result of the search */ protected String determineCommonPrefix(String currentPrefix) { String result; String newPrefix; if (!isRoot() && (getChar() != STOP)) { newPrefix = currentPrefix + getChar(); } else { newPrefix = currentPrefix; } if (m_Children.size() == 1) { result = ((TrieNode) getChildAt(0)).determineCommonPrefix(newPrefix); } else { result = newPrefix; } return result; }
/** * determines the common prefix of the nodes. * * @param currentPrefix the common prefix found so far * @return the result of the search */ protected String determineCommonPrefix(String currentPrefix) { String result; String newPrefix; if (!isRoot() && (getChar() != STOP)) { newPrefix = currentPrefix + getChar(); } else { newPrefix = currentPrefix; } if (m_Children.size() == 1) { result = ((TrieNode) getChildAt(0)).determineCommonPrefix(newPrefix); } else { result = newPrefix; } return result; }