Class MessageFormatter<D>

All Implemented Interfaces:
MessageReceiver<SimpleMessage<D>>

public class MessageFormatter<D> extends MessagePasser<SimpleMessage<D>>
Interprets the SimpleMessage.args values as arguments to string formatting and calls String.format(String,Object...). Propagates to its drain a message with the new text.
  • Field Details

    • stripArgs

      protected boolean stripArgs
      Whether the args are only entered to formatting, but not propagated. Initially true.
  • Constructor Details

  • Method Details

    • setStripArgs

      public void setStripArgs(boolean b)
      Evident.
      Parameters:
      b - whether to strip the arguments.
    • receive

      public void receive(SimpleMessage<D> m)
      Applies the message text as a format to the arguments and propagates the new message to the current drain.
      Specified by:
      receive in interface MessageReceiver<D>
      Overrides:
      receive in class MessagePasser<SimpleMessage<D>>
      Parameters:
      m - the message to receive.
      See Also:
    • render

      @Opt public static @Opt String render(SimpleMessage<?> msg)
      Applies the text as a format to the arguments. String.format(String,Object...) is called in any case, also with empty arg list, for format codes like "%n". Any PreMessage is treated recursively. Any formatting which fails returns the concatenation of the text, an error text and the Object.toString() results of the arguments.
      Parameters:
      msg - the message to be rendered
      Returns:
      a string representation of the message text and the rendered arguments
    • process

      @Opt public static @Opt String process(PreMessage embed)
      Applies the text as a format to the arguments.
      Parameters:
      embed - text and arguments to be rendered
      Returns:
      a string representation of the message text and the rendered arguments
      See Also:
    • process

      @Opt public static @Opt String process(@Opt @Opt String text, Object[] args)
      Applies the text as a format to the arguments. String.format(String,Object...) is called in any case, also with empty args list, to format codes like "%n" and "%%". Any PreMessage is treated recursively.

      Any formatting which fails returns for diagnosis the concatenation of the text, an error text and the Object.toString() results of the arguments.

      Parameters:
      text - the format text to be rendered
      args - the arguments to be rendered
      Returns:
      a string representation of the message text and the rendered arguments, or null iff the text input is null.