Package adams.core
Class Trie.TrieNode
- java.lang.Object
-
- javax.swing.tree.DefaultMutableTreeNode
-
- adams.core.Trie.TrieNode
-
- All Implemented Interfaces:
Serializable
,Cloneable
,MutableTreeNode
,TreeNode
- Enclosing class:
- Trie
public static class Trie.TrieNode extends DefaultMutableTreeNode
Represents a node in the trie.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected Hashtable<Character,Trie.TrieNode>
m_Children
for fast access to the childrenstatic Character
STOP
the stop character-
Fields inherited from class javax.swing.tree.DefaultMutableTreeNode
allowsChildren, children, EMPTY_ENUMERATION, parent, userObject
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Trie.TrieNode
add(Character c)
adds the given charater to its childrenboolean
add(String suffix)
adds the given string to its children (creates children if necessary)Object
clone()
creates a deep copy of itselfboolean
contains(String suffix)
checks whether a suffix can be found in its childrenprotected String
determineCommonPrefix(String currentPrefix)
determines the common prefix of the nodes.boolean
equals(Object obj)
Indicates whether some other object is "equal to" this one.Trie.TrieNode
find(String suffix)
returns the node with the given suffixCharacter
getChar()
returns the stored characterString
getCommonPrefix()
returns the common prefix for all the nodes starting with this node.String
getCommonPrefix(String startPrefix)
returns the common prefix for all the nodes starting with the node for the specified prefix.String
getString()
returns the full string up to the rootprotected void
remove(Character c)
removes the given characted from its childrenboolean
remove(String suffix)
Removes a suffix from the trie.void
setChar(Character value)
sets the character this node representsint
size()
returns the number of stored strings, i.e., leavesString
toString()
returns the node in a string representation-
Methods inherited from class javax.swing.tree.DefaultMutableTreeNode
add, breadthFirstEnumeration, children, depthFirstEnumeration, getAllowsChildren, getChildAfter, getChildAt, getChildBefore, getChildCount, getDepth, getFirstChild, getFirstLeaf, getIndex, getLastChild, getLastLeaf, getLeafCount, getLevel, getNextLeaf, getNextNode, getNextSibling, getParent, getPath, getPathToRoot, getPreviousLeaf, getPreviousNode, getPreviousSibling, getRoot, getSharedAncestor, getSiblingCount, getUserObject, getUserObjectPath, insert, isLeaf, isNodeAncestor, isNodeChild, isNodeDescendant, isNodeRelated, isNodeSibling, isRoot, pathFromAncestorEnumeration, postorderEnumeration, preorderEnumeration, remove, remove, removeAllChildren, removeFromParent, setAllowsChildren, setParent, setUserObject
-
-
-
-
Field Detail
-
STOP
public static final Character STOP
the stop character
-
m_Children
protected Hashtable<Character,Trie.TrieNode> m_Children
for fast access to the children
-
-
Constructor Detail
-
TrieNode
public TrieNode(char c)
initializes the node- Parameters:
c
- the value of this node
-
TrieNode
public TrieNode(Character c)
initializes the node- Parameters:
c
- the value of this node
-
-
Method Detail
-
getChar
public Character getChar()
returns the stored character- Returns:
- the stored character
-
setChar
public void setChar(Character value)
sets the character this node represents- Parameters:
value
- the character to store
-
add
public boolean add(String suffix)
adds the given string to its children (creates children if necessary)- Parameters:
suffix
- the suffix to add to its children- Returns:
- true if the add operation changed the structure
-
add
protected Trie.TrieNode add(Character c)
adds the given charater to its children- Parameters:
c
- the character to add- Returns:
- the generated child node
-
remove
protected void remove(Character c)
removes the given characted from its children- Parameters:
c
- the character to remove
-
remove
public boolean remove(String suffix)
Removes a suffix from the trie.- Parameters:
suffix
- the suffix to remove- Returns:
- true if this trie changed as a result of the call
-
contains
public boolean contains(String suffix)
checks whether a suffix can be found in its children- Parameters:
suffix
- the suffix to look for- Returns:
- true if suffix was found
-
clone
public Object clone()
creates a deep copy of itself- Overrides:
clone
in classDefaultMutableTreeNode
- Returns:
- a deep copy of itself
-
equals
public boolean equals(Object obj)
Indicates whether some other object is "equal to" this one.
-
find
public Trie.TrieNode find(String suffix)
returns the node with the given suffix- Parameters:
suffix
- the suffix to look for- Returns:
- null if unsuccessful otherwise the corresponding node
-
getCommonPrefix
public String getCommonPrefix()
returns the common prefix for all the nodes starting with this node. The result includes this node, unless it's the root node or a STOP node.- Returns:
- the result of the search
-
getCommonPrefix
public String getCommonPrefix(String startPrefix)
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.- Parameters:
startPrefix
- the prefix of the node to start the search from- Returns:
- the result of the search, null if startPrefix cannot be found
-
determineCommonPrefix
protected String determineCommonPrefix(String currentPrefix)
determines the common prefix of the nodes.- Parameters:
currentPrefix
- the common prefix found so far- Returns:
- the result of the search
-
size
public int size()
returns the number of stored strings, i.e., leaves- Returns:
- the number of stored strings
-
getString
public String getString()
returns the full string up to the root- Returns:
- the full string to the root
-
toString
public String toString()
returns the node in a string representation- Overrides:
toString
in classDefaultMutableTreeNode
- Returns:
- the node as string
-
-