laser.alphabet.labelpattern
Class AbstractLabelPatternFactory<L extends LabelInterface>

java.lang.Object
  extended by laser.alphabet.labelpattern.AbstractLabelPatternFactory<L>
Type Parameters:
L - The type of Labels that this factory produces, and the type of Label with respect to which the LabelPatterns this factory produces have meaning.
All Implemented Interfaces:
AlphabetFactoryInterface<L>, LabelPatternFactoryInterface<L>
Direct Known Subclasses:
IndexedLabelPatternFactory, StringLabelPatternFactory

public abstract class AbstractLabelPatternFactory<L extends LabelInterface>
extends java.lang.Object
implements LabelPatternFactoryInterface<L>

A basic implementation of LabelPatternFactory functionality. This class only implements the functionality universal to all types of LabelPatternFactories and leaves the remainder for subclasses to implement.

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

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)

Field Summary
protected  AlphabetFactoryInterface<L> alphabetFactory
          The AlphabetFactoryInterface responsible for creating Alphabets and Labels.
 
Constructor Summary
protected AbstractLabelPatternFactory(AlphabetFactoryInterface<L> alphabetFactory)
          Creates a new AbstractLabelPatternFactory that uses the specified AlphabetFactoryInterface to create Alphabets and Labels.
 
Method Summary
protected  AllLabelPattern<L> _internalCreateAllLabelPattern(java.lang.Class<L> labelClass)
          Creates a new AllLabelPattern.
protected  ClassSetLabelPattern<L> _internalCreateClassSetLabelPattern(java.lang.Class<L> labelClass)
          Creates a new ClassSetLabelPattern.
protected  NotClassSetLabelPattern<L> _internalCreateNotClassSetLabelPattern(java.lang.Class<L> labelClass)
          Creates a new NotClassSetLabelPattern.
abstract  LabelPatternInterface<L> createAllLabelPatternInterface()
          Creates a . or "all" LabelPattern.
 AlphabetInterface<L> createAlphabetInterface(java.lang.Object... args)
          Creates an Alphabet of the appropriate type for the factory.
abstract  ClassSetLabelPatternInterface<L> createClassSetLabelPatternInterface()
          Creates a "class set" LabelPattern.
 L createLabelInterface(java.lang.String inputString)
          Gets a Label of the type appropriate for the factory.
abstract  LabelPatternInterface<L> createLabelPatternInterface(java.lang.String pattern)
          Creates a LabelPattern based on the specified String.
abstract  NotClassSetLabelPatternInterface<L> createNotClassSetLabelPatternInterface()
          Creates a ~ or "not class set" LabelPattern.
 java.lang.Object[] getCreateAlphabetArgs(AlphabetInterface<L> alphabet)
          Gets any required arguments for the create alphabet method from the given alphabet.
 boolean isValidLabel(java.lang.String s)
          Returns true if the specified String specifies a valid Label of the type this factory creates, false otherwise.
abstract  boolean isValidLabelPattern(java.lang.String s)
          Returns true if the specified String specifies a valid LabelPattern of the type this factory creates, false otherwise.
 AlphabetInterface<L> unmodifiableAlphabet(AlphabetInterface<L> alphabet)
          Returns an unmodifiable view of the specified Alphabet (optional operation).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

alphabetFactory

protected transient AlphabetFactoryInterface<L extends LabelInterface> alphabetFactory
The AlphabetFactoryInterface responsible for creating Alphabets and Labels.

Constructor Detail

AbstractLabelPatternFactory

protected AbstractLabelPatternFactory(AlphabetFactoryInterface<L> alphabetFactory)
Creates a new AbstractLabelPatternFactory that uses the specified AlphabetFactoryInterface to create Alphabets and Labels.

Parameters:
alphabetFactory - The AlphabetFactoryInterface that this factory will use to create Alphabets and Labels.
Throws:
java.lang.NullPointerException - When the specified AlphabetFactoryInterface is null.
Method Detail

_internalCreateAllLabelPattern

protected AllLabelPattern<L> _internalCreateAllLabelPattern(java.lang.Class<L> labelClass)
Creates a new AllLabelPattern. This method should only be called by the createAllLabelPatternInterface() method of subclasses of this class.

Precondition: labelClass is not null and refers to the same class as L.

Parameters:
labelClass - the class of Label with respect to which the returned AllLabelPattern will have meaning.
Returns:
the AllLabelPattern.

_internalCreateClassSetLabelPattern

protected ClassSetLabelPattern<L> _internalCreateClassSetLabelPattern(java.lang.Class<L> labelClass)
Creates a new ClassSetLabelPattern. This method should only be called by the createClassSetLabelPatternInterface() method of subclasses of this class.

Precondition: labelClass is not null and refers to the same class as L, labelPatternClass is null or it refers to the class of LabelPatterns that have meaning with respect to Labels of type labelClass.

Parameters:
labelClass - the class of Label with respect to which the returned ClassSetLabelPattern will have meaning.
Returns:
the ClassSetLabelPattern.

