laser.alphabet.labelpattern
Class IndexedLabelPatternFactory

java.lang.Object
  extended by laser.alphabet.labelpattern.AbstractLabelPatternFactory<IndexedLabel>
      extended by laser.alphabet.labelpattern.IndexedLabelPatternFactory
All Implemented Interfaces:
AlphabetFactoryInterface<IndexedLabel>, LabelPatternFactoryInterface<IndexedLabel>

public class IndexedLabelPatternFactory
extends AbstractLabelPatternFactory<IndexedLabel>

Extends the functionality provided by IndexedAlphabetFactory, allowing the creation of IndexedLabels and Alphabets of IndexedLabels as well as LabelPatterns that specify subsets of Alphabets of IndexedLabels.

LabelPatternFactories are factories as in the factory design pattern, (Design Patterns, Gamma, Helm, Johnson, and Vlissides, p87, 1995).

This class uses the singleton design pattern, (Design Patterns, Gamma, Helm, Johnson, and Vlissides, p127, 1995) and thus there is only one instance of this class, and that single instance is referenced through a static point of access.

Note that this class is not synchronized, and attempts to use it with non-sequential code may result in unexpected behavior.

Author:
Nathan A. Jokel (laser-software@cs.umass.edu)
See Also:
IndexedAlphabetFactory, laser.alphabetinterface.labelpatterninterface.LabelPatternInterface, laser.alphabetinterface.labelpatterninterface.LabelPatternFactoryInterface, IndexedLabelPattern

Field Summary
 
Fields inherited from class laser.alphabet.labelpattern.AbstractLabelPatternFactory
alphabetFactory
 
Constructor Summary
protected IndexedLabelPatternFactory()
          Creates an instance of IndexedLabelPatternFactory.
 
Method Summary
 LabelPatternInterface<IndexedLabel> createAllLabelPatternInterface()
          Creates a . or "all" LabelPattern.
 ClassSetLabelPatternInterface<IndexedLabel> createClassSetLabelPatternInterface()
          Creates a "class set" LabelPattern.
 LabelPatternInterface<IndexedLabel> createIndexedLabelPattern(int lowerBound, int upperBound)
          Creates an IndexedLabelPattern from the specified lower bound and upper bound.
 IndexedLabel createLabelInterface(java.lang.Integer index)
          Gets an IndexedLabel specified by index.
 LabelPatternInterface<IndexedLabel> createLabelPatternInterface(java.lang.String pattern)
          Creates a LabelPattern that has meaning with respect to IndexedLabels based on the specified String.
 NotClassSetLabelPatternInterface<IndexedLabel> createNotClassSetLabelPatternInterface()
          Creates a ~ or "not class set" LabelPattern.
static IndexedLabelPatternFactory getInstance()
          Return a reference to the single instance of this class.
 int getLargestIndex()
          Returns the index of the largest existing IndexedLabel, or -1 if there are none in existence.
 boolean isValidLabelPattern(java.lang.String s)
          Returns true if the specified String specifies a valid LabelPattern of the type this factory creates, false otherwise.
 
Methods inherited from class laser.alphabet.labelpattern.AbstractLabelPatternFactory
_internalCreateAllLabelPattern, _internalCreateClassSetLabelPattern, _internalCreateNotClassSetLabelPattern, createAlphabetInterface, createLabelInterface, getCreateAlphabetArgs, isValidLabel, unmodifiableAlphabet
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IndexedLabelPatternFactory

protected IndexedLabelPatternFactory()
Creates an instance of IndexedLabelPatternFactory.

Method Detail

getInstance

public static IndexedLabelPatternFactory getInstance()
Return a reference to the single instance of this class.

Returns:
The reference.

createLabelInterface

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

Index must be >= 0, and <= the index of the largest existing IndexedLabel + 1.

Parameters:
index - The Integer from which the IndexedLabel is constructed.
Returns:
The IndexedLabel.
Throws:
AlphabetInterfaceException - When the input Integer is not >= 0.
java.lang.NullPointerException - When the input Integer is null.
java.lang.UnsupportedOperationException - When the input Integer is > the index of the largest existing IndexedLabel + 1.
See Also:
IndexedAlphabetFactory.createLabelInterface(Integer), getLargestIndex()

getLargestIndex

public int getLargestIndex()
Returns the index of the largest existing IndexedLabel, or -1 if there are none in existence.

Returns:
the index of the largest existing IndexedLabel, or -1 if there are none in existence.

createAllLabelPatternInterface

public LabelPatternInterface<IndexedLabel> createAllLabelPatternInterface()
Creates a . or "all" LabelPattern. With respect to an Alphabet of IndexedLabels, this LabelPattern specifies the set of all IndexedLabels in the Alphabet.

Specified by:
createAllLabelPatternInterface in interface LabelPatternFactoryInterface<IndexedLabel>
Specified by:
createAllLabelPatternInterface in class AbstractLabelPatternFactory<IndexedLabel>
Returns:
The "all" LabelPattern.
See Also:
laser.alphabetinterface.labelpatterninterface.LabelPatternInterface, AllLabelPattern

createClassSetLabelPatternInterface

public ClassSetLabelPatternInterface<IndexedLabel> createClassSetLabelPatternInterface()
Creates a "class set" LabelPattern. With respect to an Alphabet of IndexedLabels, this LabelPattern specifies the subset of IndexedLabels in the Alphabet that have been explicitly specified as being included in the subset.

Specified by:
createClassSetLabelPatternInterface in interface LabelPatternFactoryInterface<IndexedLabel>
Specified by:
createClassSetLabelPatternInterface in class AbstractLabelPatternFactory<IndexedLabel>
Returns:
The "class set" LabelPattern.
See Also:
laser.alphabetinterface.labelpatterninterface.LabelPatternInterface, ClassSetLabelPattern

