Interface Formatter

All Superinterfaces:
Function<@Nullable Object,String>
All Known Subinterfaces:
DefaultFormatter, SpecFormatter

public interface Formatter extends Function<@Nullable Object,String>
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 Type
    Method
    Description
    default String
    apply(@Nullable Object t)
    default <A extends Appendable, APPENDER extends Appender<A>>
    void
    format(APPENDER downstream, A a, String path, boolean b)
    Formats the object and then sends the results to the downstream appender.
    default <A extends Appendable, APPENDER extends Appender<A>>
    void
    format(APPENDER downstream, A a, String path, char c)
    Formats the object and then sends the results to the downstream appender.
    default <A extends Appendable, APPENDER extends Appender<A>>
    void
    format(APPENDER downstream, A a, String path, double d)
    Formats the object and then sends the results to the downstream appender.
    default <A extends Appendable, APPENDER extends Appender<A>>
    void
    format(APPENDER downstream, A a, String path, int i)
    Formats the object and then sends the results to the downstream appender.
    default <A extends Appendable, APPENDER extends Appender<A>>
    void
    format(APPENDER downstream, A a, String path, long l)
    Formats the object and then sends the results to the downstream appender.
    default <A extends Appendable, APPENDER extends Appender<A>>
    void
    format(APPENDER downstream, A a, String path, short s)
    Formats the object and then sends the results to the downstream appender.
    <A extends Appendable, APPENDER extends Appender<A>>
    void
    format(APPENDER downstream, A a, String path, Class<?> c, @Nullable Object o)
    Formats the object and then sends the results to the downstream appender.
    default <A extends Appendable, APPENDER extends Appender<A>>
    void
    format(APPENDER downstream, A a, String path, String s)
    Formats the object and then sends the results to the downstream appender.
    static Formatter
    of(Function<@Nullable Object,String> formatterFunction)
    Adapts a function to a formatter.

    Methods inherited from interface java.util.function.Function

    andThen, compose
  • Method Details

    • apply

      default String apply(@Nullable Object t)
      Specified by:
      apply in interface Function<@Nullable Object,String>
      Parameters:
      t - the object to be formatted. Maybe null.
      Returns:
      the formatted results as a String.
    • 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 type
      APPENDER - the downstream appender type
      Parameters:
      downstream - the downstream appender to be used instead of the appendable directly
      a - the appendable to be passed to the appender
      path - the dotted mustache like path
      c - 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 type
      APPENDER - the downstream appender type
      Parameters:
      downstream - the downstream appender to be used instead of the appendable directly
      a - the appendable to be passed to the appender
      path - the dotted mustache like path
      c - 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 type
      APPENDER - the downstream appender type
      Parameters:
      downstream - the downstream appender to be used instead of the appendable directly
      a - the appendable to be passed to the appender
      path - the dotted mustache like path
      s - 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 type
      APPENDER - the downstream appender type
      Parameters:
      downstream - the downstream appender to be used instead of the appendable directly
      a - the appendable to be passed to the appender
      path - the dotted mustache like path
      i - 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 type
      APPENDER - the downstream appender type
      Parameters:
      downstream - the downstream appender to be used instead of the appendable directly
      a - the appendable to be passed to the appender
      path - the dotted mustache like path
      l - 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 type
      APPENDER - the downstream appender type
      Parameters:
      downstream - the downstream appender to be used instead of the appendable directly
      a - the appendable to be passed to the appender
      path - the dotted mustache like path
      d - 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 type
      APPENDER - the downstream appender type
      Parameters:
      downstream - the downstream appender to be used instead of the appendable directly
      a - the appendable to be passed to the appender
      path - the dotted mustache like path
      b - 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 type
      APPENDER - the downstream appender type
      Parameters:
      downstream - the downstream appender to be used instead of the appendable directly
      a - the appendable to be passed to the appender
      path - the dotted mustache like path
      s - 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

      static Formatter of(Function<@Nullable Object,String> formatterFunction)
      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