Class EventHandlerBuilderByState<S extends State,State,Event>
-
Constructor Summary
ConstructorsConstructorDescriptionEventHandlerBuilderByState(Class<S> stateClass, Predicate<S> statePredicate) -
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds and returns a handler from the appended states.static <S extends State,State, Event>
EventHandlerBuilderByState<S,State, Event> static <State,Event>
EventHandlerBuilderByState<State,State, Event> onAnyEvent(BiFunction<State, Event, State> handler) Match any event.onAnyEvent(Function<Event, State> handler) Match any event.<E extends Event>
EventHandlerBuilderByState<S,State, Event> onEvent(Class<E> eventClass, BiFunction<S, E, State> handler) Match any event which is an instance ofEor a subtype ofE.<E extends Event>
EventHandlerBuilderByState<S,State, Event> Match any event which is an instance ofEor a subtype ofE.<E extends Event>
EventHandlerBuilderByState<S,State, Event> Match any event which is an instance ofEor a subtype ofE.<S2 extends State>
EventHandlerBuilderByState<S2,State, Event> orElse(EventHandlerBuilderByState<S2, State, Event> other) Compose this builder with another builder.
-
Constructor Details
-
EventHandlerBuilderByState
-
-
Method Details
-
builder
public static <S extends State,State, EventHandlerBuilderByState<S,Event> State, builderEvent> (Class<S> stateClass) - Parameters:
stateClass- The handlers defined by this builder are used when the state is an instance of thestateClass- Returns:
- A new, mutable, EventHandlerBuilderByState
-
builder
public static <State,Event> EventHandlerBuilderByState<State,State, builderEvent> (Predicate<State> statePredicate) - Parameters:
statePredicate- The handlers defined by this builder are used when thestatePredicateistrue, useful for example when state type is an Optional- Returns:
- A new, mutable, EventHandlerBuilderByState
-
onEvent
public <E extends Event> EventHandlerBuilderByState<S,State, onEventEvent> (Class<E> eventClass, BiFunction<S, E, State> handler) Match any event which is an instance ofEor a subtype ofE.Note: event handlers are selected in the order they are added. Once a matching is found, it's selected for handling the event and no further lookup is done. Therefore you must make sure that their matching conditions don't overlap, otherwise you risk to 'shadow' part of your event handlers.
-
onEvent
public <E extends Event> EventHandlerBuilderByState<S,State, onEventEvent> (Class<E> eventClass, Function<E, State> handler) Match any event which is an instance ofEor a subtype ofE.Use this when then
Stateis not needed in thehandler, otherwise there is an overloaded method that pass the state in aBiFunction.Note: event handlers are selected in the order they are added. Once a matching is found, it's selected for handling the event and no further lookup is done. Therefore you must make sure that their matching conditions don't overlap, otherwise you risk to 'shadow' part of your event handlers.
-
onEvent
public <E extends Event> EventHandlerBuilderByState<S,State, onEventEvent> (Class<E> eventClass, Supplier<State> handler) Match any event which is an instance ofEor a subtype ofE.Use this when then
Stateand theEventare not needed in thehandler.Note: event handlers are selected in the order they are added. Once a matching is found, it's selected for handling the event and no further lookup is done. Therefore you must make sure that their matching conditions don't overlap, otherwise you risk to 'shadow' part of your event handlers.
-
onAnyEvent
Match any event.Note: event handlers are selected in the order they are added. Once a matching is found, it's selected for handling the event and no further lookup is done. Therefore you must make sure that their matching conditions don't overlap, otherwise you risk to 'shadow' part of your event handlers.
Extra care should be taken when using
onAnyEvent(java.util.function.BiFunction<State,Event,State>)as it will match any event. This method builds and returns the event handler since this will not let through any states to subsequent match statements.- Returns:
- An EventHandler from the appended states.
-
onAnyEvent
Match any event.Use this when then
Stateis not needed in thehandler, otherwise there is an overloaded method that pass the state in aBiFunction.Note: event handlers are selected in the order they are added. Once a matching is found, it's selected for handling the event and no further lookup is done. Therefore you must make sure that their matching conditions don't overlap, otherwise you risk to 'shadow' part of your event handlers.
Extra care should be taken when using
onAnyEvent(java.util.function.BiFunction<State,Event,State>)as it will match any event. This method builds and returns the event handler since this will not let through any states to subsequent match statements.- Returns:
- An EventHandler from the appended states.
-
orElse
public <S2 extends State> EventHandlerBuilderByState<S2,State, orElseEvent> (EventHandlerBuilderByState<S2, State, Event> other) Compose this builder with another builder. The handlers in this builder will be tried first followed by the handlers inother. -
build
Builds and returns a handler from the appended states. The returnedEventHandlerwill throw aMatchErrorif applied to an event that has no defined case.
-