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

java.lang.Object
  extended by laser.regularlanguage.fsa.AbstractFSA<L>
      extended by laser.regularlanguage.fsa.AbstractMutableFSA<L>
Type Parameters:
L - The type of Label associated with this FSA.
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, ArtifactInterface, FSAInterface<L>, MutableFSAInterface<L>, Annotatable, Persistent, Visualizable
Direct Known Subclasses:
MutableFSA

public abstract class AbstractMutableFSA<L extends LabelInterface>
extends AbstractFSA<L>
implements MutableFSAInterface<L>

An abstract class representing FSAs that are mutable.

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:
MutableFSAInterface, Serialized Form

Field Summary
 
Fields inherited from class laser.regularlanguage.fsa.AbstractFSA
_alphabet, _factory, _nextStateID, _nextTransitionID, _startState, _states, _transitionIndex, _transitions
 
Fields inherited from interface laser.util.Persistent
PER_EXTENSION, READ_PERSISTENT_METHOD_NAME
 
Constructor Summary
protected AbstractMutableFSA(AbstractFSA<L> fsa)
          Creates a new MutableFSA with the same states, transitions, and Alphabet as the specified FSA.
protected AbstractMutableFSA(AlphabetInterface<L> alphabet, AbstractFSAFactory<L> factory)
          Returns a new MutableFSA with the specified Alphabet and FSA factory.
 
Method Summary
protected  void _checkLabelPattern(LabelPatternInterface<L> labelPattern)
          Checks the specified LabelPattern.
 boolean addLabel(L label)
          Adds a copy of the specified Label to the Alphabet of this FSA if it was not already present and returns true, otherwise the alphabet remains unchanged and false is returned.
 boolean addLabels(java.util.Set<? extends L> labels)
          Adds a copy of any of the Labels in the specified Set to the Alphabet of this FSA if they were not already present and returns true, otherwise the alphabet remains unchanged and false is returned.
 FSAStateInterface<L> addState(java.lang.Object... args)
          Creates a new state and adds it to this FSA, returning a reference to the new state.
 java.util.SortedSet<FSALabelTransitionInterface<L>> addTransitions(FSAStateInterface<L> source, java.util.Set<? extends L> labels, FSAStateInterface<L> target, java.lang.Object... args)
          Adds transitions to this FSA from the specified source state to the specified target state on each of the given Labels and returns a Set containing references to the newly created transitions.
abstract  MutableFSAInterface<L> clone()
          Returns a copy of this mutable FSA.
 java.util.Map<FSAStateInterface<L>,FSAStateInterface<L>> copy(FSAInterface<L> fsa, boolean setAttributes, boolean setStart, boolean setAccept)
          Copies the given FSA into this FSA.
 void copyFSAAttributes(FSAInterface<L> fsa)
          Copies the attributes of the given FSA into this FSA excluding the alphabet, states, and transitions.
 FSAStateInterface<L> copyState(FSAStateInterface<L> state, boolean setStart, boolean setAccept)
          Copies the given FSA state into this FSA.
 FSATransitionInterface<L> copyTransition(FSATransitionInterface<L> transition, FSAStateInterface<L> sourceState, FSAStateInterface<L> targetState)
          Copies the given FSA transition into this FSA.
 boolean deleteDeadStates()
          Removes any state except the start state from this FSA that is not accepting and can not reach an accepting state by any sequence of transitions, returning true is any states were so removed.
 boolean deleteUnreachableStates()
          Removes any state from this FSA that is not the start state and is not reachable from the start state by any sequence of transitions, returning true if any states were so removed, false otherwise.
protected  java.lang.Object[] getCreateArgsForLabelTransition(FSALabelPatternTransitionInterface<L> oldTransition)
          Gets any required arguments for the label transition from the given label pattern transition.
protected  java.lang.Object[] getCreateArgsForTrapState()
          Gets any required arguments for the trap state.
protected  java.lang.Object[] getCreateArgsForTrapTransition()
          Gets any required arguments for a trap transition.
 java.util.Set<LabelPatternInterface<L>> getLabelPatterns()
          Returns a view of the set P, the LabelPatterns on transitions in this FSA (optional operation).
