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

java.lang.Object
  extended by laser.regularlanguage.fsa.FSAState<L>
Type Parameters:
L - The type of Label associated with the FSA that contains this state.
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<FSAStateInterface<L>>, FSAStateInterface<L>, Annotatable

public class FSAState<L extends LabelInterface>
extends java.lang.Object
implements FSAStateInterface<L>

An FSAState represents a state in an FSA of type FSAInterface.

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

Constructor Summary
protected FSAState(FSAInterface<L> fsa, int id, boolean accept)
          Creates an FSAState in the specified FSA with the given ID.
 
Method Summary
 boolean addAnnotation(Annotation annotation)
          Associates the given Annotation with this Object.
 boolean addAnnotations(java.util.Collection<? extends Annotation> annotations)
          Associates all of the Annotations in the given Collection with this Object.
protected  void checkLabel(L label)
          Checks the specified Label, making sure it is not null and is contained in the Alphabet of this FSA.
protected  void checkLabelPattern(LabelPatternInterface<L> labelPattern)
          Checks the specified LabelPattern.
 int compareTo(FSAStateInterface<L> state)
          Compares this state with the specified state for order.
 boolean copyAnnotations(Annotatable container)
          Copies all of the Annotations associated with this Object that pass the filters and associates them with the specified Object.
 java.util.Set<java.lang.Class<? extends Annotation>> getAnnotationClasses()
          Gets all of the Annotation Classes associated with this Object.
 java.util.Set<java.lang.Class<? extends Annotation>> getAnnotationClasses(java.lang.Class<? extends Annotation> query)
          Gets all of the Annotation Classes associated with this Object of the specified Annotation Class.
 java.util.Set<java.lang.Class<? extends Annotation>> getAnnotationFilters()
          Gets the filters to use when copying the Annotations.
 java.util.Collection<Annotation> getAnnotations()
          Gets all of the Annotations associated with this Object.
 java.util.Collection<Annotation> getAnnotations(java.lang.Class<? extends Annotation> query)
          Gets all of the Annotations associated with this Object that have an equal Class to or are a Subclass of the Class of the specified Annotation.
 FSAInterface<L> getFSA()
          Returns the FSA that contains this state.
 int getID()
          Returns the ID of this state.
 java.util.Set<? extends FSAEpsilonTransitionInterface<L>> getIncomingEpsilonTransitions()
          Returns a Set containing the transitions on epsilon of the FSA of which this state is a part that have this state as their target (optional operation).
 java.util.Set<? extends FSATransitionInterface<L>> getIncomingTransitions()
          Returns a Set containing the transitions of the FSA of which this state is a part that target this state.
 java.util.Set<? extends FSALabelTransitionInterface<L>> getIncomingTransitions(L label)
          Returns a Set containing the transitions on the specified Label of the FSA of which this state is a part that target this state.
 java.util.Set<? extends FSALabelPatternTransitionInterface<L>> getIncomingTransitions(LabelPatternInterface<L> labelPattern)
          Returns a Set containing the transitions on the specified LabelPattern of the FSA of which this state is a part that target this state (optional operation).
protected  java.util.Set<L> getLabels(FSATransitionInterface<L> transition)
          Gets the Set of labels that cause the given transition to be taken.
 java.lang.String getName()
          Returns the name of this state, or null if one has not been specified.
 java.util.Set<? extends FSAEpsilonTransitionInterface<L>> getOutgoingEpsilonTransitions()
          Returns a Set containing the transitions on epsilon of the FSA of which this state is a part that have this state as their source (optional operation).
 java.util.Set<? extends FSATransitionInterface<L>> getOutgoingTransitions()
          Returns a Set containing the transitions of the FSA of which this state is a part that have this state as their source.
 java.util.Set<? extends FSALabelTransitionInterface<L>> getOutgoingTransitions(L label)
          Returns a Set containing the transitions on the specified Label of the FSA of which this state is a part that have this state as their source.
 java.util.Set<? extends FSALabelPatternTransitionInterface<L>> getOutgoingTransitions(LabelPatternInterface<L> labelPattern)
          Returns a Set containing the transitions on the specified LabelPattern of the FSA of which this state is a part that have this state as their source (optional operation).
