laser.regularlanguage.fsa
Class AbstractFSAFactory<L extends LabelInterface>

java.lang.Object
  extended by laser.regularlanguage.fsa.AbstractFSAFactory<L>
Type Parameters:
L - The type of Label associated with the FSAs that this factory creates.
All Implemented Interfaces:
java.io.Serializable, FSAFactoryInterface<L>
Direct Known Subclasses:
IndexedFSAFactory, StringFSAFactory

public abstract class AbstractFSAFactory<L extends LabelInterface>
extends java.lang.Object
implements FSAFactoryInterface<L>, java.io.Serializable

An abstract class extended by all factories that create finite state automata (FSAs) of type AbstractFSA. This is a factory as in the design pattern, (Design Patterns, Gamma, Helm, Johnson,and Vlissides, pp 87, 107, 1995). Factories of this type create FSAs associated with one particular type of Label.

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

Author:
Nathan Jokel (laser-software@cs.umass.edu)
See Also:
AbstractFSA, FSAFactoryInterface, Serialized Form

Field Summary
protected  AlphabetFactoryInterface<L> alphabetFactory
          An Alphabet factory used to create the Alphabets for the FSAs this factory creates.
 
Constructor Summary
protected AbstractFSAFactory(AlphabetFactoryInterface<L> alphabetFactory)
          Creates a new AbstractFSAFactory that uses the specified AlphabetFactoryInterface to create the Alphabets for the FSAs it creates.
 
Method Summary
protected  FSAStateInterface<L> _copyStateInto(FSAInterface<L> fsa, FSAStateInterface<L> state, int id)
          Creates a new FSAStateInterface in the given FSA with the same ID and name as the specified state.
protected  FSATransitionInterface<L> _copyTransitionInto(FSAInterface<L> fsa, FSATransitionInterface<L> transition, int id, FSAStateInterface<L> source, FSAStateInterface<L> target)
          Creates a new FSATransitionInterface in the given FSA with the same ID as the specified transition.
protected  FSAEpsilonTransitionInterface<L> _createFSAEpsilonTransitionInterface(int id, FSAStateInterface<L> source, FSAStateInterface<L> target, java.lang.Object... args)
          Returns a new FSAEpsilonTransitionInterface with the specified source and target states and ID using the specified arguments.
protected  FSALabelPatternTransitionInterface<L> _createFSALabelPatternTransitionInterface(int id, FSAStateInterface<L> source, LabelPatternInterface<L> labelPattern, FSAStateInterface<L> target, java.lang.Object... args)
          Returns a new FSALabelPatternTransitionInterface with the specified source and target states, ID, and LabelPattern using the specified arguments.
protected  FSALabelTransitionInterface<L> _createFSALabelTransitionInterface(int id, FSAStateInterface<L> source, L label, FSAStateInterface<L> target, java.lang.Object... args)
          Returns a new FSALabelTransitionInterface with the specified source and target states, ID, and Label using the specified arguments.
protected  FSAStateInterface<L> _createFSAStateInterface(FSAInterface<L> fsa, int id, boolean accept, java.lang.Object... args)
          Returns a new FSAStateInterface in the given FSA with the specified ID using the specified arguments.
protected  MutableDFAInterface<L> _internalCreateMutableDFAInterface(AlphabetInterface<L> alphabet, AbstractFSAFactory<L> factory)
          Instantiates a MutableDFAInterface from the given Alphabet and FSA factory.
protected  MutableFSAInterface<L> _internalCreateMutableFSAInterface(AlphabetInterface<L> alphabet, AbstractFSAFactory<L> factory)
          Instantiates a MutableFSAInterface from the given Alphabet and FSA factory.
protected  RunnableDFAInterface<L> _internalGetRunnableDFA(MutableDFA<L> dfa)
          Instantiates a RunnableDFAInterface from the given MutableDFAInterface.
