コード例 #1
0
 @SuppressWarnings("unchecked")
 @Override
 public <V> StateMachine<T> notify(final V state, final T value) {
   if (strict) {
     Assert.isTrue(states.contains(state), "State " + state + " has not been defined");
   }
   Event<T> ev = Event.wrap(value instanceof Event ? ((Event<T>) value).getData() : value);
   observable.notify(
       state,
       ev,
       new Consumer<Event<T>>() {
         @Override
         public void accept(final Event<T> ev) {
           transition(state, ev.getData());
         }
       });
   return this;
 }
コード例 #2
0
 @Override
 public <V> StateMachine<T> on(final V state, final Function<T, T> fn) {
   if (strict) {
     Assert.isTrue(states.contains(state), "State " + state + " has not been defined");
   }
   observable.on(
       (state instanceof Selector ? (Selector) state : Selectors.object(state)),
       new Consumer<Event<T>>() {
         @SuppressWarnings("unchecked")
         @Override
         public void accept(final Event<T> data) {
           try {
             data.setData(fn.apply(data.getData()));
           } catch (Throwable t) {
             observable.notify(
                 t.getClass(), Event.wrap(new StateException(t, state, data.getData())));
           }
         }
       });
   return this;
 }
コード例 #3
0
 @Override
 public <V> boolean contains(V state) {
   return states.contains(state);
 }