abstract  RunnableFSAInterface<L> getRunnableFSA()
          Returns the runnable FSA corresponding to this mutable FSA.
 FSAStateInterface<L> getStartState()
          Returns the start state, q0, of the FSA.
 FSALabelPatternTransitionInterface<L> getTransition(FSAStateInterface<L> source, LabelPatternInterface<L> labelPattern, FSAStateInterface<L> target)
          Returns the transition from the specified source state to the specified target state on a LabelPattern equal to the given LabelPattern if one exists in the FSA, otherwise null is returned (optional operation).
 boolean hasTransitionsOnLabelPatterns()
          Returns true if this FSA has any transitions on LabelPatterns, false otherwise (optional operation).
 FSAStateInterface<L> makeTotal()
          Makes this FSA total if it is not already.
 boolean removeLabel(L label)
          Removes the Label equal to the specified Label from the Alphabet of this FSA.
 boolean removeLabels(java.util.Set<? extends L> labels)
          Removes from the Alphabet of this FSA all of its Labels equal to the Labels that are contained in the specified Set.
 void removeState(FSAStateInterface<L> state)
          Removes the specified state from this FSA.
 void removeTransition(FSATransitionInterface<L> transition)
          Removes the specified transition from the FSA.
 void removeTransitions(java.util.Set<? extends FSATransitionInterface<L>> transitions)
          Removes the specified transitions from the FSA.
 boolean replaceLabelPatternTransitionsWithLabelTransitions()
          Replaces each transition on a LabelPattern in this FSA with the corresponding set of transitions on Labels in this FSA (optional operation).
 void setAlphabet(AlphabetInterface<? extends L> alphabet)
          Sets the Alphabet of this FSA to a copy of the specified Alphabet.
 void setStartState(FSAStateInterface<L> state)
          Sets the start state, q0 of this FSA to the specified state.
 boolean supportsLabelPatterns()
          Returns true if this FSA supports label patterns and false otherwise.
 
Methods inherited from class laser.regularlanguage.fsa.AbstractFSA
_checkLabel, _checkState, _checkTransition, _internalAddTransition, _internalCopyFSAAttributes, _internalRemoveState, _internalRemoveTransition, addAnnotation, addAnnotations, checkWellFormed, copyAnnotations, getAcceptStates, getAlphabet, getAnnotationClasses, getAnnotationClasses, getAnnotationFilters, getAnnotations, getAnnotations, getDescription, getDotWriter, getEpsilonTransition, getFactory, getName, getNonAcceptStates, getStates, getStateWithID, getTransition, getTransitions, getTransitions, getTransitionWithID, getVisExtension, hasTransitionsOnEpsilon, isDeterministic, isTotal, readPersistent, readPersistent, removeAnnotation, removeAnnotations, removeAnnotations, removeAnnotations, setAnnotationFilters, setDescription, setName, toDot, toDot, visualize, visualize, writePersistent, writePersistent
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface laser.regularlanguage.fsa.MutableFSAInterface
addEpsilonTransition, addTransition, addTransition
 
Methods inherited from interface laser.regularlanguage.fsa.FSAInterface
checkWellFormed, getAcceptStates, getAlphabet, getDescription, getEpsilonTransition, getFactory, getName, getNonAcceptStates, getStates, getStateWithID, getTransition, getTransitions, getTransitions, getTransitionWithID, hasTransitionsOnEpsilon, isDeterministic, isTotal, setDescription, setName, supportsEpsilonTransitions, supportsNondeterminism
 
Methods inherited from interface laser.util.Annotatable
addAnnotation, addAnnotations, copyAnnotations, getAnnotationClasses, getAnnotationClasses, getAnnotationFilters, getAnnotations, getAnnotations, removeAnnotation, removeAnnotations, removeAnnotations, removeAnnotations, setAnnotationFilters
 
Methods inherited from interface laser.util.Persistent
writePersistent, writePersistent
 
Methods inherited from interface laser.util.Visualizable
getVisExtension, visualize, visualize
 

Constructor Detail

AbstractMutableFSA

protected AbstractMutableFSA(AlphabetInterface<L> alphabet,
                             AbstractFSAFactory<L> factory)
Returns a new MutableFSA with the specified Alphabet and FSA factory. The factory is used to create states and transitions and to get the runnable FSA corresponding to this mutable FSA.

Precondition: alphabet and factory are not null.

