laser.alphabet
Class IndexedAlphabet

java.lang.Object
  extended by laser.alphabet.Alphabet<IndexedLabel>
      extended by laser.alphabet.IndexedAlphabet
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<IndexedLabel>, java.util.Collection<IndexedLabel>, java.util.Set<IndexedLabel>, AlphabetFactoryInterface<IndexedLabel>, AlphabetInterface<IndexedLabel>, ArtifactInterface, Annotatable, Persistent, Visualizable

public class IndexedAlphabet
extends Alphabet<IndexedLabel>

This type of Alphabet contains IndexedLabels, which represent integer indices. Also associated with IndexedAlphabets is an integer value, N, that determines the maximum index of all IndexedLabels in the Alphabet. The index of every IndexedLabel in an IndexedAlphabet must fall in the range 0 to (N - 1), inclusive, for the value of N associated with the IndexedAlphabet.

IndexedAlphabets should only be instantiated via the createAlphabetInterface method of Indexed Alphabet factories.

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

Field Summary
 
Fields inherited from class laser.alphabet.Alphabet
factory, labels
 
Fields inherited from interface laser.util.Persistent
PER_EXTENSION, READ_PERSISTENT_METHOD_NAME
 
Constructor Summary
protected IndexedAlphabet(IndexedAlphabet alphabet)
          Creates an Alphabet that is an unmodifiable view of the specified IndexedAlphabet.
protected IndexedAlphabet(int maxIndex)
          Creates a new IndexedAlphabet with the specified int value for N.
 
Method Summary
 boolean add(IndexedLabel label)
          Adds the specified IndexedLabel to this IndexedAlphabet and returns true if it is not already contained within the IndexedAlphabet, otherwise false is returned and the IndexedAlphabet remains unchanged.
 boolean addAll(java.util.Collection<? extends IndexedLabel> c)
          Adds all of the IndexedLabels in the specified Collection to this IndexedAlphabet.
 IndexedLabel createLabelInterface(java.lang.Integer index)
          Gets an IndexedLabel specified by index.
 IndexedLabel createLabelInterface(java.lang.String inputString)
          Gets an IndexedLabel specified by the inputString.
 boolean equals(java.lang.Object o)
          Tests the specified Object and this IndexedAlphabet for equivalence.
 int getMaxIndex()
          Gets the value of N in the range 0 to (N - 1), inclusive, that all IndexedLabels in this IndexedAlphabet must fall between, inclusive.
 boolean isValidLabel(java.lang.String s)
          Returns true if the specified String specifies a valid IndexedLabel, false otherwise.
 
Methods inherited from class laser.alphabet.Alphabet
addAnnotation, addAnnotations, clear, clone, collectionChecker, contains, containsAll, copyAnnotations, createAlphabetInterface, getAnnotationClasses, getAnnotationClasses, getAnnotationFilters, getAnnotations, getAnnotations, getChangeManager, getCreateAlphabetArgs, getName, getVisExtension, hashCode, isEmpty, iterator, readPersistent, readPersistent, remove, removeAll, removeAnnotation, removeAnnotations, removeAnnotations, removeAnnotations, retainAll, setAnnotationFilters, setName, size, sortedIterator, toArray, toArray, toString, unmodifiableAlphabet, visualize, visualize, writePersistent, writePersistent
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IndexedAlphabet

protected IndexedAlphabet(int maxIndex)
Creates a new IndexedAlphabet with the specified int value for N. The createLabelInterface method is used to create all the IndexedLabels in the range 0 to (N - 1), and the Labels are added to the new alphabet.

Precondition: maxIndex > 0.

Parameters:
maxIndex - The int value for N. (must be > 0)
Throws:
java.lang.IllegalArgumentException - if maxIndex <= 0.
InconsistentObjectError - if an error occurs while creating the IndexedLabels.

IndexedAlphabet

protected IndexedAlphabet(IndexedAlphabet alphabet)
Creates an Alphabet that is an unmodifiable view of the specified IndexedAlphabet.

Parameters:
alphabet - The IndexedAlphabet.
Method Detail

createLabelInterface

public IndexedLabel createLabelInterface(java.lang.String inputString)
                                  throws AlphabetInterfaceException
Gets an IndexedLabel specified by the inputString.

The input String must represent an integer value that falls in the range 0 to (N - 1), inclusive, for the value of N associated with this IndexedAlphabet.

Specified by:
createLabelInterface in interface AlphabetFactoryInterface<IndexedLabel>
Overrides:
createLabelInterface in class Alphabet<IndexedLabel>
Parameters:
inputString - The String from which the IndexedLabel is constructed.
Returns:
The IndexedLabel.
Throws:
AlphabetInterfaceException - When the input String does not represent an integer value that falls in the range 0 to (N - 1), inclusive, for the value of N associated with this IndexedAlphabet.
java.lang.NullPointerException - When the input String is null.
See Also:
IndexedAlphabetFactory.createLabelInterface(String)

