public final class MatchBinder
extends java.lang.Object
StatefulMatchFunction
.
The following methods are supported for binding patterns, in order of precedence that they are checked for matches:
predicate(Class, Predicate, BiConsumer)
: matches on the input's type and a
conditional predicate on the input object state.
predicate(Class, BiConsumer)
: simple type match on the input's type.
otherwise(BiConsumer)
: default action to take if no match can be found for the
input.
Modifier and Type | Method and Description |
---|---|
MatchBinder |
otherwise(java.util.function.BiConsumer<Context,java.lang.Object> action)
Binds a default action for inputs that fail to match any of the patterns bind via the
predicate(Class, Predicate, BiConsumer) and predicate(Class, BiConsumer) methods. |
<T> MatchBinder |
predicate(java.lang.Class<T> type,
java.util.function.BiConsumer<Context,T> action)
Binds a simple type pattern which matches on the input's type.
|
<T> MatchBinder |
predicate(java.lang.Class<T> type,
java.util.function.Predicate<T> predicate,
java.util.function.BiConsumer<Context,T> action)
Binds a pattern which matches on a function's input type, as well as a conditional predicate on
the input object's state.
|
public <T> MatchBinder predicate(java.lang.Class<T> type, java.util.function.BiConsumer<Context,T> action)
This has a lower precedence than matches found on patterns registered via predicate(Class, Predicate, BiConsumer)
. If no conditional predicates matches for a given
input of type type
, then the action registered here will be used.
T
- the expected input type.type
- the expected input type.action
- the action to take if this pattern matches.public <T> MatchBinder predicate(java.lang.Class<T> type, java.util.function.Predicate<T> predicate, java.util.function.BiConsumer<Context,T> action)
Precedence of conditional predicate matches is determined by the order in which they were bind; predicates that were bind first have higher precedence. Patterns bind via this method have the highest precedence over other methods.
T
- the expected input type.type
- the expected input type.predicate
- a predicate on the input object state to match on.action
- the action to take if this patten matches.public MatchBinder otherwise(java.util.function.BiConsumer<Context,java.lang.Object> action)
predicate(Class, Predicate, BiConsumer)
and predicate(Class, BiConsumer)
methods. If
no default action was bind using this method, then a IllegalStateException
would be
thrown for inputs that fail to match.action
- the default actionCopyright © 2014–2024 The Apache Software Foundation. All rights reserved.