protected  void internalSetAccept(boolean accept)
          Sets whether or not this state is an accept state.
 boolean isAccept()
          Returns true if this state is an accept state (i.e. this state ∈ A), false otherwise.
 boolean isDeterministic()
          Returns true if this state is deterministic and false otherwise.
 boolean isSink()
          Returns true if this state is a sink state, false otherwise.
 boolean isStart()
          Returns true if this state is the start state, q0, false otherwise.
 boolean removeAnnotation(Annotation annotation)
          Removes the association of the given Annotation with this Object.
 void removeAnnotations()
          Removes all of the Annotations associated with this Object.
 boolean removeAnnotations(java.lang.Class<? extends Annotation> query)
          Removes the association of all of the Annotations of the specified Class or Subclasses of the specified Class with this Object, returning true if any Annotations were so associated, false otherwise.
 boolean removeAnnotations(java.util.Collection<? extends Annotation> annotations)
          Removes the association of all the Annotations in the given Collection with this Object.
 void setAccept(boolean accept)
          Sets whether or not this state is an accept state.
 void setAnnotationFilters(java.util.Set<java.lang.Class<? extends Annotation>> filters)
          Sets the filters to use when copying the Annotations.
 void setName(java.lang.String name)
          Sets the name of this state to the specified String.
 java.lang.String toString()
          Gets a string representation of this state
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FSAState

protected FSAState(FSAInterface<L> fsa,
                   int id,
                   boolean accept)
Creates an FSAState in the specified FSA with the given ID. The accept parameter specifies whether or not this state is to be an accept state.

By default, the name of the state is set to the String "q" with the ID appended to it. (i.e. if the ID is 0, for example, the name of the state will be "q0").

This constructor should only be called by an appropriate factory method of an AbstractFSAFactory.

Precondition: fsa is not null.

Parameters:
fsa - The FSA that is to contain the state.
id - The ID of the state.
accept - true if this state is to be an accept state, false otherwise.
Method Detail

checkLabel

protected void checkLabel(L label)
Checks the specified Label, making sure it is not null and is contained in the Alphabet of this FSA.

Parameters:
label - The Label to check.
Throws:
java.lang.IllegalArgumentException - if label is null or is not contained in the alphabet of this FSA.

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

internalSetAccept

protected void internalSetAccept(boolean accept)
Sets whether or not this state is an accept state. If true is given as the parameter, this state is an accept state (i.e. this state ∈ A). If false is given as the parameter, this state is a non-accept state (i.e. this state ∉ A).

Parameters:
accept - The parameter determining whether or not this state will be an accept state.

compareTo

public int compareTo(FSAStateInterface<L> state)
Compares this state with the specified state for order.

The order is determined by comparing the IDs of the states.

If this state preceeds the specified state in order, a negative integer is returned. If this state is equal to the specified state in order, zero is returned. If this state follows the specified state in order, a positive integer is returned.

Specified by:
compareTo in interface java.lang.Comparable<FSAStateInterface<L extends LabelInterface>>
Parameters:
state - the state to compare with this one for order.
Returns:
a negative integer when this state preceeds the specified state in order, zero when this state is equal to the specified state in order, and a positive integer when this state follows the specified state in order.
Throws:
java.lang.NullPointerException - if the specified state is null.

getFSA

public FSAInterface<L> getFSA()
Returns the FSA that contains this state.

Specified by:
getFSA in interface FSAStateInterface<L extends LabelInterface>
Returns:
Returns the FSA that contains this state.

getID

public int getID()
Returns the ID of this state.

Specified by:
getID in interface FSAStateInterface<L extends LabelInterface>
Returns:
the ID of this state.

getIncomingTransitions

public java.util.Set<? extends FSATransitionInterface<L>> getIncomingTransitions()
Returns a Set containing the transitions of the FSA of which this state is a part that target this state.

More formally, call the returned set S and call this state q.
(∀ tT : tStarget(t) = q)

Specified by:
getIncomingTransitions in interface FSAStateInterface<L extends LabelInterface>
Returns:
A Set containing the transitions of the FSA of which this state is a part that target this state.

getIncomingEpsilonTransitions

public java.util.Set<? extends FSAEpsilonTransitionInterface<L>> getIncomingEpsilonTransitions()
Returns a Set containing the transitions on epsilon of the FSA of which this state is a part that have this state as their target (optional operation).

More formally, call the returned set S and call this state q.
(∀ tT : tStarget(t) = qlabel(t) = epsilon (ε))

Specified by:
getIncomingEpsilonTransitions in interface FSAStateInterface<L extends LabelInterface>
Returns:
A Set containing the transitions on epsilon of the FSA of which this state is a part that have this state as their target.
Throws:
java.lang.UnsupportedOperationException - if this FSA does not support epsilon (ε) transitions

