public synchronized void checkState ( State ... requiredStates ) throws IllegalStateException { for ( State requiredState : requiredStates ) { if ( requiredState . equals ( currentState ) ) { return ; } } throw new IllegalStateException ( String . format ( Locale . US , "Expected states %s, but in state %s" , Lists . newArrayList ( requiredStates ) , currentState ) ) ; }
Checks that the machine is in one of the given states . Throws if it isn t .