_internalCreateNotClassSetLabelPattern

protected NotClassSetLabelPattern<L> _internalCreateNotClassSetLabelPattern(java.lang.Class<L> labelClass)
Creates a new NotClassSetLabelPattern. This method should only be called by the createNotClassSetLabelPatternInterface() method of subclasses of this class.

Precondition: labelClass is not null and refers to the same class as L, labelPatternClass is null or it refers to the class of LabelPatterns that have meaning with respect to Labels of type labelClass.

Parameters:
labelClass - the class of Label with respect to which the returned NotClassSetLabelPattern will have meaning.
Returns:
the NotClassSetLabelPattern.

createAllLabelPatternInterface

public abstract LabelPatternInterface<L> createAllLabelPatternInterface()
Creates a . or "all" LabelPattern. With respect to an Alphabet of the correct type, this LabelPattern specifies the set of all Labels in the Alphabet.

Specified by:
createAllLabelPatternInterface in interface LabelPatternFactoryInterface<L extends LabelInterface>
Returns:
The "all" LabelPattern.
See Also:
laser.alphabetinterface.labelpatterninterface.ClassSetLabelPatternInterface, AllLabelPattern

createClassSetLabelPatternInterface

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

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

createNotClassSetLabelPatternInterface

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

Specified by:
createNotClassSetLabelPatternInterface in interface LabelPatternFactoryInterface<L extends LabelInterface>
Returns:
The "not class set" LabelPattern.
See Also:
laser.alphabetinterface.labelpatterninterface.NotClassSetLabelPatternInterface, NotClassSetLabelPattern

createLabelPatternInterface

public abstract LabelPatternInterface<L> createLabelPatternInterface(java.lang.String pattern)
                                                                                     throws LabelPatternInterfaceException
Creates a LabelPattern based on the specified String. The allowable Strings depends on the type of LabelPattern that this factory creates.

Specified by:
createLabelPatternInterface in interface LabelPatternFactoryInterface<L extends LabelInterface>
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:
laser.alphabetinterface.labelpatterninterface.LabelPatternInterface

isValidLabelPattern

public abstract 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<L extends LabelInterface>
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)

createLabelInterface

public L createLabelInterface(java.lang.String inputString)
                                              throws AlphabetInterfaceException
Gets a Label of the type appropriate for the factory.

Since all Labels participate in flyweighting, (Design Patterns, Gamma, Helm, Johnson, and Vlissides, p195, 1995) thus each factory maintains a repository of Labels of the type it creates. If the Label specified by the inputString already exists, a reference to it is returned. Otherwise, a new Label is constructed from the inputString, added to the repository, and returned.

Specified by:
createLabelInterface in interface AlphabetFactoryInterface<L extends LabelInterface>
Parameters:
inputString - The String from which the Label is constructed.
Returns:
The Label.
Throws:
AlphabetInterfaceException - When the label for the specified inputSting cannot be created.

createAlphabetInterface

public AlphabetInterface<L> createAlphabetInterface(java.lang.Object... args)
                                                                    throws AlphabetInterfaceException
Creates an Alphabet of the appropriate type for the factory.

Specified by:
createAlphabetInterface in interface AlphabetFactoryInterface<L extends LabelInterface>
Parameters:
args - The input arguments used in the construction of the Alphabet.
Returns:
The Alphabet.
Throws:
AlphabetInterfaceException - When the Alphabet cannot be created from the specified input arguments.

getCreateAlphabetArgs

public java.lang.Object[] getCreateAlphabetArgs(AlphabetInterface<L> alphabet)
Gets any required arguments for the create alphabet method from the given alphabet.

PRECONDITION: The alphabet must be non-null.

Specified by:
getCreateAlphabetArgs in interface AlphabetFactoryInterface<L extends LabelInterface>
Parameters:
alphabet - The alphabet to use as a prototype
Returns:
Any required arguments for the create alphabet method

isValidLabel

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

Specified by:
isValidLabel in interface AlphabetFactoryInterface<L extends LabelInterface>
Parameters:
s - The String.
Returns:
true if the specified String specifies a valid Label of the type this factory creates, false otherwise.
Throws:
java.lang.NullPointerException - The specified String is null.
See Also:
createLabelInterface(String)

unmodifiableAlphabet

public AlphabetInterface<L> unmodifiableAlphabet(AlphabetInterface<L> alphabet)
Returns an unmodifiable view of the specified Alphabet (optional operation). Any attempt to modify the returned Alphabet will result in an UnsupportedOperationException being thrown.

Specified by:
unmodifiableAlphabet in interface AlphabetFactoryInterface<L extends LabelInterface>
Parameters:
alphabet - The Alphabet.
Returns:
An unmodifiable view of the specified Alphabet.
Throws:
java.lang.NullPointerException - the specified Alphabet is null.
java.lang.UnsupportedOperationException - this method is not supported.