Class PFBuilder<I,R>

java.lang.Object
org.apache.pekko.japi.pf.PFBuilder<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 final class PFBuilder<I,R> extends Object
A builder for PartialFunction.
  • Field Details

    • statements

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

    • PFBuilder

      public PFBuilder()
      Create a PFBuilder.
  • Method Details

    • create

      public static <I, R> PFBuilder<I,R> create()
      Create a new PFBuilder.
      Since:
      1.1.0
    • match

      public <P> PFBuilder<I,R> match(Class<P> type, Function<P,R> apply)
      Add a new case statement to this builder.
      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
    • matchUnchecked

      public PFBuilder<I,R> matchUnchecked(Class<?> type, Function<?,R> apply)
      Add a new case statement to this builder 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) -> {}.
      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
    • match

      public <P> PFBuilder<I,R> match(Class<P> type, Predicate<P> predicate, Function<P,R> apply)
      Add a new case statement to this builder.
      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 and the predicate returns true
      Returns:
      a builder with the case statement added
    • matchUnchecked

      public PFBuilder<I,R> matchUnchecked(Class<?> type, Predicate<?> predicate, Function<?,R> apply)
      Add a new case statement to this builder 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) -> {}.
      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 and the predicate returns true
      Returns:
      a builder with the case statement added
    • matchEquals

      public <P> PFBuilder<I,R> matchEquals(P object, Function<P,R> apply)
      Add a new case statement to this builder.
      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
    • matchAny

      public PFBuilder<I,R> matchAny(Function<I,R> apply)
      Add a new case statement to this builder, that matches any argument.
      Parameters:
      apply - an action to apply to the argument
      Returns:
      a builder with the case statement added
    • addStatement

      protected void addStatement(scala.PartialFunction<I,R> statement)
    • build

      public scala.PartialFunction<I,R> build()
      Build a PartialFunction from this builder. After this call the builder will be reset.
      Returns:
      a PartialFunction for this builder.