Package org.drasyl.behaviour
Class Behavior.BehaviorBuilder
- java.lang.Object
-
- org.drasyl.behaviour.Behavior.BehaviorBuilder
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Behavior
build()
Build a behavior from the current state of the builder.Behavior.BehaviorBuilder
onAnyEvent(Function<Event,Behavior> handler)
Adds a new case to the event handling matching any event.<M> Behavior.BehaviorBuilder
onAnyMessage(BiFunction<IdentityPublicKey,M,Behavior> handler)
Adds a new case to the event handling matching anyMessageEvent
.<M extends Event>
Behavior.BehaviorBuilderonEvent(Class<M> type, Function<M,Behavior> handler)
Adds a new case to the event handling.<M extends Event>
Behavior.BehaviorBuilderonEvent(Class<M> type, Predicate<M> test, Function<M,Behavior> handler)
Adds a new predicated case to the event handling.<M extends Event>
Behavior.BehaviorBuilderonEventEquals(M event, Supplier<Behavior> handler)
Add a new case to the event handling matching equal events.<M> Behavior.BehaviorBuilder
onMessage(Class<M> messageType, BiFunction<IdentityPublicKey,M,Behavior> handler)
Add a new case to the event matching matching events of typeMessageEvent
withMessageEvent.getPayload()
matchingmessageType
.<M> Behavior.BehaviorBuilder
onMessage(Class<M> messageType, BiPredicate<IdentityPublicKey,M> test, BiFunction<IdentityPublicKey,M,Behavior> handler)
Add a new predicated case to the event matching matching events of typeMessageEvent
withMessageEvent.getPayload()
matchingmessageType
.<M> Behavior.BehaviorBuilder
onMessageEquals(IdentityPublicKey sender, M payload, Supplier<Behavior> handler)
Add a new case to the event handling matching events of typeMessageEvent
with equalMessageEvent.getPayload()
.
-
-
-
Method Detail
-
onEvent
public <M extends Event> Behavior.BehaviorBuilder onEvent(Class<M> type, Predicate<M> test, Function<M,Behavior> handler)
Adds a new predicated case to the event handling.- Type Parameters:
M
- type of event to match- Parameters:
type
- type of the event to matchtest
- a predicate that will be evaluated on the argument if the type matcheshandler
- action to apply if the type matches- Returns:
- a new
Behavior.BehaviorBuilder
with the specified handling appended
-
onEvent
public <M extends Event> Behavior.BehaviorBuilder onEvent(Class<M> type, Function<M,Behavior> handler)
Adds a new case to the event handling.- Type Parameters:
M
- type of event to match- Parameters:
type
- type of the event to matchhandler
- action to apply if the type matches- Returns:
- a new
Behavior.BehaviorBuilder
with the specified handling appended
-
onEventEquals
public <M extends Event> Behavior.BehaviorBuilder onEventEquals(M event, Supplier<Behavior> handler)
Add a new case to the event handling matching equal events.- Parameters:
event
- the event to compare tohandler
- action to apply when the event matches- Returns:
- a new
Behavior.BehaviorBuilder
with the specified handling appended
-
onAnyEvent
public Behavior.BehaviorBuilder onAnyEvent(Function<Event,Behavior> handler)
Adds a new case to the event handling matching any event. SubsequentonEvent(...)
andonMessage(...)
clauses will never see any events.- Parameters:
handler
- action to apply for any event- Returns:
- a new
Behavior.BehaviorBuilder
with the specified handling appended
-
onMessage
public <M> Behavior.BehaviorBuilder onMessage(Class<M> messageType, BiPredicate<IdentityPublicKey,M> test, BiFunction<IdentityPublicKey,M,Behavior> handler)
Add a new predicated case to the event matching matching events of typeMessageEvent
withMessageEvent.getPayload()
matchingmessageType
.- Type Parameters:
M
- type of event to match- Parameters:
messageType
- type of the event to matchtest
- a predicate that will be evaluated on the argument if the type matcheshandler
- action to apply if the type matches- Returns:
- a new
Behavior.BehaviorBuilder
with the specified handling appended
-
onMessage
public <M> Behavior.BehaviorBuilder onMessage(Class<M> messageType, BiFunction<IdentityPublicKey,M,Behavior> handler)
Add a new case to the event matching matching events of typeMessageEvent
withMessageEvent.getPayload()
matchingmessageType
.- Type Parameters:
M
- type of event to match- Parameters:
messageType
- type of the event to matchhandler
- action to apply if the type matches- Returns:
- a new
Behavior.BehaviorBuilder
with the specified handling appended
-
onMessageEquals
public <M> Behavior.BehaviorBuilder onMessageEquals(IdentityPublicKey sender, M payload, Supplier<Behavior> handler)
Add a new case to the event handling matching events of typeMessageEvent
with equalMessageEvent.getPayload()
.- Parameters:
sender
- the message sender to compare topayload
- the message payload to compare tohandler
- action to apply when the event matches- Returns:
- a new
Behavior.BehaviorBuilder
with the specified handling appended
-
onAnyMessage
public <M> Behavior.BehaviorBuilder onAnyMessage(BiFunction<IdentityPublicKey,M,Behavior> handler)
Adds a new case to the event handling matching anyMessageEvent
. SubsequentonMessage(...)
clauses will never see any messages.- Parameters:
handler
- action to apply for any message- Returns:
- a new
Behavior.BehaviorBuilder
with the specified handling appended
-
build
public Behavior build()
Build a behavior from the current state of the builder.
-
-