Package org.apache.pekko.japi.pf
Class Match<I,R>
- java.lang.Object
-
- org.apache.pekko.japi.pf.Match<I,R>
-
- Type Parameters:
I
- the input type, that this PartialFunction will be applied toR
- the return type, that the results of the application will have
public class Match<I,R> extends java.lang.Object
Version ofPartialFunction
that can be built during runtime from Java.
-
-
Field Summary
Fields Modifier and Type Field Description protected scala.PartialFunction<I,R>
statements
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description scala.PartialFunction<I,R>
asPF()
Turn thisMatch
into aPartialFunction
.static <F,T>
Match<F,T>create(PFBuilder<F,T> builder)
Create aMatch
from the builder.R
match(I i)
Convenience function to make the Java code more readable.static <F,T,P>
PFBuilder<F,T>match(java.lang.Class<P> type, FI.Apply<P,T> apply)
Convenience function to create aPFBuilder
with the first case statement added.static <F,T,P>
PFBuilder<F,T>match(java.lang.Class<P> type, FI.TypedPredicate<P> predicate, FI.Apply<P,T> apply)
Convenience function to create aPFBuilder
with the first case statement added.static <F,T>
PFBuilder<F,T>matchAny(FI.Apply<F,T> apply)
Convenience function to create aPFBuilder
with the first case statement added.static <F,T,P>
PFBuilder<F,T>matchEquals(P object, FI.Apply<P,T> apply)
Convenience function to create aPFBuilder
with the first case statement added.static <F,T>
PFBuilder<F,T>matchUnchecked(java.lang.Class<?> type, FI.Apply<?,T> apply)
Convenience function to create aPFBuilder
with the first case statement added without compile time type check of the parameters.static <F,T>
PFBuilder<F,T>matchUnchecked(java.lang.Class<?> type, FI.TypedPredicate<?> predicate, FI.Apply<?,T> apply)
Convenience function to create aPFBuilder
with the first case statement added without compile time type check of the parameters.
-
-
-
Method Detail
-
match
public static <F,T,P> PFBuilder<F,T> match(java.lang.Class<P> type, FI.Apply<P,T> apply)
Convenience function to create aPFBuilder
with the first case statement added.- Parameters:
type
- a type to match the argument againstapply
- an action to apply to the argument if the type matches- Returns:
- a builder with the case statement added
- See Also:
PFBuilder.match(Class, FI.Apply)
-
matchUnchecked
public static <F,T> PFBuilder<F,T> matchUnchecked(java.lang.Class<?> type, FI.Apply<?,T> apply)
Convenience function to create aPFBuilder
with the first case statement added without compile time type check of the parameters. Should normally not be used, but when matching on class with generic type argument it can be useful, e.g.List.class
and(List<String> list) -> {}
.
-
match
public static <F,T,P> PFBuilder<F,T> match(java.lang.Class<P> type, FI.TypedPredicate<P> predicate, FI.Apply<P,T> apply)
Convenience function to create aPFBuilder
with the first case statement added.- Parameters:
type
- a type to match the argument againstpredicate
- a predicate that will be evaluated on the argument if the type matchesapply
- an action to apply to the argument if the type matches- Returns:
- a builder with the case statement added
- See Also:
PFBuilder.match(Class, FI.TypedPredicate, FI.Apply)
-
matchUnchecked
public static <F,T> PFBuilder<F,T> matchUnchecked(java.lang.Class<?> type, FI.TypedPredicate<?> predicate, FI.Apply<?,T> apply)
Convenience function to create aPFBuilder
with the first case statement added without compile time type check of the parameters. Should normally not be used, but when matching on class with generic type argument it can be useful, e.g.List.class
and(List<String> list) -> {}
.
-
matchEquals
public static <F,T,P> PFBuilder<F,T> matchEquals(P object, FI.Apply<P,T> apply)
Convenience function to create aPFBuilder
with the first case statement added.- Parameters:
object
- the object to compare equals withapply
- an action to apply to the argument if the object compares equal- Returns:
- a builder with the case statement added
- See Also:
PFBuilder.matchEquals(Object, FI.Apply)
-
matchAny
public static <F,T> PFBuilder<F,T> matchAny(FI.Apply<F,T> apply)
Convenience function to create aPFBuilder
with the first case statement added.- Parameters:
apply
- an action to apply to the argument- Returns:
- a builder with the case statement added
- See Also:
PFBuilder.matchAny(FI.Apply)
-
create
public static final <F,T> Match<F,T> create(PFBuilder<F,T> builder)
Create aMatch
from the builder.- Parameters:
builder
- a builder representing the partial function- Returns:
- a
Match
that can be reused
-
match
public R match(I i) throws scala.MatchError
Convenience function to make the Java code more readable.Match<X, Y> matcher = Match.create(...); Y someY = matcher.match(obj);
- Parameters:
i
- the argument to apply the match to- Returns:
- the result of the application
- Throws:
scala.MatchError
- if there is no match
-
-