/** * Convenience method for checking whether the current state is one of the * specified states. * @param states The states to be checked. * @return <code>true</code> when the current state is one of the specified * states, <code>false</code> otherwise. */ @SafeVarargs public final boolean stateIsOneOf(State<T, C>... states) { for (final State<T, C> s : states) { if (stateIs(s)) { return true; } } return false; }
/** * Convenience method for checking whether the current state is one of the * specified states. * @param states The states to be checked. * @return <code>true</code> when the current state is one of the specified * states, <code>false</code> otherwise. */ @SafeVarargs public final boolean stateIsOneOf(State<T, C>... states) { for (final State<T, C> s : states) { if (stateIs(s)) { return true; } } return false; }
@Override public void stop() { LOGGER.trace("stop"); checkState(stateMachine.isSupported(Trigger.STOP), "Can not stop time in current state: %s", stateMachine.getCurrentState().name()); final boolean rt = stateMachine.stateIs(realtimeState); stateMachine.handle(Trigger.STOP, this); if (!rt) { shutdownExecutor(); } }
@Override protected void preTick(TimeLapse time) { boolean updated = false; if (stateMachine.stateIs(waitState)) { if (changed) { updateAssignmentAndRoutePlanner(); } else if (getRoute().isEmpty() && routePlanner.current().isPresent()) { updated = true; updateRoute(); } } else if (changed && isDiversionAllowed() && !stateMachine.stateIs(serviceState)) { updateAssignmentAndRoutePlanner(); } if (!updated) { checkRoutePlanner(); } }
/** * Tests correct behavior for events which are not equal. */ @SuppressWarnings("static-method") @Test public void eventNotEqualBehavior() { final TestState state1 = new TestState("state1"); state1.name(); final TestState state2 = new TestState("state2"); final Object event1 = "event1"; final Object event2 = new Object(); final StateMachine<Object, Object> sm = StateMachine.create(state1)/* */ .addTransition(state1, event1, state2)/* */ .addTransition(state2, event2, state1)/* */ .build(); assertTrue(sm.isSupported(event1)); assertTrue(sm.isSupported("event1")); assertTrue(sm.isSupported(new StringBuilder("event").append(1) .toString())); assertFalse(sm.isSupported(event2)); sm.handle("event1", CONTEXT); assertTrue(sm.stateIs(state2)); assertTrue(sm.isSupported(event2)); assertFalse(sm.isSupported(new Object())); }