createNotClassSetLabelPatternInterface

public NotClassSetLabelPatternInterface<IndexedLabel> createNotClassSetLabelPatternInterface()
Creates a ~ or "not class set" LabelPattern. With respect to an Alphabet of IndexedLabels, this LabelPattern specifies the subset of all IndexedLabels in the Alphabet except for certain IndexedLabels which are explicitly excluded from the subset.

Specified by:
createNotClassSetLabelPatternInterface in interface LabelPatternFactoryInterface<IndexedLabel>
Specified by:
createNotClassSetLabelPatternInterface in class AbstractLabelPatternFactory<IndexedLabel>
Returns:
The "not class set" LabelPattern.
See Also:
laser.alphabetinterface.labelpatterninterface.LabelPatternInterface, NotClassSetLabelPattern

createLabelPatternInterface

public LabelPatternInterface<IndexedLabel> createLabelPatternInterface(java.lang.String pattern)
                                                                throws LabelPatternInterfaceException
Creates a LabelPattern that has meaning with respect to IndexedLabels based on the specified String.

The String may specify a single IndexedLabelPattern, an AllLabelPattern that has meaning with respect to IndexedLabels, or it may specify a "class set" or "not class set" LabelPattern that has meaning with respect to IndexedLabels. The String can not specify nested "class set" or "not class set" LabelPatterns: "class set" or "not class set" LabelPatterns that contain other "class set" or not "class set" LabelPatterns. To create such LabelPatterns, use the createClassSetLabelPatternInterface or createNotClassSetLabelPatternInterface methods.

If the input String is to specify a single IndexedLabelPattern, it must obey the following grammar:

IndexedLabelPattern -> "{" LowerBound "-" UpperBound "}"

LowerBound and UpperBound must be integers >= 0. LowerBound must be <= UpperBound.

LowerBound specifies the lower bound of the IndexedLabelPattern, and UpperBound specifies its upper bound.

If the input String is to specify an AllLabelPattern that has meaning with respect to IndexedLabels, it must conform to the following grammar:

IndexedAllLabelPattern -> "."

If the input String is to specify a "class set" or "not class set" LabelPattern that has meaning with respect to IndexedLabels, it must conform to the following grammar:

IndexedClassSetOrNotClassSetLabelPattern -> IndexedClassSetLabelPattern |
IndexedNotClassSetLabelPattern
IndexedClassSetLabelPattern -> "{" IndexedLabelsAndPatterns "}"
IndexedNotClassSetLabelPattern -> "~" "{" IndexedLabelsAndPatterns "}"
IndexedLabelsAndPatterns -> IndexedLabelOrPattern ("," IndexedLabelOrPattern)*
IndexedLabelOrPattern -> IndexedLabel | IndexedLabelPattern

IndexedLabel is a valid String specification of an IndexedLabel, as defined in IndexedAlphabetFactory, and IndexedLabelPattern is a valid String specification of an IndexedLabelPattern, as specified above.

If the input String conforms to the grammar specified above for IndexedClassSetLabelPattern, a ClassSetLabelPattern is created from the Set of all the IndexedLabels specified by the String and the Set of all IndexedLabelPatterns specified by the String.

Likewise, if the input String conforms to the grammar specified above for IndexedNotClassSetLabelPattern, a NotClassSetLabelPattern is created from the Set of all the IndexedLabels specified by the String and the Set of all IndexedLabelPatterns specified by the String.

Specified by:
createLabelPatternInterface in interface LabelPatternFactoryInterface<IndexedLabel>
Specified by:
createLabelPatternInterface in class AbstractLabelPatternFactory<IndexedLabel>
Parameters:
pattern - A String specifying the LabelPattern to be created.
Returns:
The LabelPattern.
Throws:
java.lang.NullPointerException - The specified String is null.
LabelPatternInterfaceException - The specified String does not correspond to a valid LabelPattern.
java.lang.UnsupportedOperationException - The input String specifies an IndexedLabel of which the index is > the index of the largest existing IndexedLabel + 1.
See Also:
IndexedLabelPattern, AllLabelPattern, ClassSetLabelPattern, NotClassSetLabelPattern, IndexedAlphabetFactory.createLabelInterface(String), IndexedAlphabetFactory.getLargestIndex()

createIndexedLabelPattern

public LabelPatternInterface<IndexedLabel> createIndexedLabelPattern(int lowerBound,
                                                                     int upperBound)
                                                              throws LabelPatternInterfaceException
Creates an IndexedLabelPattern from the specified lower bound and upper bound.

lowerBound and upperBound must be integers >= 0. lowerBound must be <= upperBound.

lowerBound specifies the lower bound of the IndexedLabelPattern, and upperBound specifies its upper bound.

Throws:
LabelPatternInterfaceException - The specified lower and upper bound do not specify a valid IndexedLabelPattern
See Also:
IndexedLabelPattern

isValidLabelPattern

public boolean isValidLabelPattern(java.lang.String s)
Returns true if the specified String specifies a valid LabelPattern of the type this factory creates, false otherwise.

Specified by:
isValidLabelPattern in interface LabelPatternFactoryInterface<IndexedLabel>
Specified by:
isValidLabelPattern in class AbstractLabelPatternFactory<IndexedLabel>
Parameters:
s - The String.
Returns:
true if the specified String specifies a valid LabelPattern of the type this factory creates, false otherwise.
Throws:
java.lang.NullPointerException - The specified String is null.
See Also:
createLabelPatternInterface(String)