getIncomingTransitions

public java.util.Set<? extends FSALabelTransitionInterface<L>> getIncomingTransitions(L label)
Returns a Set containing the transitions on the specified Label of the FSA of which this state is a part that target this state.

More formally, call the returned set S and call this state q.
(∀ tT : tStarget(t) = qlabel(t) = label)

Note this method is ignorant of LabelPatterns, and as such will not return a transition on a LabelPattern even if the FSA has transition targeting this state on a LabelPattern that matches the specified Label.

PRECONDITION: The label must be non-null and contained in the alphabet of this FSA.

Specified by:
getIncomingTransitions in interface FSAStateInterface<L extends LabelInterface>
Parameters:
label - The Label.
Returns:
A Set containing the transitions on the specified Label of the FSA of which this state is a part that target this state.
Throws:
java.lang.IllegalArgumentException - the specified Label is null or is not contained in the alphabet of this FSA.

getIncomingTransitions

public java.util.Set<? extends FSALabelPatternTransitionInterface<L>> getIncomingTransitions(LabelPatternInterface<L> labelPattern)
Returns a Set containing the transitions on the specified LabelPattern of the FSA of which this state is a part that target this state (optional operation).

More formally, call the returned set S and call this state q.
(∀ tT : tStarget(t) = qlabel(t) = labelPattern)

PRECONDITION: The labelPattern must be non-null.

Specified by:
getIncomingTransitions in interface FSAStateInterface<L extends LabelInterface>
Parameters:
labelPattern - The LabelPattern.
Returns:
A Set containing the transitions on the specified LabelPattern of the FSA of which this state is a part that target this state.
Throws:
java.lang.IllegalArgumentException - the specified LabelPattern is null.
java.lang.UnsupportedOperationException - if this FSA does not support label pattern transitions

getName

public java.lang.String getName()
Returns the name of this state, or null if one has not been specified.

Specified by:
getName in interface FSAStateInterface<L extends LabelInterface>
Returns:
The name of this state, or null if one has not been specified.

getOutgoingTransitions

public java.util.Set<? extends FSATransitionInterface<L>> getOutgoingTransitions()
Returns a Set containing the transitions of the FSA of which this state is a part that have this state as their source.

More formally, call the returned set S and call this state q.
(∀ tT : tSsource(t) = q)

Specified by:
getOutgoingTransitions in interface FSAStateInterface<L extends LabelInterface>
Returns:
A Set containing the transitions of the FSA of which this state is a part that have this state as their source.

getOutgoingEpsilonTransitions

public java.util.Set<? extends FSAEpsilonTransitionInterface<L>> getOutgoingEpsilonTransitions()
Returns a Set containing the transitions on epsilon of the FSA of which this state is a part that have this state as their source (optional operation).

More formally, call the returned set S and call this state q.
(∀ tT : tSsource(t) = qlabel(t) = epsilon (ε))

Specified by:
getOutgoingEpsilonTransitions in interface FSAStateInterface<L extends LabelInterface>
Returns:
A Set containing the transitions on epsilon of the FSA of which this state is a part that have this state as their source.
Throws:
java.lang.UnsupportedOperationException - if this FSA does not support epsilon (ε) transitions

getOutgoingTransitions

public java.util.Set<? extends FSALabelTransitionInterface<L>> getOutgoingTransitions(L label)
Returns a Set containing the transitions on the specified Label of the FSA of which this state is a part that have this state as their source.

More formally, call the returned set S and call this state q.
(∀ tT : tSsource(t) = qlabel(t) = label)

Note this method is ignorant of LabelPatterns, and as such will not return a transition on a LabelPattern even if the FSA has a transition with this state as its source on a LabelPattern that matches the specified Label.

PRECONDITION: The label must be non-null and contained in the alphabet of this FSA.

Specified by:
getOutgoingTransitions in interface FSAStateInterface<L extends LabelInterface>
Parameters:
label - The Label.
Returns:
A Set containing the transitions on the specified Label of the FSA of which this state is a part that have this state as their source.
Throws:
java.lang.IllegalArgumentException - the specified Label is null or is not contained in the alphabet of this FSA.

getOutgoingTransitions

public java.util.Set<? extends FSALabelPatternTransitionInterface<L>> getOutgoingTransitions(LabelPatternInterface<L> labelPattern)
Returns a Set containing the transitions on the specified LabelPattern of the FSA of which this state is a part that have this state as their source (optional operation).

