public class State
extends java.lang.Object
StateMachine. Normally you wouldn't create
instances of this class directly but rather use the
State annotation to define
your states and then let StateMachineFactory create a
StateMachine for you.
States inherits Transitions from
their parent. A State can override any of the parents
Transitions. When an Event is processed the Transitions
of the current State will be searched for a Transition which
can handle the event. If none is found the State's parent will be
searched and so on.
| Modifier and Type | Class and Description |
|---|---|
private static class |
State.TransitionHolder |
| Modifier and Type | Field and Description |
|---|---|
private java.lang.String |
id |
private java.util.List<SelfTransition> |
onEntries |
private java.util.List<SelfTransition> |
onExits |
private State |
parent |
private java.util.List<State.TransitionHolder> |
transitionHolders |
private java.util.List<Transition> |
transitions |
| Constructor and Description |
|---|
State(java.lang.String id)
Creates a new
State with the specified id. |
State(java.lang.String id,
State parent)
Creates a new
State with the specified id and parent. |
| Modifier and Type | Method and Description |
|---|---|
(package private) State |
addOnEntrySelfTransaction(SelfTransition onEntrySelfTransaction)
Adds an entry
SelfTransition to this State |
(package private) State |
addOnExitSelfTransaction(SelfTransition onExitSelfTransaction)
Adds an exit
SelfTransition to this State |
State |
addTransition(Transition transition)
Adds an outgoing
Transition to this State with weight 0. |
State |
addTransition(Transition transition,
int weight)
Adds an outgoing
Transition to this State with the
specified weight. |
boolean |
equals(java.lang.Object o) |
java.lang.String |
getId()
Returns the id of this
State. |
java.util.List<SelfTransition> |
getOnEntrySelfTransitions()
Returns an unmodifiable
List of entry SelfTransitions |
java.util.List<SelfTransition> |
getOnExitSelfTransitions()
Returns an unmodifiable
List of exit SelfTransitions |
State |
getParent()
Returns the parent
State. |
java.util.List<Transition> |
getTransitions()
|
int |
hashCode() |
java.lang.String |
toString() |
private void |
updateTransitions() |
private final java.lang.String id
private final State parent
private java.util.List<State.TransitionHolder> transitionHolders
private java.util.List<Transition> transitions
private java.util.List<SelfTransition> onEntries
private java.util.List<SelfTransition> onExits
public State(java.lang.String id)
State with the specified id.id - the unique id of this State.public java.lang.String getId()
State.public State getParent()
State.null if this State has no
parent.public java.util.List<Transition> getTransitions()
Transitions.public java.util.List<SelfTransition> getOnEntrySelfTransitions()
List of entry SelfTransitionsSelfTransitions.public java.util.List<SelfTransition> getOnExitSelfTransitions()
List of exit SelfTransitionsSelfTransitions.State addOnEntrySelfTransaction(SelfTransition onEntrySelfTransaction)
SelfTransition to this StateselfTransition - the SelfTransition to add.State.State addOnExitSelfTransaction(SelfTransition onExitSelfTransaction)
SelfTransition to this StateselfTransition - the SelfTransition to add.State.private void updateTransitions()
public State addTransition(Transition transition)
Transition to this State with weight 0.transition - the Transition to add.State.addTransition(Transition, int)public State addTransition(Transition transition, int weight)
Transition to this State with the
specified weight. The higher the weight the less important a
Transition is. If two Transitions match the same
Event the Transition with the lower weight will
be executed.transition - the Transition to add.State.public boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Object