- 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
.
Implementing
An alternative to implementing this complicated interface is to simply make aFunction<@Nullable Object, String>
and call of(Function)
to create a
formatter.
To implement a custom formatter:
- Implement this interface or use
of(Function)
. - Register the custom formatter with
JStacheFormatter
. - Add additional allowed types with
JStacheFormatterTypes
on to the class that is annotated withJStacheFormatter
- Set
JStacheConfig.formatter()
to the class that has theJStacheFormatter
.
- Author:
- agentgt
- See Also:
- API Note
- Although the formatter has access to the raw
Output
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, Output, String, Class, Object)
.Formats the object and then sends the results to the downstream appender.Formats the object and then sends the results to the downstream appender.Formats the object and then sends the results to the downstream appender.Formats the object and then sends the results to the downstream appender.Formats the object and then sends the results to the downstream appender.Formats the object and then sends the results to the downstream appender.Formats the object and then sends the results to the downstream appender.Formats 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, Output, String, Class, Object)
. -
format
<A extends Output<E>,E extends Exception> void format(Appender downstream, A a, String path, Class<?> c, @Nullable Object o) throws E Formats the object and then sends the results to the downstream appender.- Type Parameters:
A
- the appendable typeE
- the appender exception 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:
E
- 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 Output<E>,E extends Exception> void format(Appender downstream, A a, String path, char c) throws E 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 typeE
- the appender exception 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:
E
- 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 Output<E>,E extends Exception> void format(Appender downstream, A a, String path, short s) throws E 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 typeE
- the appender exception 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:
E
- 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 Output<E>,E extends Exception> void format(Appender downstream, A a, String path, int i) throws E 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 typeE
- the appender exception 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:
E
- 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 Output<E>,E extends Exception> void format(Appender downstream, A a, String path, long l) throws E 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 typeE
- the appender exception 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:
E
- 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 Output<E>,E extends Exception> void format(Appender downstream, A a, String path, double d) throws E 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 typeE
- the appender exception 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:
E
- 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 Output<E>,E extends Exception> void format(Appender downstream, A a, String path, boolean b) throws E 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 typeE
- the appender exception 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:
E
- 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 Output<E>,E extends Exception> void format(Appender downstream, A a, String path, String s) throws E 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 typeE
- the appender exception 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:
E
- 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
-