jAER project on SourceForge

net.sf.jaer.util
Class StateMachineStates

java.lang.Object
  extended by net.sf.jaer.util.StateMachineStates
Direct Known Subclasses:
Goalie.GoalieState

public abstract class StateMachineStates
extends java.lang.Object

Class that keeps track of state of state machine, allowing access to previous state, time since state changed, defining an initial state. Use it like this:

     enum StateMachineStates{INITIAL, MIDDLE, FINAL} // define states
    class S extends StateMachineStates{ // extends StateMachineStates and implement the getInitial method
        StateMachineStates state=StateMachineStates.INITIAL;
        public Enum getInitial(){
            return StateMachineStates.INITIAL;
        }
    }
 
Use the enum to define the states and then the set and get methods to set and get the state.
    S s=new S();
    s.set(StateMachineStates.MIDDLE);
    s.getPrevious();
    s.timeSinceChanged();

Author:
tobi

Constructor Summary
StateMachineStates()
          Create a new state machine.
StateMachineStates(java.lang.Enum initialState)
          Create a new state machine with defined initial state.
 
Method Summary
 boolean equals(StateMachineStates other)
           
 java.lang.Enum get()
          Return present state
abstract  java.lang.Enum getInitial()
          Defines the default initial state
 java.lang.Enum getPrevious()
          return previous state, before it was changed.
 boolean isChanged()
          was the currentState changed the last time it was set(java.lang.Enum)?
 boolean isInitialized()
          has state been initialized or set away from it's Integer.MIN_VALUE initial state?
 void set(java.lang.Enum newState)
          set a possibly new currentState.
 long timeSinceChanged()
          return time in ms since state last changed
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StateMachineStates

public StateMachineStates(java.lang.Enum initialState)
Create a new state machine with defined initial state.

Parameters:
initialState - a new initial state

StateMachineStates

public StateMachineStates()
Create a new state machine.

Method Detail

getInitial

public abstract java.lang.Enum getInitial()
Defines the default initial state

Returns:
the initial state

set

public void set(java.lang.Enum newState)
set a possibly new currentState. If state didn't change, don't do anything except arrange that next time isChanged() is called, it returns false.

Parameters:
newState - the new state to be in

isChanged

public boolean isChanged()
was the currentState changed the last time it was set(java.lang.Enum)?


timeSinceChanged

public long timeSinceChanged()
return time in ms since state last changed


get

public java.lang.Enum get()
Return present state


getPrevious

public java.lang.Enum getPrevious()
return previous state, before it was changed.


isInitialized

public boolean isInitialized()
has state been initialized or set away from it's Integer.MIN_VALUE initial state?


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
name of state (enum itself, unless overridden)

equals

public boolean equals(StateMachineStates other)

jAER project on SourceForge