Note this constructor should only be called by the AbstractFSAFactory._internalCreateMutableFSAInterface(laser.alphabet.AlphabetInterface, laser.regularlanguage.fsa.AbstractFSAFactory) method and by constructors of subclasses of this class.

Parameters:
alphabet - The Alphabet.
factory - The factory
See Also:
AbstractFSAFactory._internalCreateMutableFSAInterface(laser.alphabet.AlphabetInterface, laser.regularlanguage.fsa.AbstractFSAFactory)

AbstractMutableFSA

protected AbstractMutableFSA(AbstractFSA<L> fsa)
Creates a new MutableFSA with the same states, transitions, and Alphabet as the specified FSA. The annotations on the FSA, its states and transitions are also copied.

Precondition: fsa is not null.

Parameters:
fsa - The FSA.
Method Detail

_checkLabelPattern

protected void _checkLabelPattern(LabelPatternInterface<L> labelPattern)
Checks the specified LabelPattern.

Parameters:
labelPattern - The LabelPattern to check.
Throws:
java.lang.IllegalArgumentException - if labelPattern is null

clone

public abstract MutableFSAInterface<L> clone()
Returns a copy of this mutable FSA.

Specified by:
clone in interface FSAInterface<L extends LabelInterface>
Specified by:
clone in class AbstractFSA<L extends LabelInterface>
Returns:
A copy of this mutable FSA.

addLabel

public boolean addLabel(L label)
Adds a copy of the specified Label to the Alphabet of this FSA if it was not already present and returns true, otherwise the alphabet remains unchanged and false is returned.

NOTE: No references are maintained between the specified Label and the Label in the Alphabet, thus changing the specified Label has no effect on the Label in the Alphabet and vice versa.

PRECONDITION: The label must be non-null.

Specified by:
addLabel in interface MutableFSAInterface<L extends LabelInterface>
Parameters:
label - Label to be added to the Alphabet of this FSA.
Returns:
true if the Alphabet did not already contain the specified Label, false otherwise.
Throws:
java.lang.IllegalArgumentException - the specified Label is null.
See Also:
Set.add(E)

addLabels

public boolean addLabels(java.util.Set<? extends L> labels)
Adds a copy of any of the Labels in the specified Set to the Alphabet of this FSA if they were not already present and returns true, otherwise the alphabet remains unchanged and false is returned.

NOTE: No references are maintained between the specified Labels and the Labels in the Alphabet, thus changing any of the specified Labels has no effect on the Labels in the Alphabet and vice versa.

PRECONDITIONS:

Specified by:
addLabels in interface MutableFSAInterface<L extends LabelInterface>
Parameters:
labels - Set containing Labels to be added
Returns:
true if any Labels were actually added to the Alphabet, false otherwise.
Throws:
java.lang.IllegalArgumentException - if labels is null or any of its elements is null
See Also:
Set.addAll(java.util.Collection)

addState

public FSAStateInterface<L> addState(java.lang.Object... args)
Creates a new state and adds it to this FSA, returning a reference to the new state.

PRECONDITION: The args must be valid.

Specified by:
addState in interface MutableFSAInterface<L extends LabelInterface>
Parameters:
args - Implementation specific arguments used to create the state (optional).
Returns:
A reference to the newly created state.
Throws:
java.lang.IllegalArgumentException - invalid arguments are specified by args.
See Also:
AbstractFSAFactory._createFSAStateInterface(laser.regularlanguage.fsa.FSAInterface, int, boolean, java.lang.Object...)

addTransitions

public java.util.SortedSet<FSALabelTransitionInterface<L>> addTransitions(FSAStateInterface<L> source,
                                                                          java.util.Set<? extends L> labels,
                                                                          FSAStateInterface<L> target,
                                                                          java.lang.Object... args)
Adds transitions to this FSA from the specified source state to the specified target state on each of the given Labels and returns a Set containing references to the newly created transitions. More formally, for each l in labels adds a transition t to T such that source(t) = sourcetarget(t) = targetlabel(t) = l. The behavior of this method differs depending on whether the FSA supports nondeterminism or not.

If the FSA does not support nondeterminism, there can only be exactly one transition with a certain source state and Label. In this case, attempting to add a transition with the same source state and Label but different target state as an existing transition will result in an FSAInterfaceException being thrown. This condition is formally specified as (∃ t'T : source(t') = sourcetarget(t') ≠ targetlabel(t') = l. Instead, the existing transition should first be removed using the removeTransition(laser.regularlanguage.fsa.FSATransitionInterface) method.

