public interface CharAppender extends CharSequence
Calls to appendIgnoringWhitespace(char), appendIgnoringPadding(char, char) and appendIgnoringWhitespaceAndPadding(char, char) should accumulate the
given character and only discard whitespaces/padding if no non-whitespace is appended:
For example:
append('a'); // accumulated value is now "a"; whitespaceCount = 0;
appendIgnoringWhitespace('b'); // accumulated value is now "ab"; whitespaceCount = 0;
appendIgnoringWhitespace(' '); // accumulated value remains "ab"; whitespaceCount = 1;
appendIgnoringWhitespace(' '); // accumulated value remains "ab"; whitespaceCount = 2;
appendIgnoringWhitespace('c'); // accumulated value is now "ab c"; whitespaceCount = 0;
appendIgnoringWhitespace(' '); // accumulated value remains "ab c"; whitespaceCount = 1;
appendIgnoringWhitespace('d'); // accumulated value is now "ab c d"; whitespaceCount = 0;
append(' '); // accumulated value is now "ab c d "; whitespaceCount = 0;
Implementation note: White spaces should be identified as any character <= ' '
| Modifier and Type | Method and Description |
|---|---|
void |
append(char ch)
Appends the given character.
|
void |
append(char[] ch)
Appends characters from an input array
|
void |
append(char[] ch,
int from,
int length)
Appends characters from an input array
|
void |
append(int ch)
Appends the given codepoint.
|
void |
append(int[] ch)
Appends codepoints from an input array
|
void |
append(Object obj)
Appends the
String representation of a given object. |
void |
append(String string)
Appends characters from an input
String |
void |
append(String string,
int from,
int to)
Appends the contents of a String to this appender
|
void |
appendIgnoringPadding(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.)
|
void |
appendIgnoringWhitespace(char ch)
Appends the given character and marks it as ignored if it is a whitespace (
ch <= ' ') |
void |
appendIgnoringWhitespaceAndPadding(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.) |
char |
appendUntil(char ch,
CharInput input,
char stop)
Appends characters from the input, until a stop character is found
|
char |
appendUntil(char ch,
CharInput input,
char stop1,
char stop2)
Appends characters from the input, until a stop character is found
|
char |
appendUntil(char ch,
CharInput input,
char stop1,
char stop2,
char stop3)
Appends characters from the input, until a stop character is found
|
void |
delete(int count)
Deletes a given number of characters from the end of the appended content.
|
void |
fill(char ch,
int length)
Adds a sequence of repeated characters to the input.
|
String |
getAndReset()
Returns the accumulated value as a String, discarding any trailing whitespace characters identified when using
appendIgnoringWhitespace(char), appendIgnoringPadding(char, char) or appendIgnoringWhitespaceAndPadding(char, char) |
char[] |
getChars()
Returns the internal character array.
|
char[] |
getCharsAndReset()
Returns the accumulated characters, discarding any trailing whitespace characters identified when using
appendIgnoringWhitespace(char), appendIgnoringPadding(char, char) or appendIgnoringWhitespaceAndPadding(char, char) |
void |
ignore(int count)
Ignores the given number of characters at the end of the appended content,
effectively marking these as whitespace.
|
int |
indexOf(char[] charSequence,
int from)
Returns first the position of a given character sequence
|
int |
indexOf(char ch,
int from)
Returns first the position of a given character
|
int |
indexOf(CharSequence charSequence,
int from)
Returns first the position of a given character sequence
|
int |
indexOfAny(char[] chars,
int from)
Returns the first position of any given character
|
boolean |
isEmpty()
Indicates whether this appender represents an empty
String. |
int |
lastIndexOf(char ch)
Returns the last index of a given character in the current appended (characters that have been marked as whitespace will be ignored)
|
int |
length()
Returns the current accumulated value length (the sum of all appended characters - whitespaceCount).
|
void |
prepend(char ch)
Prepends the current accumulated value with a character
|
void |
prepend(char[] chars)
Prepends the current accumulated value a sequence of characters
|
void |
prepend(char ch1,
char ch2)
Prepends the current accumulated value with a couple of characters
|
void |
remove(int from,
int length)
Removes a section from the appended content
|
void |
reset()
Clears the accumulated value and the whitespace count.
|
void |
resetWhitespaceCount()
Resets the number of whitespaces accumulated after the last non-whitespace character.
|
String |
substring(int from,
int length)
Returns a section of the appended content
|
void |
updateWhitespace()
Updates the internal whitespace count of this appender to trim trailing whitespaces.
|
int |
whitespaceCount()
Returns the current number of whitespaces accumulated after the last non-whitespace character.
|
charAt, chars, codePoints, subSequence, toStringvoid appendIgnoringWhitespace(char ch)
ch <= ' ')ch - character to appendvoid appendIgnoringPadding(char ch,
char padding)
ch - character to appendpadding - the padding character to ignorevoid appendIgnoringWhitespaceAndPadding(char ch,
char padding)
ch <= ' ') or a padding character (the definition of a padding character is implementation dependent.)ch - character to appendpadding - the padding character to ignorevoid append(char ch)
ch - the character to appendint indexOf(char ch,
int from)
ch - the character to look forfrom - the starting index from where the search will begin.-1 if not foundint indexOf(char[] charSequence,
int from)
charSequence - the character sequence to look forfrom - the starting index from where the search will begin.-1 if not foundint indexOf(CharSequence charSequence, int from)
charSequence - the character sequence to look forfrom - the starting index from where the search will begin.-1 if not foundint indexOfAny(char[] chars,
int from)
chars - the characters to look forfrom - the starting index from where the search will begin.-1 if none foundString substring(int from, int length)
from - the starting position in the bufferlength - the number of characters to accumulate from the given start positionString with the section of characters accumulated by this appender.void remove(int from,
int length)
from - the starting position in the buffer (inclusive)length - the number of characters to accumulate from the given start positionvoid append(int ch)
ch - the codepoint to appendvoid append(Object obj)
String representation of a given object.obj - the object whose String representation will be appended.int length()
length in interface CharSequenceint whitespaceCount()
This is the number of whitespaces accumulated using appendIgnoringWhitespace(char), appendIgnoringPadding(char, char) or appendIgnoringWhitespaceAndPadding(char, char)
appendIgnoringWhitespace(char), appendIgnoringPadding(char, char) or appendIgnoringWhitespaceAndPadding(char, char)void resetWhitespaceCount()
This is the number of whitespaces accumulated using appendIgnoringWhitespace(char), appendIgnoringPadding(char, char) or appendIgnoringWhitespaceAndPadding(char, char)
A subsequent call to whitespaceCount() should return 0.
String getAndReset()
appendIgnoringWhitespace(char), appendIgnoringPadding(char, char) or appendIgnoringWhitespaceAndPadding(char, char)
The internal accumulated value is discarded after invoking this method (as in reset())
void reset()
char[] getCharsAndReset()
appendIgnoringWhitespace(char), appendIgnoringPadding(char, char) or appendIgnoringWhitespaceAndPadding(char, char)
The internal accumulated value is discarded after invoking this method (as in reset())
char[] getChars()
void fill(char ch,
int length)
ch - the character to appendlength - the number of times the given character should be appended.void prepend(char ch)
ch - the character to prepend in front of the current accumulated value.void prepend(char ch1,
char ch2)
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.void prepend(char[] chars)
chars - the character sequence to prepend in front of the current accumulated value.void updateWhitespace()
char appendUntil(char ch,
CharInput input,
char stop)
ch - the first character of the input to be appended.input - the input whose the following characters will be appendedstop - the stop characterchar appendUntil(char ch,
CharInput input,
char stop1,
char stop2)
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 characterchar appendUntil(char ch,
CharInput input,
char stop1,
char stop2,
char stop3)
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 charactervoid append(char[] ch,
int from,
int length)
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.void append(char[] ch)
ch - the character arrayvoid append(int[] ch)
ch - the codepoint arrayvoid append(String string)
Stringstring - the input Stringvoid append(String string, int from, int to)
string - the string whose characters will be appended.from - the index of the first character to appendto - the index of the last character to appendvoid ignore(int count)
resetWhitespaceCount()
or updateWhitespace() will undo this effect.count - the number of characters to ignorevoid delete(int count)
updateWhitespace()
to recalculate the number of trailing whitespaces in the appended content.count - the number of characters to delete.boolean isEmpty()
String.getAndReset() would return null, otherwise false.int lastIndexOf(char ch)
ch - the character to look for-1 if not found.Copyright © 2019 Univocity Software Pty Ltd. All rights reserved.