protected  RunnableFSAInterface<L> _internalGetRunnableFSA(MutableFSA<L> fsa)
          Instantiates a RunnableFSAInterface from the given MutableFSAInterface.
 MutableFSAInterface<L> createMutableFSAInterface(AlphabetInterface<L> alphabet, java.lang.Object... args)
          Creates a mutable FSA from the specified arguments.
 AlphabetFactoryInterface<L> getAlphabetFactory()
          Gets the alphabet factory to be used to create new alphabets.
 java.lang.Object[] getCreateArgs(FSAInterface<L> oldFSA)
          Gets any required arguments for the FSA factory method from the given FSA.
 java.lang.Object[] getCreateArgs(FSAInterface<L> newFSA, FSAStateInterface<L> oldState)
          Gets any required arguments for the state factory method from the given state.
 java.lang.Object[] getCreateArgs(FSAInterface<L> newFSA, FSATransitionInterface<L> oldTransition)
          Gets any required arguments for the transition factory method from the given transition.
 
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
An Alphabet factory used to create the Alphabets for the FSAs this factory creates.

Constructor Detail

AbstractFSAFactory

protected AbstractFSAFactory(AlphabetFactoryInterface<L> alphabetFactory)
Creates a new AbstractFSAFactory that uses the specified AlphabetFactoryInterface to create the Alphabets for the FSAs it creates.

Precondition: alphabetFactory is not null.

Parameters:
alphabetFactory - the AlphabetFactory.
Method Detail

_internalCreateMutableFSAInterface

protected MutableFSAInterface<L> _internalCreateMutableFSAInterface(AlphabetInterface<L> alphabet,
                                                                    AbstractFSAFactory<L> factory)
Instantiates a MutableFSAInterface from the given Alphabet and FSA factory. This method should only be called by the createMutableFSAInterface(laser.alphabet.AlphabetInterface, java.lang.Object...) method of subclasses of this class.

Precondition: alphabet and factory are not null.

Parameters:
alphabet - The alphabet.
factory - The factory.
See Also:
createMutableFSAInterface(laser.alphabet.AlphabetInterface, java.lang.Object...), RunnableFSAInterface.getMutableFSA()

_internalCreateMutableDFAInterface

protected MutableDFAInterface<L> _internalCreateMutableDFAInterface(AlphabetInterface<L> alphabet,
                                                                    AbstractFSAFactory<L> factory)
Instantiates a MutableDFAInterface from the given Alphabet and FSA factory. This method should only be called by the createMutableFSAInterface(laser.alphabet.AlphabetInterface, java.lang.Object...) method of subclasses of this class.

Precondition: alphabet and factory are not null.

Parameters:
alphabet - The alphabet.
factory - The factory.
See Also:
createMutableFSAInterface(laser.alphabet.AlphabetInterface, java.lang.Object...), RunnableFSAInterface.getMutableFSA()

_internalGetRunnableFSA

protected RunnableFSAInterface<L> _internalGetRunnableFSA(MutableFSA<L> fsa)
Instantiates a RunnableFSAInterface from the given MutableFSAInterface. This method should only be called by the MutableFSAInterface.getRunnableFSA() method.

Precondition: fsa is not null.

Parameters:
fsa - The mutable FSA.
See Also:
MutableFSAInterface.getRunnableFSA()

_internalGetRunnableDFA

protected RunnableDFAInterface<L> _internalGetRunnableDFA(MutableDFA<L> dfa)
Instantiates a RunnableDFAInterface from the given MutableDFAInterface. This method should only be called by the MutableFSAInterface.getRunnableFSA() method.

Precondition: dfa is not null.

Parameters:
dfa - The mutable DFA.
See Also:
MutableFSAInterface.getRunnableFSA()

_createFSAEpsilonTransitionInterface

protected FSAEpsilonTransitionInterface<L> _createFSAEpsilonTransitionInterface(int id,
                                                                                FSAStateInterface<L> source,
                                                                                FSAStateInterface<L> target,
                                                                                java.lang.Object... args)