By contrast, if the FSA supports nondeterminism, there can be multiple transitions with the same source state and Label but differing target states. In this case, adding such a transition with a different target state is allowed, and the existing transition(s) remain unchanged.

NOTES:

A copy of each Label is used, thus no references are maintained between the specified Labels and the Labels on the transitions, thus modifying any of the specified Labels has no effect on the Labels on the transition and vice versa.

If the same source state, Label, and target state are specified as a transition that already exists in the FSA, a reference to that transition is returned and no new transition on that Label is added.

PRECONDITIONS:

Specified by:
addTransitions in interface MutableFSAInterface<L extends LabelInterface>
Parameters:
source - The source state of the transitions to be added.
labels - The Labels on the transitions to be added.
target - The target state of the transitions to be added.
args - Implementation specific arguments used to create the transition (optional).
Returns:
A Set containing references to the newly created transitions.
Throws:
java.lang.IllegalArgumentException - if source/target is null or is not a state in this FSA, if labels is null or any element is null or is not contained in the alphabet of this FSA, or if invalid arguments are specified by args
java.lang.UnsupportedOperationException - if adding the transitions would violate the label function of this FSA.
See Also:
MutableFSAInterface.addTransition(FSAStateInterface, LabelInterface, FSAStateInterface, Object[]), removeTransition(laser.regularlanguage.fsa.FSATransitionInterface)

copyFSAAttributes

public void copyFSAAttributes(FSAInterface<L> fsa)
Copies the attributes of the given FSA into this FSA excluding the alphabet, states, and transitions.

PRECONDITION: The given FSA must be non-null.

Specified by:
copyFSAAttributes in interface MutableFSAInterface<L extends LabelInterface>
Parameters:
fsa - The given FSA to be copied from
Throws:
java.lang.IllegalArgumentException - if the given FSA is null

copyState

public FSAStateInterface<L> copyState(FSAStateInterface<L> state,
                                      boolean setStart,
                                      boolean setAccept)
Copies the given FSA state into this FSA.

PRECONDITION: The given state must be non-null.

Specified by:
copyState in interface MutableFSAInterface<L extends LabelInterface>
Parameters:
state - The given FSA state to be copied
setStart - If true and the state is the start state of the given FSA then the corresponding state is the start state of this FSA
setAccept - If true and the state is an accept state of the given FSA then the corresponding state is an accept state of this FSA
Returns:
The corresponding FSA state in this FSA
Throws:
java.lang.IllegalArgumentException - if the given state is null

copyTransition

public FSATransitionInterface<L> copyTransition(FSATransitionInterface<L> transition,
                                                FSAStateInterface<L> sourceState,
                                                FSAStateInterface<L> targetState)
Copies the given FSA transition into this FSA.

PRECONDITIONS:

Specified by:
copyTransition in interface MutableFSAInterface<L extends LabelInterface>
Parameters:
transition - The given FSA transition to be copied from
sourceState - The state in this FSA that will be the source
targetState - the state in this FSA that will be the target
Returns:
The corresponding transition in this FSA
Throws:
java.lang.IllegalArgumentException - if the given transition is null or if the source/target state is null or is not in this FSA
java.lang.UnsupportedOperationException - if the given transition type is not supported in this FSA or if copying the given transition would violate the label function of this FSA

copy

public java.util.Map<FSAStateInterface<L>,FSAStateInterface<L>> copy(FSAInterface<L> fsa,
                                                                     boolean setAttributes,
                                                                     boolean setStart,
                                                                     boolean setAccept)
Copies the given FSA into this FSA.

PRECONDITION:

Specified by:
copy in interface MutableFSAInterface<L extends LabelInterface>
Parameters:
fsa - The given FSA to be copied from
setAttributes - If the attributes of the given FSA should be copied
setStart - If the given FSA has a start state, then it will become the this FSA's start state
setAccept - If there are any accept states in the given FSA, then they will become accept states in this FSA
Returns:
A Map from each state in the given FSA to its corresponding state in this FSA
Throws:
java.lang.IllegalArgumentException - if the given FSA is null or it not well-formed
java.lang.UnsupportedOperationException - if copying the given FSA requires features that this FSA does not support

deleteDeadStates

