public class ReceiveBuilder
extends java.lang.Object
Actor.receive()
.
There is both a match on type only, and a match on type and predicate.
Inside an actor you can use it like this with Java 8 to define your receive method.
Example:
@Override public Actor() { receive(ReceiveBuilder. match(Double.class, d -> { sender().tell(d.isNaN() ? 0 : d, self()); }). match(Integer.class, i -> { sender().tell(i * 10, self()); }). match(String.class, s -> s.startsWith("foo"), s -> { sender().tell(s.toUpperCase(), self()); }).build() ); }This is an EXPERIMENTAL feature and is subject to change until it has received more real world testing.
Modifier and Type | Method and Description |
---|---|
static UnitPFBuilder<java.lang.Object> |
create()
Return a new
UnitPFBuilder with no case statements. |
static <P> UnitPFBuilder<java.lang.Object> |
match(java.lang.Class<? extends P> type,
FI.TypedPredicate<? extends P> predicate,
FI.UnitApply<? extends P> apply)
Return a new
UnitPFBuilder with a case statement added. |
static <P> UnitPFBuilder<java.lang.Object> |
match(java.lang.Class<? extends P> type,
FI.UnitApply<? extends P> apply)
Return a new
UnitPFBuilder with a case statement added. |
static UnitPFBuilder<java.lang.Object> |
matchAny(FI.UnitApply<java.lang.Object> apply)
Return a new
UnitPFBuilder with a case statement added. |
static <P> UnitPFBuilder<java.lang.Object> |
matchEquals(P object,
FI.TypedPredicate<P> predicate,
FI.UnitApply<P> apply)
Return a new
UnitPFBuilder with a case statement added. |
static <P> UnitPFBuilder<java.lang.Object> |
matchEquals(P object,
FI.UnitApply<P> apply)
Return a new
UnitPFBuilder with a case statement added. |
public static UnitPFBuilder<java.lang.Object> create()
UnitPFBuilder
with no case statements. They can be added later as the returned UnitPFBuilder
is a mutable object.public static <P> UnitPFBuilder<java.lang.Object> match(java.lang.Class<? extends P> type, FI.UnitApply<? extends P> apply)
UnitPFBuilder
with a case statement added.type
- a type to match the argument againstapply
- an action to apply to the argument if the type matchespublic static <P> UnitPFBuilder<java.lang.Object> match(java.lang.Class<? extends P> type, FI.TypedPredicate<? extends P> predicate, FI.UnitApply<? extends P> apply)
UnitPFBuilder
with a case statement added.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 and the predicate returns truepublic static <P> UnitPFBuilder<java.lang.Object> matchEquals(P object, FI.UnitApply<P> apply)
UnitPFBuilder
with a case statement added.object
- the object to compare equals withapply
- an action to apply to the argument if the object compares equalpublic static <P> UnitPFBuilder<java.lang.Object> matchEquals(P object, FI.TypedPredicate<P> predicate, FI.UnitApply<P> apply)
UnitPFBuilder
with a case statement added.object
- the object to compare equals withpredicate
- a predicate that will be evaluated on the argument if the object compares equalapply
- an action to apply to the argument if the object compares equalpublic static UnitPFBuilder<java.lang.Object> matchAny(FI.UnitApply<java.lang.Object> apply)
UnitPFBuilder
with a case statement added.apply
- an action to apply to the argument