Class StateMachine<T extends java.lang.Enum<T>>
- java.lang.Object
-
- com.couchbase.lite.internal.utils.StateMachine<T>
-
- Type Parameters:
T- states.
public final class StateMachine<T extends java.lang.Enum<T>> extends java.lang.ObjectA simple state machine.This class is not thread safe!
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classStateMachine.Builder<S extends java.lang.Enum<S>>
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanassertState(T... expected)Verify expected state.booleansetState(T nextState)Set the new state.java.lang.StringtoString()
-
-
-
Method Detail
-
toString
@NonNull public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
assertState
@SafeVarargs public final boolean assertState(@NonNull T... expected)Verify expected state.- Parameters:
expected- expected states.- Returns:
- true if the current state at the time of the call, is one of the expected states.
-
setState
public boolean setState(@NonNull T nextState)Set the new state. If it is legal to transition to the new state, from the current state, do so, returning the now-previous state. If the transition is illegal do nothing and return null.- Parameters:
nextState- the requested new state- Returns:
- the previous state, if the transition succeeds; null otherwise.
-
-