public boolean deleteDeadStates()
Removes any state except the start state from this FSA that is not accepting and can not reach an accepting state by any sequence of transitions, returning true is any states were so removed.

More formally, removes all states qQ such that q ∉ ({q0} ∪ A) ∧ (∄ t1, t2, …, tn : (∀ 1 ≤ in : tiTsource(t1) = qtarget(tn) ∈ A ∧ (∀ 1 ≤ j < n : target(tj) = source(tj + 1)))). This takes into account any transitions in T specified by transitions on LabelPatterns.

NOTE: This does not change the set of input strings that is accepted by this FSA.

Specified by:
deleteDeadStates in interface MutableFSAInterface<L extends LabelInterface>
Returns:
true if any states were removed by this method, false otherwise.

deleteUnreachableStates

public boolean deleteUnreachableStates()
                                throws FSAInterfaceException
Removes any state from this FSA that is not the start state and is not reachable from the start state by any sequence of transitions, returning true if any states were so removed, false otherwise. This does not change the set of input strings that is accepted by this FSA.

More formally, removes all states qQ such that qq0 ∧ (∄ t1, t2, …, tn : (∀ 1 ≤ in : tiTsource(t1) = q0target(tn) = q ∧ (∀ 1 ≤ j < n : target(tj) = source(tj + 1)))). This takes into account any transitions in T specified by transitions on LabelPatterns.

NOTE: This does not change the set of input strings that is accepted by this FSA.

PRECONDITION: This FSA must have a start state.

Specified by:
deleteUnreachableStates in interface MutableFSAInterface<L extends LabelInterface>
Returns:
true if any states were removed by this method, false otherwise.
Throws:
FSAInterfaceException - if this FSA does not have a start state

getLabelPatterns

public java.util.Set<LabelPatternInterface<L>> getLabelPatterns()
Returns a view of the set P, the LabelPatterns on transitions in this FSA (optional operation).

NOTES:

The returned set can not be modified and any attempt to do so will result in a UnsupportedOperationException being thrown. If this FSA does not support transitions on LabelPatterns, calling this method may cause an UnsupportedOperationException to be thrown, depending on the implementation.

Specified by:
getLabelPatterns in interface MutableFSAInterface<L extends LabelInterface>
Returns:
An unmodifiable view of the set P, the LabelPatterns on transitions in this FSA.
Throws:
java.lang.UnsupportedOperationException - this FSA does not support transitions on LabelPatterns.

getRunnableFSA

public abstract RunnableFSAInterface<L> getRunnableFSA()
                                                                       throws FSAInterfaceException
Returns the runnable FSA corresponding to this mutable FSA. This FSA must be well-formed. Any transitions on LabelPatterns are replaced with the corresponding transitions on Labels in the runnable FSA since a runnable FSA can not have transitions on LabelPatterns, but the mutable FSA remains unchanged. The states and transitions in the runnable FSA are reindexed, therefore the ID of a state or transition in the mutable FSA might not equal the ID of its corresponding state or transition in the runnable FSA.

NOTE: No references are maintained between the FSAs, thus modifying the mutable FSA has no effect on the runnable FSA.

Specified by:
getRunnableFSA in interface MutableFSAInterface<L extends LabelInterface>
Returns:
The runnable FSA corresponding to this mutable FSA.
Throws:
FSAInterfaceException - if this FSA is not well-formed.
See Also:
RunnableFSAInterface, FSAInterface.checkWellFormed(), replaceLabelPatternTransitionsWithLabelTransitions()

getStartState

public FSAStateInterface<L> getStartState()
Returns the start state, q0, of the FSA. If there is no start state null is returned.

Specified by:
getStartState in interface FSAInterface<L extends LabelInterface>
Overrides:
getStartState in class AbstractFSA<L extends LabelInterface>
Returns:
The start state of this FSA or null if there isn't one.

getTransition

public FSALabelPatternTransitionInterface<L> getTransition(FSAStateInterface<L> source,
                                                           LabelPatternInterface<L> labelPattern,
                                                           FSAStateInterface<L> target)
Returns the transition from the specified source state to the specified target state on a LabelPattern equal to the given LabelPattern if one exists in the FSA, otherwise null is returned (optional operation).

If this FSA does not support transitions on LabelPatterns, calling this method may cause an UnsupportedOperationException to be thrown, depending on the implementation.