Returns a new FSAEpsilonTransitionInterface with the specified source and target states and ID using the specified arguments.

This method is called by the MutableFSA.addEpsilonTransition(laser.regularlanguage.fsa.FSAStateInterface, laser.regularlanguage.fsa.FSAStateInterface, java.lang.Object...) and the _copyTransitionInto(laser.regularlanguage.fsa.FSAInterface, laser.regularlanguage.fsa.FSATransitionInterface, int, laser.regularlanguage.fsa.FSAStateInterface, laser.regularlanguage.fsa.FSAStateInterface) methods to instantiate the FSAEpsilonTransitionInterface. No other methods should call this method.

Factories extending this class that need to create FSAEpsilonTransitionInterfaces of classes other than FSAEpsilonTransition should override this method.

Preconditions: source and target are not null and are states in the same FSA.

Parameters:
id - The id.
source - The source state.
target - The target state.
args - The arguments. (optional)
Returns:
The FSAEpsilonTransitionInterface.
Throws:
java.lang.IllegalArgumentException - when the specified arguments are invalid.
See Also:
MutableFSA.addEpsilonTransition(laser.regularlanguage.fsa.FSAStateInterface, laser.regularlanguage.fsa.FSAStateInterface, java.lang.Object...), _copyTransitionInto(laser.regularlanguage.fsa.FSAInterface, laser.regularlanguage.fsa.FSATransitionInterface, int, laser.regularlanguage.fsa.FSAStateInterface, laser.regularlanguage.fsa.FSAStateInterface)

_createFSALabelTransitionInterface

protected FSALabelTransitionInterface<L> _createFSALabelTransitionInterface(int id,
                                                                            FSAStateInterface<L> source,
                                                                            L label,
                                                                            FSAStateInterface<L> target,
                                                                            java.lang.Object... args)
Returns a new FSALabelTransitionInterface with the specified source and target states, ID, and Label using the specified arguments.

This method is called by the MutableFSAInterface.addTransition(FSAStateInterface,LabelInterface,FSAStateInterface,Object[]) and the _copyTransitionInto(laser.regularlanguage.fsa.FSAInterface, laser.regularlanguage.fsa.FSATransitionInterface, int, laser.regularlanguage.fsa.FSAStateInterface, laser.regularlanguage.fsa.FSAStateInterface) methods to instantiate the FSALabelTransitionInterface. No other methods should call this method.

Factories extending this class that need to create FSALabelTransitionInterfaces of classes other than FSALabelTransition should override this method.

Preconditions: source, target, and label are not null, source and target are states in the same FSA and label is equal to a Label in the Alphabet of that FSA.

Parameters:
id - The ID.
source - The source state.
label - The label.
target - The target state.
args - The arguments. (optional)
Returns:
The FSALabelTransitionInterface.
Throws:
java.lang.IllegalArgumentException - when the specified arguments are invalid.
See Also:
MutableFSAInterface.addTransition(FSAStateInterface, LabelInterface, FSAStateInterface,Object[]), _copyTransitionInto(laser.regularlanguage.fsa.FSAInterface, laser.regularlanguage.fsa.FSATransitionInterface, int, laser.regularlanguage.fsa.FSAStateInterface, laser.regularlanguage.fsa.FSAStateInterface)

_createFSALabelPatternTransitionInterface

protected FSALabelPatternTransitionInterface<L> _createFSALabelPatternTransitionInterface(int id,
                                                                                          FSAStateInterface<L> source,
                                                                                          LabelPatternInterface<L> labelPattern,
                                                                                          FSAStateInterface<L> target,
                                                                                          java.lang.Object... args)
Returns a new FSALabelPatternTransitionInterface with the specified source and target states, ID, and LabelPattern using the specified arguments.

