netkit.graph
Class AttributeCategorical

java.lang.Object
  extended by netkit.graph.Attribute
      extended by netkit.graph.AttributeCategorical
Direct Known Subclasses:
AttributeExpandableCategorical, AttributeFixedCategorical

public abstract class AttributeCategorical
extends Attribute

This class handles attributes that are of type CATEGORICAL. CATEGORICAL types can have values from a fixed set of tokens specified by the tokenSet.

Author:
Kaveh R. Ghazi
See Also:
Attributes, TokenSet, SchemaReader

Field Summary
protected  TokenSet tokenSet
           
 
Constructor Summary
protected AttributeCategorical(java.lang.String name, TokenSet tokenSet)
          The constructor must be provided the name of this attribute and the set of valid categorical token values.
 
Method Summary
 java.lang.String formatForOutput(double value)
          Formats the supplied value from this attribute as a String for output.
 java.lang.String getToken(int i)
          Gets the i'th token from the list of valid tokens for this categorical attribute; the index is a zero-based array lookup.
 java.lang.String[] getTokens()
          Gets the tokens valid for this categorical attribute.
 int getValue(java.lang.String token)
          Gets the numerical value for a particular token; the token must be in the set of valid tokens for this attribute.
 int size()
          Gets the size of the categorical token list.
 
Methods inherited from class netkit.graph.Attribute
getName, getType, parseAndInsert, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

tokenSet

protected final TokenSet tokenSet
Constructor Detail

AttributeCategorical

protected AttributeCategorical(java.lang.String name,
                               TokenSet tokenSet)
The constructor must be provided the name of this attribute and the set of valid categorical token values. Subclasses should provide a public constructor that overrides this one.

Parameters:
name - a String representing the name of this attribute.
tokenSet - a TokenSet representing the valid tokens of this attribute.
Method Detail

getTokens

public final java.lang.String[] getTokens()
Gets the tokens valid for this categorical attribute.

Returns:
an array of String containing the tokens valid for this categorical attribute.

getToken

public final java.lang.String getToken(int i)
Gets the i'th token from the list of valid tokens for this categorical attribute; the index is a zero-based array lookup.

Parameters:
i - the index into the token array to lookup
Returns:
a String with the i'th valid token.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the parameter is outside the bounds of the array containing the valid tokens.

size

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

Returns:
the size of the categorical token list.

getValue

public final int getValue(java.lang.String token)
Gets the numerical value for a particular token; the token must be in the set of valid tokens for this attribute.

Parameters:
token - the String token to lookup in the token set.
Returns:
the integer index of the token.
Throws:
java.lang.RuntimeException - if the token isn't found.

formatForOutput

public java.lang.String formatForOutput(double value)
Description copied from class: Attribute
Formats the supplied value from this attribute as a String for output. Subclasses will supply their own mechanism for conversion.

Specified by:
formatForOutput in class Attribute
Parameters:
value - a double to be converted into an output String.
Returns:
a String representing the supplied value.