PRECONDITIONS:

Specified by:
getTransition in interface MutableFSAInterface<L extends LabelInterface>
Parameters:
source - The source state.
labelPattern - The LabelPattern of the transition.
target - The target state.
Returns:
The transition if it exists, null otherwise.
Throws:
java.lang.IllegalArgumentException - if source/target is null or is not a part of this FSA, if labelPattern is null or is not valid
java.lang.UnsupportedOperationException - this FSA does not support transitions on LabelPatterns.

hasTransitionsOnLabelPatterns

public boolean hasTransitionsOnLabelPatterns()
Returns true if this FSA has any transitions on LabelPatterns, false otherwise (optional operation). More formally, returns true iff (∃ t ∈ T : label(t) ∈ P).

Specified by:
hasTransitionsOnLabelPatterns in interface MutableFSAInterface<L extends LabelInterface>
Returns:
true if this FSA has any transitions on LabelPatterns, false otherwise.

getCreateArgsForTrapState

protected java.lang.Object[] getCreateArgsForTrapState()
Gets any required arguments for the trap state.

Returns:
Any required arguments for the trap state

getCreateArgsForTrapTransition

protected java.lang.Object[] getCreateArgsForTrapTransition()
Gets any required arguments for a trap transition.

Returns:
Any required arguments for a trap transition

makeTotal

public FSAStateInterface<L> makeTotal()
Makes this FSA total if it is not already. Making an FSA total does not change the set of input strings that it accepts.

A non-accepting state is added to the FSA and a reference to it is returned. Transitions on Labels are added as necessary from every state in the FSA to target this new state to make the FSA total. Call the added state qtrap. (∀ l ∈ Σ, qQ : (∄ tT : source(t) = qlabel(t) = l) → add a transition t' to T such that source(t') = qlabel(t') = ltarget(t') = qtrap). This takes into account any transitions in T specified by transitions on LabelPatterns.

If this FSA was already total, no state is added, and instead null is returned.

Specified by:
makeTotal in interface MutableFSAInterface<L extends LabelInterface>
Returns:
A reference to the non-accepting state that was added, or null if no state was added.
See Also:
FSAInterface.isTotal()

removeLabel

public boolean removeLabel(L label)
Removes the Label equal to the specified Label from the Alphabet of this FSA. If the Label was present, it is removed and true is returned. If it was not present, the Alphabet remains unchanged and false is returned.

When a Label is removed from the Alphabet of the FSA with this method, all transitions on that Label are likewise removed.

PRECONDITION: The label must be non-null.

Specified by:
removeLabel in interface MutableFSAInterface<L extends LabelInterface>
Parameters:
label - Label to be removed from the Alphabet of this FSA.
Returns:
true if the Alphabet contained the specified label, false otherwise.
Throws:
java.lang.IllegalArgumentException - the specified label is null.
See Also:
Set.remove(java.lang.Object), removeTransition(laser.regularlanguage.fsa.FSATransitionInterface)

removeLabels

public boolean removeLabels(java.util.Set<? extends L> labels)
Removes from the Alphabet of this FSA all of its Labels equal to the Labels that are contained in the specified Set. If any Labels are so removed, true is returned, otherwise false is returned and the Alphabet remains unchanged.

When a Label is removed from the Alphabet of the FSA with this method, all transitions on that Label are likewise removed.

PRECONDITIONS:

Specified by:
removeLabels in interface MutableFSAInterface<L extends LabelInterface>
Parameters:
labels - Set containing Labels to be removed from the Alphabet of this FSA.
Returns:
true if Labels were actually removed from the Alphabet of this FSA, false otherwise.
Throws:
java.lang.IllegalArgumentException - if labels or any of its elements is null.
See Also:
Set.removeAll(java.util.Collection), removeTransition(laser.regularlanguage.fsa.FSATransitionInterface)

removeState

public void removeState(FSAStateInterface<L> state)
Removes the specified state from this FSA. The specified state must be a part of this FSA. If the specified state is the start state, the FSA will not be well formed until another start state has been set. When a state is removed, all transitions whose source or target is that state are also removed.

PRECONDITION: The state must be non-null and a part of this FSA.

