Class DefaultCharAppender
- All Implemented Interfaces:
CharAppender,CharSequence
- Direct Known Subclasses:
ExpandingCharAppender
CharAppender interface-
Field Summary
FieldsModifier and TypeFieldDescription(package private) char[](package private) final char[](package private) final String(package private) int(package private) int(package private) final int -
Constructor Summary
ConstructorsConstructorDescriptionDefaultCharAppender(int maxLength, String emptyValue, int whitespaceRangeStart) Creates a DefaultCharAppender with a maximum limit of characters to append and the default value to return when no characters have been accumulated. -
Method Summary
Modifier and TypeMethodDescriptionvoidappend(char ch) Appends the given character.final voidappend(char[] ch) Appends characters from an input arrayvoidappend(char[] ch, int from, int length) Appends characters from an input arrayfinal voidappend(int ch) Appends the given codepoint.final voidappend(int[] ch) Appends codepoints from an input arrayvoidappend(DefaultCharAppender appender) Appends the contents of another DefaultCharAppender, discarding any of its trailing whitespace charactersfinal voidAppends theStringrepresentation of a given object.final voidAppends characters from an inputStringvoidAppends the contents of a String to this appendervoidappendIgnoringPadding(char ch, char padding) Appends the given character and marks it as ignored if it is a padding character (the definition of a padding character is implementation dependent.)voidappendIgnoringWhitespace(char ch) Appends the given character and marks it as ignored if it is a whitespace (ch <= ' ')voidappendIgnoringWhitespaceAndPadding(char ch, char padding) Appends the given character and marks it as ignored if it is a whitespace (ch <= ' ') or a padding character (the definition of a padding character is implementation dependent.)charappendUntil(char ch, CharInput input, char stop) Appends characters from the input, until a stop character is foundcharappendUntil(char ch, CharInput input, char stop1, char stop2) Appends characters from the input, until a stop character is foundcharappendUntil(char ch, CharInput input, char stop1, char stop2, char stop3) Appends characters from the input, until a stop character is foundfinal charcharAt(int i) voiddelete(int count) Deletes a given number of characters from the end of the appended content.voidfill(char ch, int length) Adds a sequence of repeated characters to the input.Returns the accumulated value as a String, discarding any trailing whitespace characters identified when usingappendIgnoringWhitespace(char),appendIgnoringPadding(char, char)orappendIgnoringWhitespaceAndPadding(char, char)final char[]getChars()Returns the internal character array.char[]Returns the accumulated characters, discarding any trailing whitespace characters identified when usingappendIgnoringWhitespace(char),appendIgnoringPadding(char, char)orappendIgnoringWhitespaceAndPadding(char, char)final voidignore(int count) Ignores the given number of characters at the end of the appended content, effectively marking these as whitespace.intindexOf(char[] charSequence, int fromIndex) Returns first the position of a given character sequenceintindexOf(char ch, int from) Returns first the position of a given characterintindexOf(CharSequence charSequence, int fromIndex) Returns first the position of a given character sequenceintindexOfAny(char[] chars, int from) Returns the first position of any given characterbooleanisEmpty()Indicates whether this appender represents an emptyString.intlastIndexOf(char ch) Returns the last index of a given character in the current appended (characters that have been marked as whitespace will be ignored)final intlength()Returns the current accumulated value length (the sum of all appended characters - whitespaceCount).voidprepend(char ch) Prepends the current accumulated value with a charactervoidprepend(char[] chars) Prepends the current accumulated value a sequence of charactersvoidprepend(char ch1, char ch2) Prepends the current accumulated value with a couple of charactersvoidremove(int from, int length) Removes a section from the appended contentvoidreset()Clears the accumulated value and the whitespace count.final voidResets the number of whitespaces accumulated after the last non-whitespace character.final StringsubSequence(int from, int to) substring(int from, int length) Returns a section of the appended contentfinal StringtoString()Returns the accumulated value as a String, discarding any trailing whitespace characters identified when usingappendIgnoringWhitespace(char),appendIgnoringPadding(char, char)orappendIgnoringWhitespaceAndPadding(char, char)final voidUpdates the internal whitespace count of this appender to trim trailing whitespaces.final intReturns the current number of whitespaces accumulated after the last non-whitespace character.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.CharSequence
chars, codePoints
-
Field Details
-
whitespaceRangeStart
final int whitespaceRangeStart -
emptyChars
final char[] emptyChars -
chars
char[] chars -
index
int index -
emptyValue
-
whitespaceCount
int whitespaceCount
-
-
Constructor Details
-
DefaultCharAppender
Creates a DefaultCharAppender with a maximum limit of characters to append and the default value to return when no characters have been accumulated. The padding character is defaulted to a whitespace character ' '.- Parameters:
maxLength- maximum limit of characters to appendemptyValue- default value to return when no characters have been accumulatedwhitespaceRangeStart- starting range of characters considered to be whitespace.
-
-
Method Details
-
appendIgnoringPadding
public void appendIgnoringPadding(char ch, char padding) Description copied from interface:CharAppenderAppends the given character and marks it as ignored if it is a padding character (the definition of a padding character is implementation dependent.)- Specified by:
appendIgnoringPaddingin interfaceCharAppender- Parameters:
ch- character to appendpadding- the padding character to ignore
-
appendIgnoringWhitespaceAndPadding
public void appendIgnoringWhitespaceAndPadding(char ch, char padding) Description copied from interface:CharAppenderAppends the given character and marks it as ignored if it is a whitespace (ch <= ' ') or a padding character (the definition of a padding character is implementation dependent.)- Specified by:
appendIgnoringWhitespaceAndPaddingin interfaceCharAppender- Parameters:
ch- character to appendpadding- the padding character to ignore
-
appendIgnoringWhitespace
public void appendIgnoringWhitespace(char ch) Description copied from interface:CharAppenderAppends the given character and marks it as ignored if it is a whitespace (ch <= ' ')- Specified by:
appendIgnoringWhitespacein interfaceCharAppender- Parameters:
ch- character to append
-
indexOf
public int indexOf(char ch, int from) Description copied from interface:CharAppenderReturns first the position of a given character- Specified by:
indexOfin interfaceCharAppender- Parameters:
ch- the character to look forfrom- the starting index from where the search will begin.- Returns:
- the position of the given character in the appended content,
-1if not found
-
indexOfAny
public int indexOfAny(char[] chars, int from) Description copied from interface:CharAppenderReturns the first position of any given character- Specified by:
indexOfAnyin interfaceCharAppender- Parameters:
chars- the characters to look forfrom- the starting index from where the search will begin.- Returns:
- the position any one of the given characters in the appended content,
-1if none found
-
substring
Description copied from interface:CharAppenderReturns a section of the appended content- Specified by:
substringin interfaceCharAppender- Parameters:
from- the starting position in the bufferlength- the number of characters to accumulate from the given start position- Returns:
- a
Stringwith the section of characters accumulated by this appender.
-
remove
public void remove(int from, int length) Description copied from interface:CharAppenderRemoves a section from the appended content- Specified by:
removein interfaceCharAppender- Parameters:
from- the starting position in the buffer (inclusive)length- the number of characters to accumulate from the given start position
-
append
public void append(char ch) Description copied from interface:CharAppenderAppends the given character.- Specified by:
appendin interfaceCharAppender- Parameters:
ch- the character to append
-
append
Description copied from interface:CharAppenderAppends theStringrepresentation of a given object.- Specified by:
appendin interfaceCharAppender- Parameters:
o- the object whoseStringrepresentation will be appended.
-
append
public final void append(int ch) Description copied from interface:CharAppenderAppends the given codepoint.- Specified by:
appendin interfaceCharAppender- Parameters:
ch- the codepoint to append
-
append
public final void append(int[] ch) Description copied from interface:CharAppenderAppends codepoints from an input array- Specified by:
appendin interfaceCharAppender- Parameters:
ch- the codepoint array
-
getAndReset
Returns the accumulated value as a String, discarding any trailing whitespace characters identified when usingappendIgnoringWhitespace(char),appendIgnoringPadding(char, char)orappendIgnoringWhitespaceAndPadding(char, char)The internal accumulated value is discarded after invoking this method (as in
reset())If the accumulated value is empty (i.e. no characters were appended, or all appended characters where ignored as whitespace or padding), then the return value will be
emptyValueattribute defined in the constructor of this class.- Specified by:
getAndResetin interfaceCharAppender- Returns:
- a String containing the accumulated characters without the trailing white spaces. Or the
emptyValuedefined in the constructor of this class.
-
toString
Returns the accumulated value as a String, discarding any trailing whitespace characters identified when usingappendIgnoringWhitespace(char),appendIgnoringPadding(char, char)orappendIgnoringWhitespaceAndPadding(char, char)Does not discard the accumulated value.
If the accumulated value is empty (i.e. no characters were appended, or all appended characters where ignored as whitespace or padding), then the return value will be
emptyValueattribute defined in the constructor of this class.- Specified by:
toStringin interfaceCharSequence- Overrides:
toStringin classObject- Returns:
- a String containing the accumulated characters without the trailing white spaces. Or the
emptyValuedefined in the constructor of this class.
-
length
public final int length()Description copied from interface:CharAppenderReturns the current accumulated value length (the sum of all appended characters - whitespaceCount).- Specified by:
lengthin interfaceCharAppender- Specified by:
lengthin interfaceCharSequence- Returns:
- the current accumulated value length (the sum of all appended characters - whitespaceCount).
-
getCharsAndReset
public char[] getCharsAndReset()Returns the accumulated characters, discarding any trailing whitespace characters identified when usingappendIgnoringWhitespace(char),appendIgnoringPadding(char, char)orappendIgnoringWhitespaceAndPadding(char, char)The internal accumulated value is discarded after invoking this method (as in
reset())If the accumulated value is empty (i.e. no characters were appended, or all appended characters where ignored as whitespace or padding), then the return value will be character sequence of the
emptyValueattribute defined in the constructor of this class.- Specified by:
getCharsAndResetin interfaceCharAppender- Returns:
- a character array containing the accumulated characters without the trailing white spaces. Or the characters of the
emptyValuedefined in the constructor of this class.
-
whitespaceCount
public final int whitespaceCount()Description copied from interface:CharAppenderReturns the current number of whitespaces accumulated after the last non-whitespace character.This is the number of whitespaces accumulated using
CharAppender.appendIgnoringWhitespace(char),CharAppender.appendIgnoringPadding(char, char)orCharAppender.appendIgnoringWhitespaceAndPadding(char, char)- Specified by:
whitespaceCountin interfaceCharAppender- Returns:
- the number of whitespaces accumulated using
CharAppender.appendIgnoringWhitespace(char),CharAppender.appendIgnoringPadding(char, char)orCharAppender.appendIgnoringWhitespaceAndPadding(char, char)
-
reset
public void reset()Description copied from interface:CharAppenderClears the accumulated value and the whitespace count.- Specified by:
resetin interfaceCharAppender
-
append
Appends the contents of another DefaultCharAppender, discarding any of its trailing whitespace characters- Parameters:
appender- The DefaultCharAppender instance got get contents from.
-
resetWhitespaceCount
public final void resetWhitespaceCount()Description copied from interface:CharAppenderResets the number of whitespaces accumulated after the last non-whitespace character.This is the number of whitespaces accumulated using
CharAppender.appendIgnoringWhitespace(char),CharAppender.appendIgnoringPadding(char, char)orCharAppender.appendIgnoringWhitespaceAndPadding(char, char)A subsequent call to
CharAppender.whitespaceCount()should return 0.- Specified by:
resetWhitespaceCountin interfaceCharAppender
-
getChars
public final char[] getChars()Description copied from interface:CharAppenderReturns the internal character array.- Specified by:
getCharsin interfaceCharAppender- Returns:
- the internal character array.
-
fill
public void fill(char ch, int length) Description copied from interface:CharAppenderAdds a sequence of repeated characters to the input.- Specified by:
fillin interfaceCharAppender- Parameters:
ch- the character to appendlength- the number of times the given character should be appended.
-
prepend
public void prepend(char ch) Prepends the current accumulated value with a character- Specified by:
prependin interfaceCharAppender- Parameters:
ch- the character to prepend in front of the current accumulated value.
-
prepend
public void prepend(char ch1, char ch2) Description copied from interface:CharAppenderPrepends the current accumulated value with a couple of characters- Specified by:
prependin interfaceCharAppender- Parameters:
ch1- the first character to prepend in front of the current accumulated value.ch2- the second character to prepend in front of the current accumulated value.
-
prepend
public void prepend(char[] chars) Description copied from interface:CharAppenderPrepends the current accumulated value a sequence of characters- Specified by:
prependin interfaceCharAppender- Parameters:
chars- the character sequence to prepend in front of the current accumulated value.
-
updateWhitespace
public final void updateWhitespace()Updates the internal whitespace count of this appender to trim trailing whitespaces.- Specified by:
updateWhitespacein interfaceCharAppender
-
appendUntil
Description copied from interface:CharAppenderAppends characters from the input, until a stop character is found- Specified by:
appendUntilin interfaceCharAppender- Parameters:
ch- the first character of the input to be appended.input- the input whose the following characters will be appendedstop- the stop character- Returns:
- the stop character found on the input.
-
appendUntil
Description copied from interface:CharAppenderAppends characters from the input, until a stop character is found- Specified by:
appendUntilin interfaceCharAppender- Parameters:
ch- the first character of the input to be appended.input- the input whose the following characters will be appendedstop1- the first stop characterstop2- the second stop character- Returns:
- one of the stop characters found on the input.
-
appendUntil
Description copied from interface:CharAppenderAppends characters from the input, until a stop character is found- Specified by:
appendUntilin interfaceCharAppender- Parameters:
ch- the first character of the input to be appended.input- the input whose the following characters will be appendedstop1- the first stop characterstop2- the second stop characterstop3- the third stop character- Returns:
- one of the stop characters found on the input.
-
append
public void append(char[] ch, int from, int length) Description copied from interface:CharAppenderAppends characters from an input array- Specified by:
appendin interfaceCharAppender- Parameters:
ch- the character arrayfrom- the position of the first character in the array to be appendedlength- the number of characters to be appended from the given posiion.
-
append
public final void append(char[] ch) Description copied from interface:CharAppenderAppends characters from an input array- Specified by:
appendin interfaceCharAppender- Parameters:
ch- the character array
-
append
Description copied from interface:CharAppenderAppends the contents of a String to this appender- Specified by:
appendin interfaceCharAppender- Parameters:
string- the string whose characters will be appended.from- the index of the first character to appendto- the index of the last character to append
-
append
Description copied from interface:CharAppenderAppends characters from an inputString- Specified by:
appendin interfaceCharAppender- Parameters:
string- the input String
-
charAt
public final char charAt(int i) - Specified by:
charAtin interfaceCharSequence
-
subSequence
- Specified by:
subSequencein interfaceCharSequence
-
ignore
public final void ignore(int count) Description copied from interface:CharAppenderIgnores the given number of characters at the end of the appended content, effectively marking these as whitespace. InvokingCharAppender.resetWhitespaceCount()orCharAppender.updateWhitespace()will undo this effect.- Specified by:
ignorein interfaceCharAppender- Parameters:
count- the number of characters to ignore
-
delete
public void delete(int count) Description copied from interface:CharAppenderDeletes a given number of characters from the end of the appended content. Will reset the internal whitespace count if any. InvokeCharAppender.updateWhitespace()to recalculate the number of trailing whitespaces in the appended content.- Specified by:
deletein interfaceCharAppender- Parameters:
count- the number of characters to delete.
-
indexOf
public int indexOf(char[] charSequence, int fromIndex) Description copied from interface:CharAppenderReturns first the position of a given character sequence- Specified by:
indexOfin interfaceCharAppender- Parameters:
charSequence- the character sequence to look forfromIndex- the starting index from where the search will begin.- Returns:
- the position of the given character sequence in the appended content,
-1if not found
-
indexOf
Description copied from interface:CharAppenderReturns first the position of a given character sequence- Specified by:
indexOfin interfaceCharAppender- Parameters:
charSequence- the character sequence to look forfromIndex- the starting index from where the search will begin.- Returns:
- the position of the given character sequence in the appended content,
-1if not found
-
isEmpty
public boolean isEmpty()Description copied from interface:CharAppenderIndicates whether this appender represents an emptyString.- Specified by:
isEmptyin interfaceCharAppender- Specified by:
isEmptyin interfaceCharSequence- Returns:
- true calling
CharAppender.getAndReset()would returnnull, otherwisefalse.
-
lastIndexOf
public int lastIndexOf(char ch) Description copied from interface:CharAppenderReturns the last index of a given character in the current appended (characters that have been marked as whitespace will be ignored)- Specified by:
lastIndexOfin interfaceCharAppender- Parameters:
ch- the character to look for- Returns:
- the last position of the given character in the appended content, or
-1if not found.
-