Package eu.bandm.tools.message
Class MessagePrinter<M extends Message>
java.lang.Object
eu.bandm.tools.message.MessagePrinter<M>
- All Implemented Interfaces:
MessageReceiver<M>
- Direct Known Subclasses:
MessagePrinter.Indenting
Prints textual representations of all received messages to an
output stream.
After each printed message this stream is
After each printed message this stream is
flushed
explicitly.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
MessagePrinter.Indenting<M extends Message>
Specialization ofMessagePrinter
with addtional features. -
Field Summary
-
Constructor Summary
ConstructorDescriptionPrints toSystem.err
, using default encoding.Creates and uses as its drain a freshPrintWriter
to theOutputStream
argument. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Print the message to the output stream.setMessageToString
(Function<? super M, ? extends String> toStr) Sets the function which converts the message to a printable string.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface eu.bandm.tools.message.MessageReceiver
ifSubcriticalThen, ifSubcriticalThen, ifSubcriticalThenElse
-
Field Details
-
out
The drain of the print activities. -
toStr
The function which converts the message to a printable string. Defaults toObject::toString
.
-
-
Constructor Details
-
MessagePrinter
public MessagePrinter()Prints toSystem.err
, using default encoding. -
MessagePrinter
Creates and uses as its drain a freshPrintWriter
to theOutputStream
argument.
Therefore printing must use the default character encoding.- Parameters:
os
- the target of all text output
-
MessagePrinter
- Parameters:
out
- the target of all text output
-
-
Method Details
-
setMessageToString
Sets the function which converts the message to a printable string.- Parameters:
toStr
- the function which converts the message to a printable string.- Returns:
- this for message chaining.
-
receive
Print the message to the output stream.Rendering is done by applying the function in
toStr
.
After each printed message the output stream isflushed
explicitly.- Specified by:
receive
in interfaceMessageReceiver<M extends Message>
- Parameters:
message
- the message to receive.
-