This method is called by the MutableFSAInterface.addTransition(FSAStateInterface,LabelPatternInterface,FSAStateInterface,Object[]) and the _copyTransitionInto(laser.regularlanguage.fsa.FSAInterface, laser.regularlanguage.fsa.FSATransitionInterface, int, laser.regularlanguage.fsa.FSAStateInterface, laser.regularlanguage.fsa.FSAStateInterface) methods to instantiate the FSALabelPatternTransitionInterface. No other methods should call this method.

Factories extending this class that need to create FSALabelPatternTransitionInterfaces of classes other than FSALabelPatternTransition should override this method.

Preconditions: source, target, and labelPattern are not null, source and target are states in the same FSA.

Parameters:
id - The ID.
source - The source state.
labelPattern - The LabelPattern.
target - The target state.
args - The arguments. (optional)
Returns:
The FSALabelPatternTransitionInterface.
Throws:
java.lang.IllegalArgumentException - when the specified arguments are invalid.
See Also:
MutableFSAInterface.addTransition(FSAStateInterface, LabelPatternInterface, FSAStateInterface,Object[]), _copyTransitionInto(laser.regularlanguage.fsa.FSAInterface, laser.regularlanguage.fsa.FSATransitionInterface, int, laser.regularlanguage.fsa.FSAStateInterface, laser.regularlanguage.fsa.FSAStateInterface)

_createFSAStateInterface

protected FSAStateInterface<L> _createFSAStateInterface(FSAInterface<L> fsa,
                                                        int id,
                                                        boolean accept,
                                                        java.lang.Object... args)
Returns a new FSAStateInterface in the given FSA with the specified ID using the specified arguments. The state will be accepting if and only if accept is true.

This method is called by the AbstractMutableFSA.addState(java.lang.Object...) and the _copyStateInto(laser.regularlanguage.fsa.FSAInterface, laser.regularlanguage.fsa.FSAStateInterface, int) methods to instantiate the FSAStateInterface. No other methods should call this method.

Factories extending this class that need to create FSAStateInterfaces of a class other than FSAState should override this method.

Preconditions: fsa is not null.

Parameters:
fsa - The FSA.
id - The ID.
accept - The state will be accepting if and only if accept is true
args - The arguments. (optional)
Returns:
The FSAStateInterface.
Throws:
java.lang.IllegalArgumentException - when the specified arguments are invalid.
See Also:
AbstractMutableFSA.addState(java.lang.Object...), _copyStateInto(laser.regularlanguage.fsa.FSAInterface, laser.regularlanguage.fsa.FSAStateInterface, int)

_copyStateInto

protected FSAStateInterface<L> _copyStateInto(FSAInterface<L> fsa,
                                              FSAStateInterface<L> state,
                                              int id)
Creates a new FSAStateInterface in the given FSA with the same ID and name as the specified state. The new state is an accept state if and only if the specified state is also an accept state. The annotations on the specified state are also copied to the new state.

Preconditions: fsa, state are not null, state is not already a state in fsa.

Parameters:
fsa - The fsa into which the state is being copied.
state - The state to copy.
id - The ID.
Returns:
The FSAStateInterface.
See Also:
Annotatable#copyAnnotations(Annotatable), MutableFSAInterface.copyState(laser.regularlanguage.fsa.FSAStateInterface, boolean, boolean)

_copyTransitionInto

protected FSATransitionInterface<L> _copyTransitionInto(FSAInterface<L> fsa,
                                                        FSATransitionInterface<L> transition,
                                                        int id,
                                                        FSAStateInterface<L> source,
                                                        FSAStateInterface<L> target)
Creates a new FSATransitionInterface in the given FSA with the same ID as the specified transition. The source state of the new transition is the state in the specified FSA with the same ID as the source state of the specified transition. Likewise, the target state of the new transition is the state in the specified FSA with the same ID as the target state of the specified transition. If the specified transition is a FSALabelTransitionInterface, the new transition will also be a FSALabelTransitionInterface with an equal label. Likewise, if the specified transition is a FSALabelPatternTransitionInterface, the new transition will also be a FSALabelPatternTransitionInterface with an equal LabelPattern. The annotations on the specified transition are also copied to the new transition.

