com.hazelcast.util
Class StateMachine<T extends Enum<T>>

java.lang.Object
  extended by com.hazelcast.util.StateMachine<T>
Type Parameters:
T -

public class StateMachine<T extends Enum<T>>
extends Object

Simple state machine using an Enum as possible states.


Constructor Summary
StateMachine(T initialState)
           
 
Method Summary
 boolean is(T state, T... otherStates)
          Check if current state is one of given states
 StateMachine<T> next(T nextState)
          Transition to next state
 void nextOrStay(T nextState)
          Transition to next state if not already there
static
<T extends Enum<T>>
StateMachine<T>
of(T initialState)
           
 String toString()
           
 StateMachine<T> withTransition(T from, T to, T... moreTo)
          Add a valid transition from one state to one or more states
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StateMachine

public StateMachine(T initialState)
Method Detail

of

public static <T extends Enum<T>> StateMachine<T> of(T initialState)

withTransition

public StateMachine<T> withTransition(T from,
                                      T to,
                                      T... moreTo)
Add a valid transition from one state to one or more states


next

public StateMachine<T> next(T nextState)
                                     throws IllegalStateException
Transition to next state

Throws:
IllegalStateException - if transition is not allowed

nextOrStay

public void nextOrStay(T nextState)
Transition to next state if not already there


is

public boolean is(T state,
                  T... otherStates)
Check if current state is one of given states


toString

public String toString()
Overrides:
toString in class Object


Copyright © 2015 Hazelcast, Inc.. All Rights Reserved.