Package discord4j.common.store.api
Class ActionMapper
- java.lang.Object
-
- discord4j.common.store.api.ActionMapper
-
public class ActionMapper extends Object
Holds mappings between concreteStoreActiontypes and the code to execute when they are invoked.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classActionMapper.Builder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ActionMapperaggregate(ActionMapper... mappers)Aggregates the mappings contained in the givenmappersinto a singleActionMapperinstance.static ActionMapper.Builderbuilder()Initializes a new builder for anActionMapper.static ActionMapperempty()Returns anActionMappercontaining no mappings.<R> Optional<Function<StoreAction<R>,? extends Publisher<R>>>findHandlerForAction(StoreAction<R> action)Retrieves the handler associated to the given action based on its concrete type.
-
-
-
Method Detail
-
builder
public static ActionMapper.Builder builder()
Initializes a new builder for anActionMapper.- Returns:
- a new builder
-
empty
public static ActionMapper empty()
Returns anActionMappercontaining no mappings.- Returns:
- an empty
ActionMapper
-
aggregate
public static ActionMapper aggregate(ActionMapper... mappers)
Aggregates the mappings contained in the givenmappersinto a singleActionMapperinstance. All mappers must be defining distinct sets of actions, any conflicts will cause anIllegalStateExceptionto be thrown.- Parameters:
mappers- the mappers to aggregate- Returns:
- an aggregated
ActionMapper - Throws:
IllegalStateException- if two or more mappers define a mapping for the same action type
-
findHandlerForAction
public <R> Optional<Function<StoreAction<R>,? extends Publisher<R>>> findHandlerForAction(StoreAction<R> action)
Retrieves the handler associated to the given action based on its concrete type.- Type Parameters:
R- the return type of the action, to ensure type safety- Parameters:
action- the action to retrieve the handler for- Returns:
- the handler for the given action, or
Optional.empty()if not found.
-
-