State - A Java enumeration.public abstract class TransitionSystem<State extends java.lang.Enum<State>>
extends java.lang.Object
Defines the possible transitions between states. This class provides classical accessibility queries on a state transition systems.
Subclasses must implement the isInitialState(State) and isPossibleTransition(State, State) methods to specify the possible
transitions. The following contract must be obeyed by these two methods:
null state to a state s means that s is an initial state. As a consequence, the
Boolean values of isInitialState(s) and of isPossibleTransition(null, s) must be the same.null state has no meaning. A NullPointerException must be thrown when null is passed to
isInitialState(State) or as the second argument of isPossibleTransition(State, State).| Modifier and Type | Field and Description |
|---|---|
protected java.lang.Class<State> |
stateClass
|
| Modifier | Constructor and Description |
|---|---|
protected |
TransitionSystem(java.lang.Class<State> stateClass)
Constructs a transition system for the states in the
State enumeration passed as a parameter to this class. |
| Modifier and Type | Method and Description |
|---|---|
int |
countNextStates(State s)
Returns the number of successors of the provided state.
|
int |
countPreviousStates(State s)
Returns the number of predecessors of the provided state.
|
java.util.Set<State> |
getAccessibleStates(State s)
Returns the set of all states that can be reached from the provided state with one or more transitions.
|
protected java.util.Set<State> |
getAccessibleStates(State s1,
java.util.EnumSet<State> visited)
Utility method that remembers the states visited, to avoid looping on loops.
|
java.util.Set<State> |
getFinalStates()
Returns the set of final states.
|
java.util.Set<State> |
getInitialStates()
Returns the set of initial states.
|
java.util.Set<State> |
getNextStates(State s)
Returns the set of all states to which a transition from the provided state is possible.
|
java.util.Set<State> |
getPreviousStates(State s)
Returns the set of all states from which a transition to the provided state is possible.
|
java.util.Set<State> |
getSelfAccessibleStates()
Returns the set of states for which a non-empty path to themselves exist.
|
boolean |
isAccessible(State s1,
State s2)
Indicates whether there is a non-empty path between the provided states.
|
protected boolean |
isAccessible(State s1,
State s2,
java.util.EnumSet<State> visited)
Utility method that remembers the states visited, to avoid looping on loops.
|
boolean |
isFinalState(State s)
Indicates whether the provided state is final.
|
abstract boolean |
isInitialState(State s)
Indicates whether the provided state is an initial state.
|
abstract boolean |
isPossibleTransition(State s1,
State s2)
Indicates whether the transition is allowed.
|
protected TransitionSystem(java.lang.Class<State> stateClass)
Constructs a transition system for the states in the State enumeration passed as a parameter to this class. Since type information
is not available at run-time for Java generic classes, the reflective Class object for the state enumeration has to be provided to the
constructor.
stateClass - The reflective object for the state enumeration.public abstract boolean isInitialState(State s)
Indicates whether the provided state is an initial state. States that are not accessible from any other state are initial states; other states
can also be declared as initial by methods such as TableTransitionSystem.addInitialStates(State...).
Note: This method must return true iff isPossibleTransition(null, s) returns true.
java.lang.NullPointerException - if s is null.s - The state to test. Cannot be null.true if the provided state is an initial state.public abstract boolean isPossibleTransition(State s1, State s2)
Indicates whether the transition is allowed. By extension, a possible transition from a null state means that the end state of the
transition is an initial state.
Note: If s1 is null, then this method must return true iff isInitialState(s2) returns
true.
java.lang.NullPointerException - if s2 is null.s1 - The start state of the transition, or null to check whether s2 is an initial state.s2 - Then end state of the transition. Cannot be null.true if the transition is allowed.getNextStates(State)public java.util.Set<State> getNextStates(State s)
Returns the set of all states to which a transition from the provided state is possible. If no transition is possible, an empty set is returned. Do not modify the returned set; make a copy of it if needed.
s - The state whose successors are queried. If null, the initial states are returned.s is possible. The initial states if s is null.countNextStates(State),
isAccessible(State, State)public int countNextStates(State s)
Returns the number of successors of the provided state.
s - The state whose successors are queried. If null, the number of initial states is returned.s.getNextStates(State)public java.util.Set<State> getPreviousStates(State s)
Returns the set of all states from which a transition to the provided state is possible. If no transition is possible, an empty set is returned. Do not modify the returned set; make a copy of it if needed.
java.lang.NullPointerException - if s is null.s - The state whose predecessors are queried. Cannot be null.s.public int countPreviousStates(State s)
Returns the number of predecessors of the provided state.
java.lang.NullPointerException - if s is null.s - The state whose predecessors are queried. Cannot be null.s.getPreviousStates(State)public boolean isAccessible(State s1, State s2)
Indicates whether there is a non-empty path between the provided states.
java.lang.NullPointerException - if s2 is null.s1 - The start state of the path.s2 - Then end state of the path. Cannot be null.true if s2 can be reached from s1 in one or more transitions.getAccessibleStates(State)protected boolean isAccessible(State s1, State s2, java.util.EnumSet<State> visited)
public java.util.Set<State> getSelfAccessibleStates()
Returns the set of states for which a non-empty path to themselves exist.
getAccessibleStates(State)public java.util.Set<State> getInitialStates()
Returns the set of initial states. States that are not accessible from any other state are initial states; other states
can also be declared as initial by methods such as TableTransitionSystem.addInitialStates(State...).
isInitialState(State)public boolean isFinalState(State s)
Indicates whether the provided state is final. A state is final if there exists no possible transition from this state to another.
java.lang.NullPointerException - if s is null.s - The state to check. Cannot be null.true if no transition from s is possible.public java.util.Set<State> getFinalStates()
Returns the set of final states. A state is final if there exists no possible transition from this state to another.
public java.util.Set<State> getAccessibleStates(State s)
Returns the set of all states that can be reached from the provided state with one or more transitions. Empty paths are not counted, meaning that the provided state is included in the returned set only if there is a proper loop in the transition system.
s - The start state of the path.s with one or more transitions.© Copyright IBM Corp. 1987, 2017