laser.alphabet
Class IndexedLabel

java.lang.Object
  extended by laser.alphabet.AbstractLabel<IndexedLabel>
      extended by laser.alphabet.IndexedLabel
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<IndexedLabel>, LabelInterface<IndexedLabel>

public class IndexedLabel
extends AbstractLabel<IndexedLabel>

IndexedLabels are Labels that represent integers from 0 to (N - 1), where N is specified by the Alphabet the IndexedLabels are associated with.

Like all types of Labels, IndexedLabels participate in flyweighting, thus there is only one instance of each unique IndexedLabel. For this reason, IndexedLabels should only be instantiated through an IndexedAlphabetFactory, which maintains a repository of all IndexedLabels.

Author:
Nathan A. Jokel (laser-software@cs.umass.edu)
See Also:
LabelInterface, IndexedAlphabetFactory, Serialized Form

Constructor Summary
protected IndexedLabel(int i)
          Creates a new IndexedLabel from the specified int.
 
Method Summary
 IndexedLabel clone()
          Returns a reference to this IndexedLabel.
 int compareTo(IndexedLabel label)
          Compares this IndexedLabel with the specified IndexedLabel for order.
 int getIndex()
          Gets the integer value of the index of this Label.
 int hashCode()
          Returns a hash code for this IndexedLabel.
 java.lang.String toString()
          Returns the String representation of this IndexedLabel.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IndexedLabel

protected IndexedLabel(int i)
Creates a new IndexedLabel from the specified int.

Precondition: i >= 0.

Parameters:
i - The int.
Method Detail

getIndex

public int getIndex()
Gets the integer value of the index of this Label.

Returns:
The index.

clone

public IndexedLabel clone()
Returns a reference to this IndexedLabel. Since Labels participate in flyweighting, there should be only one instance of each unique IndexedLabel.

Specified by:
clone in interface LabelInterface<IndexedLabel>
Specified by:
clone in class AbstractLabel<IndexedLabel>
Returns:
The reference.
See Also:
Object.clone()

compareTo

public int compareTo(IndexedLabel label)
Compares this IndexedLabel with the specified IndexedLabel for order. The order is determined by comparing the integer values of the indices of the IndexedLabels.

If this IndexedLabel is less than the specified IndexedLabel, a negative integer is returned. If this IndexedLabel is equal to the specified IndexedLabel, zero is returned. If this IndexedLabel is greater than the specified IndexedLabel, a positive integer is returned.

Specified by:
compareTo in interface java.lang.Comparable<IndexedLabel>
Specified by:
compareTo in class AbstractLabel<IndexedLabel>
Parameters:
label - the IndexedLabel to compare with this one.
Returns:
a negative integer when this IndexedLabel is less than the specified IndexedLabel, zero when this IndexedLabel is equal to the specified IndexedLabel, and a positive integer when this IndexedLabel is greater than the specified IndexedLabel.
Throws:
java.lang.NullPointerException - if the specified IndexedLabel is null.

toString

public java.lang.String toString()
Returns the String representation of this IndexedLabel.

Specified by:
toString in class AbstractLabel<IndexedLabel>
Returns:
The String representation of this IndexedLabel.
See Also:
Object.toString()

hashCode

public int hashCode()
Returns a hash code for this IndexedLabel.

Specified by:
hashCode in class AbstractLabel<IndexedLabel>
Returns:
The hash code value for this IndexedLabel.
See Also:
Object.hashCode()