Interface CharAppender
public interface CharAppender
A functional interface that takes and returns an object that is a CharSequence and is Appendable, appending
a
byte item to it.
This is often a method reference to a method in Base, such as Base.appendSigned(CharSequence, char).-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CharAppenderAppends one char at a time, without anything around it and without escaping any chars.static final CharAppenderAppends the given char in single quotes, with a backslash-escape if it would be necessary in Java sources.static final CharAppenderAppends char constants as they would be read in Java sources, in single quotes, with backslash escapes if necessary. -
Method Summary
Modifier and TypeMethodDescriptionstatic <S extends CharSequence & Appendable>
Sappend(S sb, char item) Appends a single char to sb.<S extends CharSequence & Appendable>
Sapply(S sb, char item) Appendsitemtosband returnssbfor chaining.
-
Field Details
-
DEFAULT
Appends one char at a time, without anything around it and without escaping any chars. This is a static constant to avoid Android and its R8 compiler allocating a new lambda every timeStringBuilder::appendis present at a call-site. This should be used in place ofStringBuilder.append(char)when you want to use that as a CharAppender.
This functional interface doesn't have aDENSEmethod reference because appending one shown char per char item is really as dense as you can get already. -
QUOTED
Appends the given char in single quotes, with a backslash-escape if it would be necessary in Java sources. -
READABLE
Appends char constants as they would be read in Java sources, in single quotes, with backslash escapes if necessary.
-
-
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
Appends a single char to sb. Doesn't append anything around it. Throws a RuntimeException if sb can't be appended to due to an IOException, which should never really happen unless you're using a fixed-size Appendable that has no room left.- 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
-