laser.alphabet.labelpattern
Class StringLabelPatternFactory

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

public class StringLabelPatternFactory
extends AbstractLabelPatternFactory<StringLabel>

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

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:
StringAlphabetFactory, laser.alphabetinterface.labelpatterninterface.LabelPatternInterface, laser.alphabetinterface.labelpatterninterface.LabelPatternFactoryInterface

Field Summary
 
Fields inherited from class laser.alphabet.labelpattern.AbstractLabelPatternFactory
alphabetFactory
 
Constructor Summary
protected StringLabelPatternFactory()
          Creates an instance of StringLabelPatternFactory.
 
Method Summary
 LabelPatternInterface<StringLabel> createAllLabelPatternInterface()
          Creates a . or "all" LabelPattern.
 ClassSetLabelPatternInterface<StringLabel> createClassSetLabelPatternInterface()
          Creates a "class set" LabelPattern.
 LabelPatternInterface<StringLabel> createLabelPatternInterface(java.lang.String pattern)
          Creates a LabelPattern that has meaning with respect to StringLabels based on the specified String.
 NotClassSetLabelPatternInterface<StringLabel> createNotClassSetLabelPatternInterface()
          Creates a ~ or "not class set" LabelPattern.
static StringLabelPatternFactory getInstance()
          Return a reference to the single instance of this class.
 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

StringLabelPatternFactory

protected StringLabelPatternFactory()
Creates an instance of StringLabelPatternFactory.

Method Detail

getInstance

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

Returns:
The reference.

createAllLabelPatternInterface

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

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

createClassSetLabelPatternInterface

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

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

createNotClassSetLabelPatternInterface

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

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

createLabelPatternInterface

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

The String may specify an AllLabelPattern that has meaning with respect to StringLabels or it may specify a "class set" or "not class set" LabelPattern that has meaning with respect to StringLabels. 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 an AllLabelPattern that has meaning with respect to StringLabels, it must conform to the following grammar:

StringAllLabelPattern -> "."

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

StringClassSetOrNotClassSetLabelPattern -> StringClassSetLabelPattern |
StringNotClassSetLabelPattern
StringClassSetLabelPattern -> "{" StringLabels "}"
StringNotClassSetLabelPattern -> "~" "{" StringLabels "}"
StringLabelsAndPatterns -> StringLabel ("," StringLabel)*

StringLabel is a valid String specification of an StringLabel. This is restricted somewhat from the definition given in StringAlphabetFactory. The String specifying the StringLabel may not equal the empty string, "", and may not contain '{', '}', ',', or any whitespace as defined in Character.isWhitespace(). If a StringLabel containing any of these restricted Strings needs to be included in the created ClassSetLabelPattern or NotClassSetLabelPattern, then it should be created separately using the createLabelInterface() method and added to the LabelPattern via the addIncludedLabel() or addExcludedLabel() method, as appropriate.

If the input String conforms to the grammar specified above for StringClassSetLabelPattern, a ClassSetLabelPattern is created from the Set of all the StringLabels specified by the String.

Likewise, if the input String conforms to the grammar specified above for StringNotClassSetLabelPattern, a NotClassSetLabelPattern is created from the Set of all the StringLabels specified by the String.

Specified by:
createLabelPatternInterface in interface LabelPatternFactoryInterface<StringLabel>
Specified by:
createLabelPatternInterface in class AbstractLabelPatternFactory<StringLabel>
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.
See Also:
AllLabelPattern, ClassSetLabelPattern, NotClassSetLabelPattern, Character.isWhitespace(char), StringAlphabetFactory.createLabelInterface(String), ClassSetLabelPattern.addIncludedLabel(L), NotClassSetLabelPattern.addExcludedLabel(L)

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<StringLabel>
Specified by:
isValidLabelPattern in class AbstractLabelPatternFactory<StringLabel>
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)