Package eu.bandm.tools.message
Class MessagePrinter<M extends Message>
java.lang.Object
eu.bandm.tools.message.MessagePrinter<M>
- Type Parameters:
M- the type of the messages
- 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, that stream is
After each printed message, that stream is
flushed explicitly.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classMessagePrinter.Indenting<M extends Message>Specialization ofMessagePrinterwith addtional features. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionPrints toSystem.err, using default encoding.Creates and uses as its drain a freshPrintWriterto theOutputStreamargument.Prints to thePrintWriterprovided. -
Method Summary
Modifier and TypeMethodDescriptionvoidPrint 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, waitMethods 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 freshPrintWriterto theOutputStreamargument.
Therefore printing must use the default character encoding.- Parameters:
os- the target of all text output
-
MessagePrinter
Prints to thePrintWriterprovided.By this, the character encoding can be set explicitly.
- 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 instance, for method 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 isflushedexplicitly.- Specified by:
receivein interfaceMessageReceiver<M extends Message>- Parameters:
message- the message to receive.
-