Package org.jboss.util.state
Class StateMachine
- java.lang.Object
-
- org.jboss.util.state.StateMachine
-
- All Implemented Interfaces:
java.lang.Cloneable
public class StateMachine extends java.lang.Object implements java.lang.Cloneable
The representation of a finite state machine.- Version:
- $Revision$
-
-
Field Summary
Fields Modifier and Type Field Description private State
currentState
The current state of the state machineprivate java.lang.String
description
A description of the state machineprivate static org.jboss.logging.Logger
log
private State
startState
The starting stateprivate java.util.HashSet
states
The set of states making up the state machine
-
Constructor Summary
Constructors Constructor Description StateMachine(java.util.Set states, State startState)
Create a state machine given its states and start state.StateMachine(java.util.Set states, State startState, java.lang.String description)
Create a state machine given its states and start state.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
clone()
Make a copy of the StateMachine maintaining the current state.State
getCurrentState()
Get the current state of the state machine.java.lang.String
getDescription()
Get the state machine description.State
getStartState()
Get the start state of the state machine.java.util.Set
getStates()
Get the states of the state machine.State
nextState(java.lang.String actionName)
Transition to the next state given the name of a valid transition.State
reset()
Reset the state machine back to the start statejava.lang.String
toString()
-
-
-
Field Detail
-
log
private static org.jboss.logging.Logger log
-
description
private java.lang.String description
A description of the state machine
-
states
private java.util.HashSet states
The set of states making up the state machine
-
startState
private State startState
The starting state
-
currentState
private State currentState
The current state of the state machine
-
-
Constructor Detail
-
StateMachine
public StateMachine(java.util.Set states, State startState)
Create a state machine given its states and start state.- Parameters:
states
- - Setfor the state machine startState
- - the starting state
-
StateMachine
public StateMachine(java.util.Set states, State startState, java.lang.String description)
Create a state machine given its states and start state.- Parameters:
states
- - Setfor the state machine startState
- - the starting statedescription
- - an optional description of the state machine
-
-
Method Detail
-
clone
public java.lang.Object clone()
Make a copy of the StateMachine maintaining the current state.- Overrides:
clone
in classjava.lang.Object
- Returns:
- a copy of the StateMachine.
-
getDescription
public java.lang.String getDescription()
Get the state machine description.- Returns:
- an possibly null description.
-
getCurrentState
public State getCurrentState()
Get the current state of the state machine.- Returns:
- the current state.
-
getStartState
public State getStartState()
Get the start state of the state machine.- Returns:
- the start state.
-
getStates
public java.util.Set getStates()
Get the states of the state machine.- Returns:
- the machine states.
-
nextState
public State nextState(java.lang.String actionName) throws IllegalTransitionException
Transition to the next state given the name of a valid transition.- Parameters:
actionName
- - the name of transition that is valid for the current state.- Returns:
- the next state
- Throws:
IllegalTransitionException
-
reset
public State reset()
Reset the state machine back to the start state- Returns:
- the start state
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-