More formally, call the returned set S and call this state q.
(∀ tT : tSsource(t) = qlabel(t) = labelPattern)

PRECONDITION: The labelPattern must be non-null.

Specified by:
getOutgoingTransitions in interface FSAStateInterface<L extends LabelInterface>
Parameters:
labelPattern - The LabelPattern.
Returns:
A Set containing the transitions on the specified Label of the FSA of which this state is a part that have this state as their source.
Throws:
java.lang.IllegalArgumentException - the specified LabelPattern is null.
java.lang.UnsupportedOperationException - if this FSA does not support label pattern transitions

isAccept

public boolean isAccept()
Returns true if this state is an accept state (i.e. this state ∈ A), false otherwise.

Specified by:
isAccept in interface FSAStateInterface<L extends LabelInterface>
Returns:
true if this state is an accept state, false otherwise.

getLabels

protected java.util.Set<L> getLabels(FSATransitionInterface<L> transition)
Gets the Set of labels that cause the given transition to be taken.

Parameters:
transition - The transition of interest
Returns:
The Set of labels that cause it to be taken

isDeterministic

public boolean isDeterministic()
Returns true if this state is deterministic and false otherwise. If the FSA that contains this state does not support nondeterminism, true will always be returned.

If the FSA that contains this state supports nondeterminism, true is returned iff this state has no outgoing epsilon (ε) transitions and no two outgoing transitions have the same Label. More formally, call this state q. true is returned iff
(∄ tT : source(t) = qlabel(t) = ε) ∧ (∄ x,yT : xysource(x) = qsource(y) = qlabel(x) = label(y)))

Specified by:
isDeterministic in interface FSAStateInterface<L extends LabelInterface>
Returns:
true if this state is deterministic and false otherwise.

isSink

public boolean isSink()
Returns true if this state is a sink state, false otherwise. A state is a sink state if it has no outgoing transitions targeting other states. More formally, call this state q. true is returned iff
(∀ tT : source(t) = q target(t) = q)

Specified by:
isSink in interface FSAStateInterface<L extends LabelInterface>
Returns:
true if this state is a sink state, false otherwise.

isStart

public boolean isStart()
Returns true if this state is the start state, q0, false otherwise.

Specified by:
isStart in interface FSAStateInterface<L extends LabelInterface>
Returns:
true if this state is the start state, false otherwise.

setAccept

public void setAccept(boolean accept)
Sets whether or not this state is an accept state. If true is given as the parameter, this state is an accept state (i.e. this state ∈ A). If false is given as the parameter, this state is a non-accept state (i.e. this state ∉ A).

Specified by:
setAccept in interface FSAStateInterface<L extends LabelInterface>
Parameters:
accept - The parameter determining whether or not this state will be an accept state.
Throws:
java.lang.UnsupportedOperationException - if the FSA that contains this state is not mutable.

setName

public void setName(java.lang.String name)
Sets the name of this state to the specified String.

Specified by:
setName in interface FSAStateInterface<L extends LabelInterface>
Parameters:
name - The name.

toString

public java.lang.String toString()
Gets a string representation of this state

Overrides:
toString in class java.lang.Object
Returns:
a string representation of this state

addAnnotation

public boolean addAnnotation(Annotation annotation)
Associates the given Annotation with this Object. If an equal Annotation was already so associated, false is returned, otherwise true is returned.

Specified by:
addAnnotation in interface Annotatable
Parameters:
annotation - The Annotation to associate with this Object.
Returns:
false if an equal Annotation was already associated with this Object and true otherwise.
Throws:
java.lang.IllegalArgumentException - if annotation is null.

addAnnotations

public boolean addAnnotations(java.util.Collection<? extends Annotation> annotations)
Associates all of the Annotations in the given Collection with this Object. If an equal Annotation to every Annotation in the Collection was already so associated, false is returned, otherwise true is returned.

Specified by:
addAnnotations in interface Annotatable
Parameters:
annotations - The Collection of Annotations to associate with this Object.
Returns:
false if an equal Annotation to every Annotation in the specified Collection was already associated with this Object and true otherwise.
Throws:
java.lang.IllegalArgumentException - if annotations or any annotation is null.

copyAnnotations

public boolean copyAnnotations(Annotatable container)
Copies all of the Annotations associated with this Object that pass the filters and associates them with the specified Object. If equal Annotations to every Annotation that was copied from this Object were already associated with the specified Object, false is returned, otherwise true is returned.

