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 Summary
FieldsModifier and TypeFieldDescriptionstatic final Appender<?> A pre-made Appender for any Object items.static final Appender<CharSequence> A pre-made Appender for CharSequence items.Used in enum-keyed maps and sets to write an Enum constant's name, rather than its toString result.A pre-made Appender for String items. -
Method Summary
Modifier and TypeMethodDescriptionstatic <S extends CharSequence & Appendable, T>
Sappend(S sb, T item) Commonly used as a method reference where a generic Appender is needed.static <S extends CharSequence & Appendable>
SappendEnumName(S sb, Enum<?> item) Appends theEnum.name()to the given Appendable CharSequence, sovalueOfcan be used to look up an enum constant when reading.<S extends CharSequence & Appendable>
SAppendsitemtosband returnssbfor chaining.
-
Field Details
-
ENUM_NAME_APPENDER
-
STRING_APPENDER
-
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
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 toappend(CharSequence, Object)and store it once per type, as with:public static final Appender<Thing> THING_APPENDER = Appender::append;for your own typeThing.
-
-
Method Details
-
apply
Appendsitemtosband returnssbfor 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 StringBuilderitem- the item to append- Returns:
sb, after modification
-
append
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 CharListT- the type ofitem, which will be run throughObjects.toString(Object)to get a String representation- Parameters:
sb- an Appendable CharSequence that will be modified, such as a StringBuilderitem- the item to append- Returns:
sb, after modification
-
appendEnumName
Appends theEnum.name()to the given Appendable CharSequence, sovalueOfcan be used to look up an enum constant when reading.
Similar toappend(CharSequence, Object), but not intended to be used as a method reference; useENUM_NAME_APPENDERif 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 StringBuilderitem- the Enum item to append theEnum.name()of- Returns:
sb, after modification
-