createLabelInterface

public IndexedLabel createLabelInterface(java.lang.Integer index)
                                  throws AlphabetInterfaceException
Gets an IndexedLabel specified by index.

index must fall in the range 0 to (N - 1), inclusive, for the value of N associated with this IndexedAlphabet.

Parameters:
index - The Integer from which the IndexedLabel is constructed.
Returns:
The IndexedLabel.
Throws:
AlphabetInterfaceException - When the input Integer does not fall in the range 0 to (N - 1), inclusive, for the value of N associated with this IndexedAlphabet.
java.lang.NullPointerException - When the input Integer is null.
See Also:
IndexedAlphabetFactory.createLabelInterface(Integer)

isValidLabel

public boolean isValidLabel(java.lang.String s)
Returns true if the specified String specifies a valid IndexedLabel, false otherwise.

Specified by:
isValidLabel in interface AlphabetFactoryInterface<IndexedLabel>
Overrides:
isValidLabel in class Alphabet<IndexedLabel>
Parameters:
s - The String.
Returns:
true if the specified String specifies a valid IndexedLabel, false otherwise.
Throws:
java.lang.NullPointerException - The specified String is null.
See Also:
createLabelInterface(String)

add

public boolean add(IndexedLabel label)
Adds the specified IndexedLabel to this IndexedAlphabet and returns true if it is not already contained within the IndexedAlphabet, otherwise false is returned and the IndexedAlphabet remains unchanged.

The index of the IndexedLabel must fall in the range 0 to (N - 1), inclusive, for the value of N specified by this IndexedAlphabet.

Specified by:
add in interface java.util.Collection<IndexedLabel>
Specified by:
add in interface java.util.Set<IndexedLabel>
Overrides:
add in class Alphabet<IndexedLabel>
Parameters:
label - IndexedLabel to be added to this Alphabet.
Returns:
true if the IndexedAlphabet did not already contain the specified IndexedLabel, false otherwise.
Throws:
java.lang.ClassCastException - if the specified Object is not an IndexedLabel.
java.lang.NullPointerException - if the specified IndexedLabel is null.
java.lang.IllegalArgumentException - if the index of the specified IndexedLabel is not between 0 and (N - 1), inclusive, for the value of N specified by this IndexedAlphabet.
See Also:
Set.add(E)

addAll

public boolean addAll(java.util.Collection<? extends IndexedLabel> c)
Adds all of the IndexedLabels in the specified Collection to this IndexedAlphabet. If all of the IndexedLabels in the specified Collection are already contained within this IndexedAlphabet, the IndexedAlphabet remains unchanged and false is returned. If any of the IndexedLabels are not so contained, they are added and true is returned.

All of the IndexedLabels contained in the specified Collection must have an index that falls between 0 and (N - 1), inclusive, for the value of N specified by this IndexedAlphabet.

Specified by:
addAll in interface java.util.Collection<IndexedLabel>
Specified by:
addAll in interface java.util.Set<IndexedLabel>
Overrides:
addAll in class Alphabet<IndexedLabel>
Parameters:
c - Collection containing IndexedLabels to be added.
Returns:
true if any IndexedLabels were actually added to this IndexedAlphabet.
Throws:
java.lang.ClassCastException - if any element of the specified Collection is not an IndexedLabel.
java.lang.NullPointerException - if the specified Collection or any IndexedLabel contained in it is null.
java.lang.IllegalArgumentException - the index of any IndexedLabel in the specified Collection does not fall between 0 and (N - 1), inclusive, for the value of N specified by this IndexedAlphabet.
See Also:
Set.addAll(java.util.Collection)

equals

public boolean equals(java.lang.Object o)
Tests the specified Object and this IndexedAlphabet for equivalence. Returns true if the given object is also a IndexedAlphabet, the two IndexedAlphabets have the same size, the two IndexedAlphabets have the same value for N (the maximum index of IndexedLabels in the IndexedAlphabets), and every IndexedLabel in the specified IndexedAlphabet is contained in this IndexedAlphabet.

Specified by:
equals in interface java.util.Collection<IndexedLabel>
Specified by:
equals in interface java.util.Set<IndexedLabel>
Overrides:
equals in class Alphabet<IndexedLabel>
Parameters:
o - Object to be compared for equality with this IndexedAlphabet.
Returns:
true if the specified Object and this IndexedAlphabet are equivalent.
See Also:
Set.equals(java.lang.Object)

getMaxIndex

public int getMaxIndex()
Gets the value of N in the range 0 to (N - 1), inclusive, that all IndexedLabels in this IndexedAlphabet must fall between, inclusive. (The maximum index of IndexedLabels in this IndexedAlphabet).

Returns:
The value of N (the maximum index).