From 953eab11d9beb947f74ad14f96652881b70dbaac Mon Sep 17 00:00:00 2001 From: Patrik Nordwall Date: Thu, 17 Oct 2019 16:10:40 +0200 Subject: [PATCH] Revert "Add external predicate to matchEquals and matchAny in ReceiverBuilder (#25822)" This reverts commit e27b25d8c9b3493dff83566813c378a8a1d6d402. --- .../java/akka/japi/pf/ReceiveBuilder.java | 51 +++++-------------- 1 file changed, 12 insertions(+), 39 deletions(-) diff --git a/akka-actor/src/main/java/akka/japi/pf/ReceiveBuilder.java b/akka-actor/src/main/java/akka/japi/pf/ReceiveBuilder.java index 1fa7959c9b..2c9d55364d 100644 --- a/akka-actor/src/main/java/akka/japi/pf/ReceiveBuilder.java +++ b/akka-actor/src/main/java/akka/japi/pf/ReceiveBuilder.java @@ -4,9 +4,10 @@ package akka.japi.pf; -import akka.actor.AbstractActor.Receive; import scala.PartialFunction; import scala.runtime.BoxedUnit; +import akka.actor.AbstractActor; +import akka.actor.AbstractActor.Receive; /** * Used for building a partial function for {@link akka.actor.AbstractActor#createReceive() @@ -168,7 +169,7 @@ public class ReceiveBuilder { * List.class and (List<String> list) -> {}. * * @param type a type to match the argument against - * @param externalPredicate an external predicate that will be evaluated if the type matches + * @param externalPredicate a external predicate that will be evaluated if the type matches * @param apply an action to apply to the argument if the type matches and the predicate returns * true * @return a builder with the case statement added @@ -239,27 +240,6 @@ public class ReceiveBuilder { return this; } - /** - * Add a new case statement to this builder. - * - * @param object the object to compare equals with - * @param externalPredicate an external predicate that will be evaluated if the object compares - * equal - * @param apply an action to apply to the argument if the object compares equal - * @return a builder with the case statement added - */ - @SuppressWarnings("unchecked") - public

ReceiveBuilder matchEquals( - final P object, - final java.util.function.BooleanSupplier externalPredicate, - final FI.UnitApply

apply) { - final FI.Predicate predicate = o -> object.equals(o) && externalPredicate.getAsBoolean(); - addStatement(new UnitCaseStatement<>(predicate, (FI.UnitApply) apply)); - return this; - } - - private static final FI.Predicate ALWAYS_TRUE = (input) -> true; - /** * Add a new case statement to this builder, that matches any argument. * @@ -267,22 +247,15 @@ public class ReceiveBuilder { * @return a builder with the case statement added */ public ReceiveBuilder matchAny(final FI.UnitApply apply) { - addStatement(new UnitCaseStatement<>(ALWAYS_TRUE, apply)); - return this; - } - - /** - * Add a new case statement to this builder, that pass the test of the predicate. - * - * @param externalPredicate an external predicate that will always be evaluated. - * @param apply an action to apply to the argument - * @return a builder with the case statement added - */ - public ReceiveBuilder matchAny( - final java.util.function.BooleanSupplier externalPredicate, - final FI.UnitApply apply) { - final FI.Predicate predicate = o -> externalPredicate.getAsBoolean(); - addStatement(new UnitCaseStatement<>(predicate, apply)); + addStatement( + new UnitCaseStatement( + new FI.Predicate() { + @Override + public boolean defined(Object o) { + return true; + } + }, + apply)); return this; } }