Preconditions: fsa, transition are not null, transition is not already a transition in fsa.

Parameters:
fsa - The fsa into which the transition is being copied.
transition - The transition to copy.
id - The id.
source - The new source state.
target - The new target state.
Returns:
The FSATransitionInterface.
Throws:
InconsistentObjectError - when the source or target state with the correct ID can not be retrieved from fsa, or when the type of transition can not be determined.
See Also:
Annotatable#copyAnnotations(Annotatable), MutableFSAInterface.copyTransition(laser.regularlanguage.fsa.FSATransitionInterface, laser.regularlanguage.fsa.FSAStateInterface, laser.regularlanguage.fsa.FSAStateInterface)

createMutableFSAInterface

public MutableFSAInterface<L> createMutableFSAInterface(AlphabetInterface<L> alphabet,
                                                        java.lang.Object... args)
Creates a mutable FSA from the specified arguments.

PRECONDITIONS:

Specified by:
createMutableFSAInterface in interface FSAFactoryInterface<L extends LabelInterface>
Parameters:
alphabet - The alphabet for the new FSA.
args - The arguments (optional).
Returns:
The mutable FSA.
Throws:
java.lang.IllegalArgumentException - A mutable FSA can not be created from the specified arguments.

getAlphabetFactory

public AlphabetFactoryInterface<L> getAlphabetFactory()
Gets the alphabet factory to be used to create new alphabets.

Specified by:
getAlphabetFactory in interface FSAFactoryInterface<L extends LabelInterface>
Returns:
The AlphabetFactoryInterface to be used to create new alphabets

getCreateArgs

public java.lang.Object[] getCreateArgs(FSAInterface<L> oldFSA)
Gets any required arguments for the FSA factory method from the given FSA.

PRECONDITION: The fsa must be non-null.

Specified by:
getCreateArgs in interface FSAFactoryInterface<L extends LabelInterface>
Parameters:
oldFSA - The FSA to use as a prototype
Returns:
Any required arguments for the FSA factory method
See Also:
createMutableFSAInterface(AlphabetInterface, Object[]), MutableFSAInterface.copy(FSAInterface, boolean, boolean, boolean)

getCreateArgs

public java.lang.Object[] getCreateArgs(FSAInterface<L> newFSA,
                                        FSAStateInterface<L> oldState)
Gets any required arguments for the state factory method from the given state.

PRECONDITION:

Specified by:
getCreateArgs in interface FSAFactoryInterface<L extends LabelInterface>
Parameters:
newFSA - The FSA that will contain the new state
oldState - The FSA state to use as a prototype
Returns:
Any required arguments for the state factory method
See Also:
MutableFSAInterface.addState(Object[]), MutableFSAInterface.copyState(FSAStateInterface, boolean, boolean)

getCreateArgs

public java.lang.Object[] getCreateArgs(FSAInterface<L> newFSA,
                                        FSATransitionInterface<L> oldTransition)
Gets any required arguments for the transition factory method from the given transition.

PRECONDITION:

Specified by:
getCreateArgs in interface FSAFactoryInterface<L extends LabelInterface>
Parameters:
newFSA - The FSA that will contain the new transition
oldTransition - The FSA transition to use as a prototype
Returns:
Any required arguments for the transition factory method
See Also:
MutableFSAInterface.addEpsilonTransition(FSAStateInterface, FSAStateInterface, Object[]), MutableFSAInterface.addTransition(FSAStateInterface, LabelInterface, FSAStateInterface, Object[]), MutableFSAInterface.addTransition(FSAStateInterface, LabelPatternInterface, FSAStateInterface, Object[]), MutableFSAInterface.copyTransition(FSATransitionInterface, FSAStateInterface, FSAStateInterface)