edu.iastate.jtm.dic
Class AbstractTrieNode

java.lang.Object
  extended by edu.iastate.jtm.dic.AbstractTrieNode
All Implemented Interfaces:
TrieNode
Direct Known Subclasses:
AsciiTrieNode, DigitTrieNode, FuzzyTrieNode, LetterDigitTrieNode, LetterTrieNode, LowerTrieNode, WordTrieNode

public abstract class AbstractTrieNode
extends java.lang.Object
implements TrieNode

Provide methods for all TrieNode.

Author:
Jing Ding

Field Summary
protected  TrieNode[] children
          Child node array.
protected  TrieNode parent
           
 
Constructor Summary
AbstractTrieNode()
           
 
Method Summary
 int compareKey(java.lang.CharSequence str)
          Compare a string to this node's key.
 TrieNode createChild(int id)
          Create a new child node at the specified array index.
abstract  TrieNode[] createChildren()
          Allocate memory for a node's child node array.
protected abstract  TrieNode createNodeInstance()
           
 TrieNode[] getChildren()
          Return a node's child node array.
abstract  int getDegree()
          Return the degree of this trie (size of the trie's alphabet).
abstract  int getIndex(char c)
          Return the index of a character in this node's child array.
 int getIndex(char[] key)
           
 int getIndex(java.lang.CharSequence key)
           
 char[] getKey()
          Return a node's key.
 java.lang.String getKeyString()
           
 TrieNode getParent()
           
 java.lang.Object getValue()
          Return a node's attached value.
 boolean isCaseSensitive()
           
 void printIndexMapping()
           
 void removeChild(int index)
           
 void removeChildren()
           
 void setKey(char[] k)
          Set a node's key.
 void setParent(TrieNode parent)
           
 void setValue(java.lang.Object obj)
          Attach a value to the node.
 java.lang.String supportedCharacters()
          Return supported characters by this TrieNode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

children

protected TrieNode[] children
Child node array. Lazily populated.


parent

protected TrieNode parent
Constructor Detail

AbstractTrieNode

public AbstractTrieNode()
Method Detail

compareKey

public int compareKey(java.lang.CharSequence str)
Compare a string to this node's key.

Specified by:
compareKey in interface TrieNode
Parameters:
str - the string to be compared.
Returns:
= 0, complete match; > 0, the string is a superset of the key; < 0, matched portion is a subset of the key. The absolute value of the return value is the number of characters matched, if return != 0.

createChild

public TrieNode createChild(int id)
Create a new child node at the specified array index.

Specified by:
createChild in interface TrieNode
Parameters:
id - the position in the array for the child node.
Returns:
The newly created child node.

createNodeInstance

protected abstract TrieNode createNodeInstance()

createChildren

public abstract TrieNode[] createChildren()
Allocate memory for a node's child node array.

Specified by:
createChildren in interface TrieNode
Returns:
Newly allocated array.

getChildren

public TrieNode[] getChildren()
Return a node's child node array.

Specified by:
getChildren in interface TrieNode
Returns:
The child node array of the node.

getParent

public TrieNode getParent()
Specified by:
getParent in interface TrieNode

setParent

public void setParent(TrieNode parent)
Specified by:
setParent in interface TrieNode

getDegree

public abstract int getDegree()
Return the degree of this trie (size of the trie's alphabet).

Specified by:
getDegree in interface TrieNode
Returns:
the size of alphabet.

getIndex

public abstract int getIndex(char c)
Return the index of a character in this node's child array.

Specified by:
getIndex in interface TrieNode
Parameters:
c - the character of interest.
Returns:
index of the character.

getIndex

public int getIndex(char[] key)
Specified by:
getIndex in interface TrieNode

getIndex

public int getIndex(java.lang.CharSequence key)
Specified by:
getIndex in interface TrieNode

getKey

public char[] getKey()
Return a node's key.

Specified by:
getKey in interface TrieNode
Returns:
the key of the node.

getValue

public java.lang.Object getValue()
Return a node's attached value.

Specified by:
getValue in interface TrieNode
Returns:
the value attached to the node.

setKey

public void setKey(char[] k)
Set a node's key.

Specified by:
setKey in interface TrieNode
Parameters:
str - the node's key.

setValue

public void setValue(java.lang.Object obj)
Attach a value to the node.

Specified by:
setValue in interface TrieNode
Parameters:
obj - the value.

supportedCharacters

public java.lang.String supportedCharacters()
Return supported characters by this TrieNode.

Specified by:
supportedCharacters in interface TrieNode
Returns:
supported characters by this TrieNode.

printIndexMapping

public void printIndexMapping()
Specified by:
printIndexMapping in interface TrieNode

removeChild

public void removeChild(int index)
Specified by:
removeChild in interface TrieNode

removeChildren

public void removeChildren()
Specified by:
removeChildren in interface TrieNode

getKeyString

public java.lang.String getKeyString()
Specified by:
getKeyString in interface TrieNode

isCaseSensitive

public boolean isCaseSensitive()
Specified by:
isCaseSensitive in interface TrieNode