/** * adds the given string to its children (creates children if necessary) * * @param suffix the suffix to add to its children * @return true if the add operation changed the structure */ public boolean add(String suffix) { boolean result; Character c; String newSuffix; TrieNode child; result = false; c = suffix.charAt(0); newSuffix = suffix.substring(1); // find child and add if necessary child = m_Children.get(c); if (child == null) { result = true; child = add(c); } // propagate remaining suffix if (newSuffix.length() > 0) { result = child.add(newSuffix) || result; } return result; }
/** * adds the given string to its children (creates children if necessary) * * @param suffix the suffix to add to its children * @return true if the add operation changed the structure */ public boolean add(String suffix) { boolean result; Character c; String newSuffix; TrieNode child; result = false; c = suffix.charAt(0); newSuffix = suffix.substring(1); // find child and add if necessary child = m_Children.get(c); if (child == null) { result = true; child = add(c); } // propagate remaining suffix if (newSuffix.length() > 0) { result = child.add(newSuffix) || result; } return result; }
/** * creates a deep copy of itself * * @return a deep copy of itself */ @Override public Object clone() { TrieNode result; Enumeration<Character> keys; Character key; TrieNode child; result = new TrieNode(getChar()); keys = m_Children.keys(); while (keys.hasMoreElements()) { key = keys.nextElement(); child = (TrieNode) m_Children.get(key).clone(); result.add(child); result.m_Children.put(key, child); } return result; }
/** * creates a deep copy of itself * * @return a deep copy of itself */ @Override public Object clone() { TrieNode result; Enumeration<Character> keys; Character key; TrieNode child; result = new TrieNode(getChar()); keys = m_Children.keys(); while (keys.hasMoreElements()) { key = keys.nextElement(); child = (TrieNode) m_Children.get(key).clone(); result.add(child); result.m_Children.put(key, child); } return result; }
/** * adds the given charater to its children * * @param c the character to add * @return the generated child node */ protected TrieNode add(Character c) { TrieNode child; child = new TrieNode(c); add(child); m_Children.put(c, child); return child; }
/** * Ensures that this collection contains the specified element. * * @param o the string to add * @return true if the structure changed */ @Override public boolean add(String o) { return m_Root.add(o + TrieNode.STOP); }
/** * adds the given charater to its children * * @param c the character to add * @return the generated child node */ protected TrieNode add(Character c) { TrieNode child; child = new TrieNode(c); add(child); m_Children.put(c, child); return child; }
/** * Ensures that this collection contains the specified element. * * @param o the string to add * @return true if the structure changed */ @Override public boolean add(String o) { return m_Root.add(o + TrieNode.STOP); }