|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface CharAppender
The general interface for classes responsible for appending characters efficiently while handling whitespaces and padding characters.
Calls to appendIgnoringWhitespace(char)
, appendIgnoringPadding(char)
and appendIgnoringWhitespaceAndPadding(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 <= ' '
Method Summary | |
---|---|
void |
append(char ch)
Appends the given character. |
void |
appendIgnoringPadding(char ch)
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)
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.) |
String |
getAndReset()
Returns the accumulated value as a String, discarding any trailing whitespace characters identified when using appendIgnoringWhitespace(char) , appendIgnoringPadding(char) or appendIgnoringWhitespaceAndPadding(char) |
char[] |
getCharsAndReset()
Returns the accumulated characters, discarding any trailing whitespace characters identified when using appendIgnoringWhitespace(char) , appendIgnoringPadding(char) or appendIgnoringWhitespaceAndPadding(char) |
int |
length()
Returns the current accumulated value length (the sum of all appended characters - whitespaceCount). |
void |
reset()
Clears the accumulated value and the whitespace count. |
void |
resetWhitespaceCount()
Resets the number of whitespaces accumulated after the last non-whitespace character. |
int |
whitespaceCount()
Returns the current number of whitespaces accumulated after the last non-whitespace character. |
Method Detail |
---|
void appendIgnoringWhitespace(char ch)
ch
- character to appendvoid appendIgnoringPadding(char ch)
ch
- character to appendvoid appendIgnoringWhitespaceAndPadding(char ch)
ch
- character to appendvoid append(char ch)
ch
- the character to appendint length()
int whitespaceCount()
This is the number of whitespaces accumulated using appendIgnoringWhitespace(char)
, appendIgnoringPadding(char)
or appendIgnoringWhitespaceAndPadding(char)
appendIgnoringWhitespace(char)
, appendIgnoringPadding(char)
or appendIgnoringWhitespaceAndPadding(char)
void resetWhitespaceCount()
This is the number of whitespaces accumulated using appendIgnoringWhitespace(char)
, appendIgnoringPadding(char)
or appendIgnoringWhitespaceAndPadding(char)
A subsequent call to whitespaceCount()
should return 0.
String getAndReset()
appendIgnoringWhitespace(char)
, appendIgnoringPadding(char)
or appendIgnoringWhitespaceAndPadding(char)
The internal accumulated value is discarded after invoking this method (as in reset()
)
void reset()
char[] getCharsAndReset()
appendIgnoringWhitespace(char)
, appendIgnoringPadding(char)
or appendIgnoringWhitespaceAndPadding(char)
The internal accumulated value is discarded after invoking this method (as in reset()
)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |