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

java.lang.Object
  extended by laser.regularlanguage.fsa.AbstractFSATransition<L>
Type Parameters:
L - The type of Label associated with the FSA that contains this transition.
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<FSATransitionInterface<L>>, FSATransitionInterface<L>, Annotatable
Direct Known Subclasses:
FSAEpsilonTransition, FSALabelPatternTransition, FSALabelTransition

public abstract class AbstractFSATransition<L extends LabelInterface>
extends java.lang.Object
implements FSATransitionInterface<L>

An abstract class that represents a transition 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:
FSAInterface, FSATransitionInterface, Serialized Form

Constructor Summary
protected AbstractFSATransition(int id, FSAStateInterface<L> source, FSAStateInterface<L> target)
          Creates a new AbstractFSATransition from the specified source state to the specified target state with the specified 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.
 int compareTo(FSATransitionInterface<L> transition)
          Compares this transition with the specified transition 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 transition.
 int getID()
          Returns the ID of this transition.
 FSAStateInterface<L> getSource()
          Returns the state that is the source of this transition (the result of evaluating the source function of the FSA that contains this transition with this transition as input).
 FSAStateInterface<L> getTarget()
          Returns the state that is the target of this transition (the result of evaluating the target function of the FSA that contains this transition with this transition as input).
 boolean isSelfLoop()
          Returns true if this transition is a self-loop and 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 setAnnotationFilters(java.util.Set<java.lang.Class<? extends Annotation>> filters)
          Sets the filters to use when copying the Annotations.
 java.lang.String toString()
          Returns a String representation of this AbstractFSATransition.
protected abstract  java.lang.String toStringLabel()
          Returns a String representation of the label function of this AbstractFSATransition.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractFSATransition

protected AbstractFSATransition(int id,
                                FSAStateInterface<L> source,
                                FSAStateInterface<L> target)
Creates a new AbstractFSATransition from the specified source state to the specified target state with the specified ID.

PRECONDITIONS:

Method Detail

compareTo

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

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

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

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

getFSA

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

Specified by:
getFSA in interface FSATransitionInterface<L extends LabelInterface>
Returns:
The FSA that contains this transition.

getID

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

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

getSource

public FSAStateInterface<L> getSource()
Returns the state that is the source of this transition (the result of evaluating the source function of the FSA that contains this transition with this transition as input).

Specified by:
getSource in interface FSATransitionInterface<L extends LabelInterface>
Returns:
The state that is the source of this transition.

getTarget

public FSAStateInterface<L> getTarget()
Returns the state that is the target of this transition (the result of evaluating the target function of the FSA that contains this transition with this transition as input).

Specified by:
getTarget in interface FSATransitionInterface<L extends LabelInterface>
Returns:
The state that is the target of this transition.

isSelfLoop

public boolean isSelfLoop()
Returns true if this transition is a self-loop and false otherwise. More formally, call this transition t, returns true iff (source(t) = target(t)).

Returns:
True if this transition is a self-loop and false otherwise

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

toStringLabel

protected abstract java.lang.String toStringLabel()
Returns a String representation of the label function of this AbstractFSATransition.

Returns:
A String representation of the label function

toString

public java.lang.String toString()
Returns a String representation of this AbstractFSATransition.

Overrides:
toString in class java.lang.Object
Returns:
A String representation of this Object