Package org.ujorm.tools.msg
Class MsgFormatter
java.lang.Object
org.ujorm.tools.msg.MsgFormatter
- Direct Known Subclasses:
ValueFormatter
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
FieldsModifier and TypeFieldDescriptionprotected static final StringParameter markprotected static final charSeparator of unmarked arguments '{}' was changed to a single space from release 1.91 -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedStatic methods are available onlyprotectedMsgFormatter(@NotNull String mark) Static methods are available only -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> @NotNull Stringformat(@Nullable CharSequence messageTemplate, @Nullable T... arguments) Format the message, see the next correct asserts:static <T> @Nullable Stringformat(@Nullable T... templateAndArguments) Format the message from Object array<T> @NotNull StringformatMsg(@Nullable Appendable writer, @Nullable CharSequence messageTemplate, @Nullable T... argumentValues) Format the message, see the next correct asserts:protected <T> @Nullable StringformatMsg(@Nullable Appendable writer, @Nullable T... templateAndArguments) Format the message from Object arrayprotected voidwriteValue(@Nullable Object value, @NotNull Appendable out, boolean marked) Print argument to the Writter with an optional format.
-
Field Details
-
DEFAULT_MARK
Parameter mark- See Also:
-
SEPARATOR
protected static final char SEPARATORSeparator 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
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 writermessageTemplate- Template where argument position is marked by the{}characters.argumentValues- Optional arguments, where theSupplierinterface 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- Appendablevalue- Value where theSupplierinterface 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 theSupplierinterface is supported.- Returns:
-
format
Format the message from Object array- Parameters:
templateAndArguments- The first item is a template where parameters are located by"{}". TheSupplierinterface 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.
-