netkit.graph
Class TokenSet

java.lang.Object
  extended by netkit.graph.TokenSet
Direct Known Subclasses:
ExpandableTokenSet, FixedTokenSet

public abstract class TokenSet
extends java.lang.Object

This abstract class is the parent of the token set hierarchy. These containers keep track of valid tokens for a CATEGORICAL attribute type.

Author:
Kaveh R. Ghazi
See Also:
AttributeCategorical

Field Summary
protected  java.util.ArrayList<java.lang.String> tokenList
           
protected  java.util.Map<java.lang.String,java.lang.Integer> tokenMap
           
 
Constructor Summary
TokenSet()
           
 
Method Summary
protected  void add(java.lang.String token)
          Adds the supplied token to this set; duplicates are not allowed.
 boolean contains(java.lang.String token)
          Determines if a token is valid for this container.
 java.lang.String getToken(int i)
          Gets the i'th element from the array of valid tokens.
 java.lang.String[] getTokens()
          Get a String array of valid tokens.
 int getValue(java.lang.String token)
          Gets the integer value associated with the supplied token.
 int size()
          Gets the size of the categorical token list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tokenMap

protected final java.util.Map<java.lang.String,java.lang.Integer> tokenMap

tokenList

protected final java.util.ArrayList<java.lang.String> tokenList
Constructor Detail

TokenSet

public TokenSet()
Method Detail

add

protected void add(java.lang.String token)
Adds the supplied token to this set; duplicates are not allowed.

Parameters:
token - a String token to add to this container.
Throws:
java.lang.RuntimeException - if the token already exists in this container.

contains

public boolean contains(java.lang.String token)
Determines if a token is valid for this container.

Parameters:
token - a String representation of a value for this Set.
Returns:
true if the token is valid for this Set, i.e. it exists in this container.

getTokens

public java.lang.String[] getTokens()
Get a String array of valid tokens.

Returns:
a String array representing the valid tokens in this container.

getToken

public java.lang.String getToken(int i)
Gets the i'th element from the array of valid tokens.

Parameters:
i - the index to get the token from.
Returns:
the i'th token element at the supplied index.
Throws:
java.lang.IndexOutOfBoundsException - if the supplied index is not within the range of valid token indexes.

size

public int size()
Gets the size of the categorical token list.

Returns:
the size of the categorical token list.

getValue

public int getValue(java.lang.String token)
Gets the integer value associated with the supplied token.

Parameters:
token - a String representing the token to be converted into a numeric value.
Returns:
an integer value unique for each valid token. Tokens are numbered sequentially in the order they were added to this container.
Throws:
java.lang.RuntimeException - if the supplied token isn't found.