Class CommandHandlerBuilderByState<Command,Event,S extends State,State>
-
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds and returns a handler from the appended states.static <Command,Event, S extends State, State>
CommandHandlerBuilderByState<Command,Event, S, State> static <Command,Event, State>
CommandHandlerBuilderByState<Command,Event, State, State> onAnyCommand(BiFunction<? super S, ? super Command, ? extends Effect<Event, State>> handler) Matches any command.Matches any command.onAnyCommand(Supplier<? extends Effect<Event, State>> handler) Matches any command.onCommand(Class<C> commandClass, BiFunction<? super S, ? super C, ? extends Effect<Event, State>> handler) Matches commands that are of the givencommandClassor subclass thereofMatches commands that are of the givencommandClassor subclass thereof.Matches commands that are of the givencommandClassor subclass thereof.onCommand(Predicate<? super Command> predicate, BiFunction<? super S, ? super Command, ? extends Effect<Event, State>> handler) Matches any command which the givenpredicatereturns true for.onCommand(Predicate<? super Command> predicate, Function<? super Command, ? extends Effect<Event, State>> handler) Matches any command which the givenpredicatereturns true for.<S2 extends State>
CommandHandlerBuilderByState<Command,Event, S2, State> orElse(CommandHandlerBuilderByState<Command, Event, S2, State> other) Compose this builder with another builder.
-
Method Details
-
builder
public static <Command,Event, CommandHandlerBuilderByState<Command,S extends State, State> Event, builderS, State> (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, CommandHandlerBuilderByState
-
builder
public static <Command,Event, CommandHandlerBuilderByState<Command,State> Event, builderState, State> (Predicate<? super 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, CommandHandlerBuilderByState
-
onCommand
public CommandHandlerBuilderByState<Command,Event, onCommandS, State> (Predicate<? super Command> predicate, BiFunction<? super S, ? super Command, ? extends Effect<Event, State>> handler) Matches any command which the givenpredicatereturns true for.Note: command handlers are selected in the order they are added. Once a matching is found, it's selected for handling the command 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 command handlers.
-
onCommand
public CommandHandlerBuilderByState<Command,Event, onCommandS, State> (Predicate<? super Command> predicate, Function<? super Command, ? extends Effect<Event, State>> handler) Matches any command which the givenpredicatereturns true for.Use this when the
Stateis not needed in thehandler, otherwise there is an overloaded method that pass the state in aBiFunction.Note: command handlers are selected in the order they are added. Once a matching is found, it's selected for handling the command 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 command handlers.
-
onCommand
public <C extends Command> CommandHandlerBuilderByState<Command,Event, onCommandS, State> (Class<C> commandClass, BiFunction<? super S, ? super C, ? extends Effect<Event, State>> handler) Matches commands that are of the givencommandClassor subclass thereofNote: command handlers are selected in the order they are added. Once a matching is found, it's selected for handling the command 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 command handlers.
-
onCommand
public <C extends Command> CommandHandlerBuilderByState<Command,Event, onCommandS, State> (Class<C> commandClass, Function<? super C, ? extends Effect<Event, State>> handler) Matches commands that are of the givencommandClassor subclass thereof.Use this when the
Stateis not needed in thehandler, otherwise there is an overloaded method that pass the state in aBiFunction.Note: command handlers are selected in the order they are added. Once a matching is found, it's selected for handling the command 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 command handlers.
-
onCommand
public <C extends Command> CommandHandlerBuilderByState<Command,Event, onCommandS, State> (Class<C> commandClass, Supplier<? extends Effect<Event, State>> handler) Matches commands that are of the givencommandClassor subclass thereof.Use this when you just need to initialize the
Statewithout using any data from the command.Note: command handlers are selected in the order they are added. Once a matching is found, it's selected for handling the command 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 command handlers.
-
onAnyCommand
public CommandHandler<Command,Event, onAnyCommandState> (BiFunction<? super S, ? super Command, ? extends Effect<Event, State>> handler) Matches any command.Use this to declare a command handler that will match any command. This is particular useful when encoding a finite state machine in which the final state is not supposed to handle any new command.
Note: command handlers are selected in the order they are added. Once a matching is found, it's selected for handling the command 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 command handlers.
Extra care should be taken when using
onAnyCommandas it will match any command. This method builds and returns the command handler since this will not let through any states to subsequent match statements.- Returns:
- A CommandHandler from the appended states.
-
onAnyCommand
public CommandHandler<Command,Event, onAnyCommandState> (Function<? super Command, ? extends Effect<Event, State>> handler) Matches any command.Use this to declare a command handler that will match any command. This is particular useful when encoding a finite state machine in which the final state is not supposed to handle any new command.
Use this when you just need to return an
Effectwithout using any data from the state.Note: command handlers are selected in the order they are added. Once a matching is found, it's selected for handling the command 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 command handlers.
Extra care should be taken when using
onAnyCommandas it will match any command. This method builds and returns the command handler since this will not let through any states to subsequent match statements.- Returns:
- A CommandHandler from the appended states.
-
onAnyCommand
public CommandHandler<Command,Event, onAnyCommandState> (Supplier<? extends Effect<Event, State>> handler) Matches any command.Use this to declare a command handler that will match any command. This is particular useful when encoding a finite state machine in which the final state is not supposed to handle any new command.
Use this when you just need to return an
Effectwithout using any data from the command or from the state.Note: command handlers are selected in the order they are added. Once a matching is found, it's selected for handling the command 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 command handlers.
Extra care should be taken when using
onAnyCommandas it will match any command. This method builds and returns the command handler since this will not let through any states to subsequent match statements.- Returns:
- A CommandHandler from the appended states.
-
orElse
public <S2 extends State> CommandHandlerBuilderByState<Command,Event, orElseS2, State> (CommandHandlerBuilderByState<Command, Event, S2, State> 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 returnedCommandHandlerwill throw aMatchErrorif applied to a command that has no defined case.
-