Specified by:
copyAnnotations in interface Annotatable
Parameters:
container - The Object to associate the copied Annotations with.
Returns:
false if the specified Object was already associated with equal Annotations to every Annotation that was copied from this Object, true otherwise.
Throws:
java.lang.IllegalArgumentException - if container is null.
See Also:
getAnnotationFilters()

getAnnotationClasses

public java.util.Set<java.lang.Class<? extends Annotation>> getAnnotationClasses(java.lang.Class<? extends Annotation> query)
Gets all of the Annotation Classes associated with this Object of the specified Annotation Class.

Specified by:
getAnnotationClasses in interface Annotatable
Parameters:
query - The Annotation Class of interest
Returns:
A Set of all of the Annotation Classes of the specified Annotation Class
Throws:
java.lang.IllegalArgumentException - if query is null.

getAnnotationClasses

public java.util.Set<java.lang.Class<? extends Annotation>> getAnnotationClasses()
Gets all of the Annotation Classes associated with this Object.

Specified by:
getAnnotationClasses in interface Annotatable
Returns:
A Set of all of the Annotation Classes

getAnnotations

public java.util.Collection<Annotation> getAnnotations(java.lang.Class<? extends Annotation> query)
Gets all of the Annotations associated with this Object that have an equal Class to or are a Subclass of the Class of the specified Annotation.

Specified by:
getAnnotations in interface Annotatable
Parameters:
query - The Class of which Annotations of equal Class or Subclasses of the Class are to be returned.
Returns:
A Collection containing all of the Annotations associated with this Object that have an equal Class or are Subclasses of the specified Class.
Throws:
java.lang.IllegalArgumentException - if query is null.

getAnnotations

public java.util.Collection<Annotation> getAnnotations()
Gets all of the Annotations associated with this Object.

Specified by:
getAnnotations in interface Annotatable
Returns:
A Collection containing the Annotations associated with this Object.

getAnnotationFilters

public java.util.Set<java.lang.Class<? extends Annotation>> getAnnotationFilters()
Gets the filters to use when copying the Annotations. The returned Set contains the Classes of Annotations that are not to be copied by the copyAnnotations(laser.util.Annotatable) method.

Specified by:
getAnnotationFilters in interface Annotatable
Returns:
The filters for the Annotations.
See Also:
copyAnnotations(laser.util.Annotatable)

setAnnotationFilters

public void setAnnotationFilters(java.util.Set<java.lang.Class<? extends Annotation>> filters)
Sets the filters to use when copying the Annotations. The Set contains the Classes of Annotations that are not to be copied by the copyAnnotations(laser.util.Annotatable) method.

Specified by:
setAnnotationFilters in interface Annotatable
Parameters:
filters - The filters for the Annotations
Throws:
java.lang.IllegalArgumentException - if the filters are null
See Also:
copyAnnotations(laser.util.Annotatable)

removeAnnotation

public boolean removeAnnotation(Annotation annotation)
Removes the association of the given Annotation with this Object. If an equal Annotation was so associated, true is returned, otherwise false is returned.

Specified by:
removeAnnotation in interface Annotatable
Parameters:
annotation - The Annotation of which the association with this Object is to be removed.
Returns:
true if an equal Annotation was associated with this Object and false otherwise.
Throws:
java.lang.IllegalArgumentException - if annotation is null.

removeAnnotations

public boolean removeAnnotations(java.util.Collection<? extends Annotation> annotations)
Removes the association of all the Annotations in the given Collection with this Object. If an equal Annotation to any Annotation in the Collection was so associated, true is returned, otherwise false is returned.

Specified by:
removeAnnotations in interface Annotatable
Parameters:
annotations - The Collection of Annotations of which the association with this Object is to be removed.
Returns:
true if an equal Annotation to any Annotation in the specified Collection was associated with this Object and false otherwise.
Throws:
java.lang.IllegalArgumentException - if annotations or any annotation is null.

removeAnnotations

public boolean removeAnnotations(java.lang.Class<? extends Annotation> query)
Removes the association of all of the Annotations of the specified Class or Subclasses of the specified Class with this Object, returning true if any Annotations were so associated, false otherwise.

Specified by:
removeAnnotations in interface Annotatable
Parameters:
query - The Class of Annotations that are to be removed.
Returns:
true if any associations with Annotations were removed, false otherwise.
Throws:
java.lang.IllegalArgumentException - if query is null.

removeAnnotations

public void removeAnnotations()
Removes all of the Annotations associated with this Object.

Specified by:
removeAnnotations in interface Annotatable