Interface Appender<T>

Type Parameters:
T - the type of items that can be appended by this functional interface

public interface Appender<T>
A functional interface that takes and returns an object that is a CharSequence and is Appendable, appending a T item to it. This is not typically a method reference to anything in Base, which is different from other Appender types. This will frequently use a lambda.
  • Field Details

    • ENUM_NAME_APPENDER

      static final Appender<Enum<?>> ENUM_NAME_APPENDER
      Used in enum-keyed maps and sets to write an Enum constant's name, rather than its toString result. Does not use a method reference, and instead has to use an anonymous inner class, because of GWT.
    • STRING_APPENDER

      static final Appender<String> STRING_APPENDER
      A pre-made Appender for String items. This exists both for convenience and to avoid repeatedly creating new method references on Android.
    • CHARSEQUENCE_APPENDER

      static final Appender<CharSequence> CHARSEQUENCE_APPENDER
      A pre-made Appender for CharSequence items. This exists both for convenience and to avoid repeatedly creating new method references on Android.
    • ANY_APPENDER

      static final Appender<?> ANY_APPENDER
      A pre-made Appender for any Object items. This exists both for convenience and to avoid repeatedly creating new method references on Android.
      NOTE: Whether this works or not in practice (on all platforms) is unknown. If in doubt, create a strongly-typed Appender from a method reference to append(CharSequence, Object) and store it once per type, as with: public static final Appender<Thing> THING_APPENDER = Appender::append; for your own type Thing.
  • Method Details

    • apply

      <S extends CharSequence & Appendable> S apply(S sb, T item)
      Appends item to sb and returns sb for chaining.
      Type Parameters:
      S - any type that is both a CharSequence and an Appendable, such as StringBuilder, StringBuffer, CharBuffer, or CharList
      Parameters:
      sb - an Appendable CharSequence that will be modified, such as a StringBuilder
      item - the item to append
      Returns:
      sb, after modification
    • append

      static <S extends CharSequence & Appendable, T> S append(S sb, T item)
      Commonly used as a method reference where a generic Appender is needed.
      Type Parameters:
      S - any type that is both a CharSequence and an Appendable, such as StringBuilder, StringBuffer, CharBuffer, or CharList
      T - the type of item, which will be run through Objects.toString(Object) to get a String representation
      Parameters:
      sb - an Appendable CharSequence that will be modified, such as a StringBuilder
      item - the item to append
      Returns:
      sb, after modification
    • appendEnumName

      static <S extends CharSequence & Appendable> S appendEnumName(S sb, Enum<?> item)
      Appends the Enum.name() to the given Appendable CharSequence, so valueOf can be used to look up an enum constant when reading.
      Similar to append(CharSequence, Object), but not intended to be used as a method reference; use ENUM_NAME_APPENDER if you need an Appender instance (it should perform identically, but works around a bug in GWT that would make a method reference fail to compile).
      Type Parameters:
      S - any type that is both a CharSequence and an Appendable, such as StringBuilder, StringBuffer, CharBuffer, or CharList
      Parameters:
      sb - an Appendable CharSequence that will be modified, such as a StringBuilder
      item - the Enum item to append the Enum.name() of
      Returns:
      sb, after modification