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 to
R - the return type, that the results of the application will have

public class Match<I,R> extends Object
Version of PartialFunction that can be built during runtime from Java.
  • Field Details

    • statements

      protected final scala.PartialFunction<I,R> statements
  • Method Details

    • match

      public static <F, T, P> PFBuilder<F,T> match(Class<P> type, Function<P,T> apply)
      Convenience function to create a PFBuilder with the first case statement added.
      Parameters:
      type - a type to match the argument against
      apply - an action to apply to the argument if the type matches
      Returns:
      a builder with the case statement added
      See Also:
    • matchUnchecked

      public static <F, T> PFBuilder<F,T> matchUnchecked(Class<?> type, Function<?,T> apply)
      Convenience function to create a PFBuilder 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) -> {}.
      See Also:
    • match

      public static <F, T, P> PFBuilder<F,T> match(Class<P> type, Predicate<P> predicate, Function<P,T> apply)
      Convenience function to create a PFBuilder with the first case statement added.
      Parameters:
      type - a type to match the argument against
      predicate - a predicate that will be evaluated on the argument if the type matches
      apply - an action to apply to the argument if the type matches
      Returns:
      a builder with the case statement added
      See Also:
    • matchUnchecked

      public static <F, T> PFBuilder<F,T> matchUnchecked(Class<?> type, Predicate<?> predicate, Function<?,T> apply)
      Convenience function to create a PFBuilder 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) -> {}.
      See Also:
    • matchEquals

      public static <F, T, P> PFBuilder<F,T> matchEquals(P object, Function<P,T> apply)
      Convenience function to create a PFBuilder with the first case statement added.
      Parameters:
      object - the object to compare equals with
      apply - an action to apply to the argument if the object compares equal
      Returns:
      a builder with the case statement added
      See Also:
    • matchAny

      public static <F, T> PFBuilder<F,T> matchAny(Function<F,T> apply)
      Convenience function to create a PFBuilder 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:
    • create

      public static final <F, T> Match<F,T> create(PFBuilder<F,T> builder)
      Create a Match 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
    • asPF

      public scala.PartialFunction<I,R> asPF()
      Turn this Match into a PartialFunction.
      Returns:
      a partial function representation ot his Match