laser.alphabet
Class StringAlphabetFactory

java.lang.Object
  extended by laser.alphabet.StringAlphabetFactory
All Implemented Interfaces:
AlphabetFactoryInterface<StringLabel>

public class StringAlphabetFactory
extends java.lang.Object
implements AlphabetFactoryInterface<StringLabel>

This AlphabetFactory, as in the factory design pattern, (Design Patterns, Gamma, Helm, Johnson, and Vlissides, p87, 1995), is used to create StringLabels and Alphabets of StringLabels.

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:
Alphabet, StringLabel

Nested Class Summary
 class StringAlphabetFactory.TestProbe
          Provides, for testing purposes only, methods necessary for testing the StringAlphabetFactory class that should not under any circumstances be invoked during normal operation.
 
Constructor Summary
protected StringAlphabetFactory()
          Creates an instance of StringAlphabetFactory.
 
Method Summary
 AlphabetInterface<StringLabel> createAlphabetInterface(java.lang.Object... args)
          Creates a new Alphabet of StringLabels.
 StringLabel createLabelInterface(java.lang.String inputString)
          Gets a StringLabel specified by the inputString.
 java.lang.Object[] getCreateAlphabetArgs(AlphabetInterface<StringLabel> alphabet)
          Gets any required arguments for the create alphabet method from the given alphabet.
static StringAlphabetFactory getInstance()
          Return a reference to the single instance of this class.
 StringAlphabetFactory.TestProbe getTestProbe()
          Returns a TestProbe that provides for testing purposes only, methods necessary for testing the StringAlphabetFactory class that should not under any circumstances be invoked during normal operation.
 boolean isValidLabel(java.lang.String s)
          Returns true if the specified String specifies a valid StringLabel, false otherwise.
 AlphabetInterface<StringLabel> unmodifiableAlphabet(AlphabetInterface<StringLabel> alphabet)
          Returns an unmodifiable view of the specified Alphabet of StringLabels.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringAlphabetFactory

protected StringAlphabetFactory()
Creates an instance of StringAlphabetFactory.

Method Detail

getInstance

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

Returns:
The reference.

createLabelInterface

public StringLabel createLabelInterface(java.lang.String inputString)
                                 throws AlphabetInterfaceException
Gets a StringLabel specified by the inputString. Like all Labels, StringLabels participate in flyweighting, (Design Patterns, Gamma, Helm, Johnson, and Vlissides, p195, 1995) thus StringAlphabetFactory maintains a repository of StringLabels. If the StringLabel specified by the inputString already exists, a reference to it is returned. Otherwise, a new StringLabel is constructed from the inputString, added to the repository, and returned.

Specified by:
createLabelInterface in interface AlphabetFactoryInterface<StringLabel>
Parameters:
inputString - The String from which the StringLabel is constructed.
Returns:
The StringLabel.
Throws:
AlphabetInterfaceException - When the StringLabel cannot be created from the specified input String.
java.lang.NullPointerException - When the input String is null.

createAlphabetInterface

public AlphabetInterface<StringLabel> createAlphabetInterface(java.lang.Object... args)
                                                       throws AlphabetInterfaceException
Creates a new Alphabet of StringLabels.

Specified by:
createAlphabetInterface in interface AlphabetFactoryInterface<StringLabel>
Parameters:
args - The input arguments. There should be exactly 0.
Returns:
The Alphabet of StringLabels.
Throws:
AlphabetInterfaceException - When there are not exactly 0 input arguments.

getCreateAlphabetArgs

public java.lang.Object[] getCreateAlphabetArgs(AlphabetInterface<StringLabel> 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<StringLabel>
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 StringLabel, false otherwise.

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

unmodifiableAlphabet

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

Specified by:
unmodifiableAlphabet in interface AlphabetFactoryInterface<StringLabel>
Parameters:
alphabet - The Alphabet.
Returns:
An unmodifiable view of the specified Alphabet.
Throws:
java.lang.ClassCastException - the specified Alphabet is not an instance of Alphabet.
java.lang.NullPointerException - the specified Alphabet is null.

getTestProbe

public StringAlphabetFactory.TestProbe getTestProbe()
Returns a TestProbe that provides for testing purposes only, methods necessary for testing the StringAlphabetFactory class that should not under any circumstances be invoked during normal operation.

Returns:
The TestProbe.