Specified by:
removeState in interface MutableFSAInterface<L extends LabelInterface>
Parameters:
state - The state to be removed from this FSA.
Throws:
java.lang.IllegalArgumentException - if state is null or is not part of this FSA.
See Also:
setStartState(laser.regularlanguage.fsa.FSAStateInterface), removeTransition(laser.regularlanguage.fsa.FSATransitionInterface)

removeTransition

public void removeTransition(FSATransitionInterface<L> transition)
Removes the specified transition from the FSA.

PRECONDITION: The transition must be non-null and a part of this FSA.

Specified by:
removeTransition in interface MutableFSAInterface<L extends LabelInterface>
Parameters:
transition - The transition to be removed.
Throws:
java.lang.IllegalArgumentException - if transition is null or is not part of this FSA.

removeTransitions

public void removeTransitions(java.util.Set<? extends FSATransitionInterface<L>> transitions)
Removes the specified transitions from the FSA.

PRECONDITIONS:

Specified by:
removeTransitions in interface MutableFSAInterface<L extends LabelInterface>
Parameters:
transitions - The transitions to be removed.
Throws:
java.lang.IllegalArgumentException - if transitions or any of its elements is null or if any of its elements in not a part of this FSA.
See Also:
removeTransition(laser.regularlanguage.fsa.FSATransitionInterface)

getCreateArgsForLabelTransition

protected java.lang.Object[] getCreateArgsForLabelTransition(FSALabelPatternTransitionInterface<L> oldTransition)
Gets any required arguments for the label transition from the given label pattern transition.

Parameters:
oldTransition - The old label pattern transition
Returns:
Any required arguments for the new label transition

replaceLabelPatternTransitionsWithLabelTransitions

public boolean replaceLabelPatternTransitionsWithLabelTransitions()
Replaces each transition on a LabelPattern in this FSA with the corresponding set of transitions on Labels in this FSA (optional operation). If any such transitions were so replaced true is returned, otherwise false is returned.

More formally, call the set of all transitions on LabelPatterns in this FSA TP then:

TP' = { t' | ∃ tpTP : (source(t') = source(tp) ∧ target(t') = target(tp) ∧ label(t') ∈ t.getLabelPattern().getMatchingLabels(Σ)) }

Then after this method is called, the set of transitions in this FSA T' will be (T \ TP) ∪ TP'.

Specified by:
replaceLabelPatternTransitionsWithLabelTransitions in interface MutableFSAInterface<L extends LabelInterface>
Returns:
true if any transitions were replaced, false otherwise.
See Also:
FSALabelPatternTransitionInterface, removeTransition(laser.regularlanguage.fsa.FSATransitionInterface), addTransitions(FSAStateInterface, Set, FSAStateInterface, Object[])

setAlphabet

public void setAlphabet(AlphabetInterface<? extends L> alphabet)
Sets the Alphabet of this FSA to a copy of the specified Alphabet.

NOTES:

No references are maintained between the new Alphabet of the FSA and the specified Alphabet, thus modifying the specified Alphabet does not affect the FSA's Alphabet and vice versa.

If there are any Labels in the current Alphabet that are not equal to Labels contained in the specified Alphabet, all transitions on Labels equal to those labels are removed.

Any transitions on Labels equal to Labels contained in both the current and specified alphabets remain unchanged.

PRECONDITIONS:

Specified by:
setAlphabet in interface MutableFSAInterface<L extends LabelInterface>
Parameters:
alphabet - The specified Alphabet, a copy of which will become the new Alphabet of this FSA.
Throws:
java.lang.IllegalArgumentException - if alphabet or any of its elements is null.

setStartState

public void setStartState(FSAStateInterface<L> state)
Sets the start state, q0 of this FSA to the specified state.

NOTE: Since an FSA has exactly one start state, if another state was previously the start state, it is no longer the start state.

PRECONDITION: The state is null or else it is non-null and a part of this FSA.

Specified by:
setStartState in interface MutableFSAInterface<L extends LabelInterface>
Parameters:
state - The state that is to be the new start state.
Throws:
java.lang.IllegalArgumentException - if state is non-null and is not part of this FSA.

supportsLabelPatterns

public boolean supportsLabelPatterns()
Returns true if this FSA supports label patterns and false otherwise.

More formally, returns label is defined to include P.

Specified by:
supportsLabelPatterns in interface MutableFSAInterface<L extends LabelInterface>
Returns:
True if label patterns are supported and false otherwise