Package eu.bandm.tools.message
Class MessageMapper<M extends Message,N extends Message>
- java.lang.Object
-
- eu.bandm.tools.message.SingleSender<N>
-
- eu.bandm.tools.message.MessageMapper<M,N>
-
- All Implemented Interfaces:
MessageReceiver<M>
public class MessageMapper<M extends Message,N extends Message> extends SingleSender<N> implements MessageReceiver<M>
A message receiver which receives a message of one type, and propagates the result of applying a function to this message, which may be of different type.
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
allowPartialFunctions
Whether a null value coming from the function means not to send anything.protected java.util.function.Function<? super M,? extends N>
fun
Evident.-
Fields inherited from class eu.bandm.tools.message.SingleSender
receiver
-
-
Constructor Summary
Constructors Constructor Description MessageMapper(java.util.function.Function<? super M,? extends N> fun)
Will apply the specified total function to each received message.MessageMapper(java.util.function.Function<? super M,? extends N> fun, boolean p)
Will apply the specified function to each received message.MessageMapper(java.util.function.Function<? super M,? extends N> fun, boolean p, MessageReceiver<N> drain)
Will apply the specified function to each received message.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <M extends Message,N extends Message>
java.util.function.Function<MessageReceiver<N>,MessageReceiver<M>>lift(java.util.function.Function<M,? extends N> f)
Delivers a function to apply on a message receiver for type "N" to get a message receiver for type "M", when a function is given which maps the messages the other way round.void
receive(M message)
Apply the functionfun
and send its result to the curent drainSingleSender.receiver
.protected void
setAllowPartialFunctions(boolean b)
Evident-
Methods inherited from class eu.bandm.tools.message.SingleSender
getReceiver, send, setReceiver
-
-
-
-
Constructor Detail
-
MessageMapper
public MessageMapper(java.util.function.Function<? super M,? extends N> fun, boolean p, MessageReceiver<N> drain)
Will apply the specified function to each received message.- Parameters:
p
- whether partial functions returning null are allowed
-
MessageMapper
public MessageMapper(java.util.function.Function<? super M,? extends N> fun, boolean p)
Will apply the specified function to each received message.- Parameters:
p
- whether partial functions returning null are allowed
-
-
Method Detail
-
setAllowPartialFunctions
protected void setAllowPartialFunctions(boolean b)
Evident
-
receive
public void receive(M message)
Apply the functionfun
and send its result to the curent drainSingleSender.receiver
.- Specified by:
receive
in interfaceMessageReceiver<M extends Message>
-
lift
public static <M extends Message,N extends Message> java.util.function.Function<MessageReceiver<N>,MessageReceiver<M>> lift(java.util.function.Function<M,? extends N> f)
Delivers a function to apply on a message receiver for type "N" to get a message receiver for type "M", when a function is given which maps the messages the other way round.
-
-