Class MsgFormatter

java.lang.Object
org.ujorm.tools.msg.MsgFormatter
Direct Known Subclasses:
ValueFormatter

@Unmodifiable public class MsgFormatter extends Object
Formatter of log messages where argument is located by the {} characters. See the next correct asserts:
  assertEquals("TEST"    , MsgFormatter.format("TE{}T", "S"));
  assertEquals("TE, S, T", MsgFormatter.format("TE", "S", "T"));
  assertEquals("TES{}"   , MsgFormatter.format("TE{}{}", "S"));
 
Since:
1.73
Author:
Pavel Ponec
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static final String
    Parameter mark
    protected static final char
    Separator of unmarked arguments '{}' was changed to a single space from release 1.91
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Static methods are available only
    protected
    MsgFormatter(@NotNull String mark)
    Static methods are available only
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> @NotNull String
    format(@Nullable CharSequence messageTemplate, @Nullable T... arguments)
    Format the message, see the next correct asserts:
    static <T> @Nullable String
    format(@Nullable T... templateAndArguments)
    Format the message from Object array
    <T> @NotNull String
    formatMsg(@Nullable Appendable writer, @Nullable CharSequence messageTemplate, @Nullable T... argumentValues)
    Format the message, see the next correct asserts:
    protected <T> @Nullable String
    formatMsg(@Nullable Appendable writer, @Nullable T... templateAndArguments)
    Format the message from Object array
    protected void
    writeValue(@Nullable Object value, @NotNull Appendable out, boolean marked)
    Print argument to the Writter with an optional format.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_MARK

      protected static final String DEFAULT_MARK
      Parameter mark
      See Also:
    • SEPARATOR

      protected static final char SEPARATOR
      Separator of unmarked arguments '{}' was changed to a single space from release 1.91
      See Also:
  • Constructor Details

    • MsgFormatter

      protected MsgFormatter()
      Static methods are available only
    • MsgFormatter

      protected MsgFormatter(@NotNull @NotNull String mark)
      Static methods are available only
  • Method Details

    • formatMsg

      @NotNull public <T> @NotNull String formatMsg(@Nullable @Nullable Appendable writer, @Nullable @Nullable CharSequence messageTemplate, @Nullable @Nullable T... argumentValues) throws IOException
      Format the message, see the next correct asserts:
        assertEquals("TEST"    , MsgFormatter.format("TE{}T", "S"));
        assertEquals("TE, S, T", MsgFormatter.format("TE", "S", "T"));
        assertEquals("TES{}"   , MsgFormatter.format("TE{}{}", "S"));
       
      Parameters:
      writer - An optional writer
      messageTemplate - Template where argument position is marked by the {} characters.
      argumentValues - Optional arguments, where the Supplier interface is supported.
      Returns:
      A result text or an empty text, if the writer is available.
      Throws:
      IOException
    • formatMsg

      @Nullable protected <T> @Nullable String formatMsg(@Nullable @Nullable Appendable writer, @Nullable @Nullable T... templateAndArguments) throws IOException
      Format the message from Object array
      Parameters:
      templateAndArguments - The first item is a template where parameters are located by "{}" text and the next arguments are optional parameters of the template.
      Returns:
      In case the argument have no length, the result message is null.
      Throws:
      IOException
    • writeValue

      protected void writeValue(@Nullable @Nullable Object value, @NotNull @NotNull Appendable out, boolean marked) throws IOException
      Print argument to the Writter with an optional format.
      Parameters:
      out - Appendable
      value - Value where the Supplier interface is supported.
      Throws:
      IOException
    • format

      @NotNull public static <T> @NotNull String format(@Nullable @Nullable CharSequence messageTemplate, @Nullable @Nullable T... arguments)
      Format the message, see the next correct asserts:
        assertEquals("TEST"    , MsgFormatter.format("TE{}T", "S"));
        assertEquals("TE S T", MsgFormatter.format("TE", "S", "T"));
        assertEquals("TES{}"   , MsgFormatter.format("TE{}{}", "S"));
       
      Parameters:
      messageTemplate - Template where argument position is marked by the {} characters.
      arguments - Optional arguments, where the Supplier interface is supported.
      Returns:
    • format

      @Nullable public static <T> @Nullable String format(@Nullable @Nullable T... templateAndArguments)
      Format the message from Object array
      Parameters:
      templateAndArguments - The first item is a template where parameters are located by "{}". The Supplier interface is supported. text and the next arguments are optional parameters of the template.
      Returns:
      In case the argument have no length, the result message is null.