- All Known Subinterfaces:
DefaultFormatter
,SpecFormatter
Formats and then sends the results to the downstream appender.
Implementations should be singleton like and should not contain state. By default
native types are passed straight through to the downstream appender. If this is not
desired one can override those methods.
Important: the formatter does not decide what types are allowed at compile time to
be formatted. To control what types are allowed to be formatted see
JStacheFormatterTypes
.
An alternative to implementing this complicated interface is to simply make a
Function<@Nullable Object, String>
and call of(Function)
to create a
formatter.
- Author:
- agentgt
- See Also:
- API Note
- Although the formatter has access to the raw
Appendable
the formatter should never use it directly and simply pass it on to the downstream appender.
-
Method Summary
Modifier and TypeMethodDescriptiondefault String
Formats an object by usingStringBuilder
and callingformat(Appender, Appendable, String, Class, Object)
.default <A extends Appendable,
APPENDER extends Appender<A>>
voidFormats the object and then sends the results to the downstream appender.default <A extends Appendable,
APPENDER extends Appender<A>>
voidFormats the object and then sends the results to the downstream appender.default <A extends Appendable,
APPENDER extends Appender<A>>
voidFormats the object and then sends the results to the downstream appender.default <A extends Appendable,
APPENDER extends Appender<A>>
voidFormats the object and then sends the results to the downstream appender.default <A extends Appendable,
APPENDER extends Appender<A>>
voidFormats the object and then sends the results to the downstream appender.default <A extends Appendable,
APPENDER extends Appender<A>>
voidFormats the object and then sends the results to the downstream appender.<A extends Appendable,
APPENDER extends Appender<A>>
voidFormats the object and then sends the results to the downstream appender.default <A extends Appendable,
APPENDER extends Appender<A>>
voidFormats the object and then sends the results to the downstream appender.static Formatter
Adapts a function to a formatter.
-
Method Details
-
apply
Formats an object by usingStringBuilder
and callingformat(Appender, Appendable, String, Class, Object)
. -
format
<A extends Appendable,APPENDER extends Appender<A>> void format(APPENDER downstream, A a, String path, Class<?> c, @Nullable Object o) throws IOException Formats the object and then sends the results to the downstream appender.- Type Parameters:
A
- the appendable typeAPPENDER
- the downstream appender type- Parameters:
downstream
- the downstream appender to be used instead of the appendable directlya
- the appendable to be passed to the appenderpath
- the dotted mustache like pathc
- the object class but is not guaranteed to be accurate. If it is not known Object.class will be used.o
- the object which maybe null- Throws:
IOException
- if the appender or appendable throws an exception- API Note
- Although the formatter has access to the raw
Appendable
the formatter should never use it directly and simply pass it on to the downstream appender.
-
format
default <A extends Appendable,APPENDER extends Appender<A>> void format(APPENDER downstream, A a, String path, char c) throws IOException Formats the object and then sends the results to the downstream appender. The default implementation passes natives through to the downstream appender.- Type Parameters:
A
- the appendable typeAPPENDER
- the downstream appender type- Parameters:
downstream
- the downstream appender to be used instead of the appendable directlya
- the appendable to be passed to the appenderpath
- the dotted mustache like pathc
- character- Throws:
IOException
- if the appender or appendable throws an exception- API Note
- Although the formatter has access to the raw
Appendable
the formatter should never use it directly and simply pass it on to the downstream appender.
-
format
default <A extends Appendable,APPENDER extends Appender<A>> void format(APPENDER downstream, A a, String path, short s) throws IOException Formats the object and then sends the results to the downstream appender. The default implementation passes natives through to the downstream appender.- Type Parameters:
A
- the appendable typeAPPENDER
- the downstream appender type- Parameters:
downstream
- the downstream appender to be used instead of the appendable directlya
- the appendable to be passed to the appenderpath
- the dotted mustache like paths
- short- Throws:
IOException
- if the appender or appendable throws an exception- API Note
- Although the formatter has access to the raw
Appendable
the formatter should never use it directly and simply pass it on to the downstream appender.
-
format
default <A extends Appendable,APPENDER extends Appender<A>> void format(APPENDER downstream, A a, String path, int i) throws IOException Formats the object and then sends the results to the downstream appender. The default implementation passes natives through to the downstream appender.- Type Parameters:
A
- the appendable typeAPPENDER
- the downstream appender type- Parameters:
downstream
- the downstream appender to be used instead of the appendable directlya
- the appendable to be passed to the appenderpath
- the dotted mustache like pathi
- integer- Throws:
IOException
- if the appender or appendable throws an exception- API Note
- Although the formatter has access to the raw
Appendable
the formatter should never use it directly and simply pass it on to the downstream appender.
-
format
default <A extends Appendable,APPENDER extends Appender<A>> void format(APPENDER downstream, A a, String path, long l) throws IOException Formats the object and then sends the results to the downstream appender. The default implementation passes natives through to the downstream appender.- Type Parameters:
A
- the appendable typeAPPENDER
- the downstream appender type- Parameters:
downstream
- the downstream appender to be used instead of the appendable directlya
- the appendable to be passed to the appenderpath
- the dotted mustache like pathl
- long- Throws:
IOException
- if the appender or appendable throws an exception- API Note
- Although the formatter has access to the raw
Appendable
the formatter should never use it directly and simply pass it on to the downstream appender.
-
format
default <A extends Appendable,APPENDER extends Appender<A>> void format(APPENDER downstream, A a, String path, double d) throws IOException Formats the object and then sends the results to the downstream appender. The default implementation passes natives through to the downstream appender.- Type Parameters:
A
- the appendable typeAPPENDER
- the downstream appender type- Parameters:
downstream
- the downstream appender to be used instead of the appendable directlya
- the appendable to be passed to the appenderpath
- the dotted mustache like pathd
- double- Throws:
IOException
- if the appender or appendable throws an exception- API Note
- Although the formatter has access to the raw
Appendable
the formatter should never use it directly and simply pass it on to the downstream appender.
-
format
default <A extends Appendable,APPENDER extends Appender<A>> void format(APPENDER downstream, A a, String path, boolean b) throws IOException Formats the object and then sends the results to the downstream appender. The default implementation passes natives through to the downstream appender.- Type Parameters:
A
- the appendable typeAPPENDER
- the downstream appender type- Parameters:
downstream
- the downstream appender to be used instead of the appendable directlya
- the appendable to be passed to the appenderpath
- the dotted mustache like pathb
- boolean- Throws:
IOException
- if the appender or appendable throws an exception- API Note
- Although the formatter has access to the raw
Appendable
the formatter should never use it directly and simply pass it on to the downstream appender.
-
format
default <A extends Appendable,APPENDER extends Appender<A>> void format(APPENDER downstream, A a, String path, String s) throws IOException Formats the object and then sends the results to the downstream appender. The default implementation passes natives through to the downstream appender.- Type Parameters:
A
- the appendable typeAPPENDER
- the downstream appender type- Parameters:
downstream
- the downstream appender to be used instead of the appendable directlya
- the appendable to be passed to the appenderpath
- the dotted mustache like paths
- String- Throws:
IOException
- if the appender or appendable throws an exception- API Note
- Although the formatter has access to the raw
Appendable
the formatter should never use it directly and simply pass it on to the downstream appender.
-
of
Adapts a function to a formatter. If the function is already a formatter then it is simply returned (noop). Thus it is safe to repeatedly call this on formatters. If the function is adapted the returned adapted formatter does not pass native types to the inputted function.- Parameters:
formatterFunction
- if it is already an escaper- Returns:
- adapted formattter
-