public class DefaultCharAppender extends Object implements CharAppender
CharAppender
interfaceConstructor and Description |
---|
DefaultCharAppender(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.
|
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(DefaultCharAppender appender)
Appends the contents of another DefaultCharAppender, discarding any of its trailing whitespace characters
|
void |
append(int ch)
Appends the given codepoint.
|
void |
append(int[] ch)
Appends codepoints from an input array
|
void |
append(Object o)
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
|
char |
charAt(int i) |
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 fromIndex)
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 fromIndex)
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 |
subSequence(int from,
int to) |
String |
substring(int from,
int length)
Returns a section of the appended content
|
String |
toString()
Returns the accumulated value as a String, discarding any trailing whitespace characters identified when using
appendIgnoringWhitespace(char) , appendIgnoringPadding(char, char) or appendIgnoringWhitespaceAndPadding(char, char) |
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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
chars, codePoints
public DefaultCharAppender(int maxLength, String emptyValue, int whitespaceRangeStart)
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.public void appendIgnoringPadding(char ch, char padding)
CharAppender
appendIgnoringPadding
in interface CharAppender
ch
- character to appendpadding
- the padding character to ignorepublic void appendIgnoringWhitespaceAndPadding(char ch, char padding)
CharAppender
ch <= ' '
) or a padding character (the definition of a padding character is implementation dependent.)appendIgnoringWhitespaceAndPadding
in interface CharAppender
ch
- character to appendpadding
- the padding character to ignorepublic void appendIgnoringWhitespace(char ch)
CharAppender
ch <= ' '
)appendIgnoringWhitespace
in interface CharAppender
ch
- character to appendpublic int indexOf(char ch, int from)
CharAppender
indexOf
in interface CharAppender
ch
- the character to look forfrom
- the starting index from where the search will begin.-1
if not foundpublic int indexOfAny(char[] chars, int from)
CharAppender
indexOfAny
in interface CharAppender
chars
- the characters to look forfrom
- the starting index from where the search will begin.-1
if none foundpublic String substring(int from, int length)
CharAppender
substring
in interface CharAppender
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.public void remove(int from, int length)
CharAppender
remove
in interface CharAppender
from
- the starting position in the buffer (inclusive)length
- the number of characters to accumulate from the given start positionpublic void append(char ch)
CharAppender
append
in interface CharAppender
ch
- the character to appendpublic final void append(Object o)
CharAppender
String
representation of a given object.append
in interface CharAppender
o
- the object whose String
representation will be appended.public final void append(int ch)
CharAppender
append
in interface CharAppender
ch
- the codepoint to appendpublic final void append(int[] ch)
CharAppender
append
in interface CharAppender
ch
- the codepoint arraypublic String getAndReset()
appendIgnoringWhitespace(char)
, appendIgnoringPadding(char, char)
or appendIgnoringWhitespaceAndPadding(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 emptyValue
attribute defined in the constructor of this class.
getAndReset
in interface CharAppender
emptyValue
defined in the constructor of this class.public final String toString()
appendIgnoringWhitespace(char)
, appendIgnoringPadding(char, char)
or appendIgnoringWhitespaceAndPadding(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 emptyValue
attribute defined in the constructor of this class.
toString
in interface CharSequence
toString
in class Object
emptyValue
defined in the constructor of this class.public final int length()
CharAppender
length
in interface CharAppender
length
in interface CharSequence
public char[] getCharsAndReset()
appendIgnoringWhitespace(char)
, appendIgnoringPadding(char, char)
or appendIgnoringWhitespaceAndPadding(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 emptyValue
attribute defined in the constructor of this class.
getCharsAndReset
in interface CharAppender
emptyValue
defined in the constructor of this class.public final int whitespaceCount()
CharAppender
This is the number of whitespaces accumulated using CharAppender.appendIgnoringWhitespace(char)
, CharAppender.appendIgnoringPadding(char, char)
or CharAppender.appendIgnoringWhitespaceAndPadding(char, char)
whitespaceCount
in interface CharAppender
CharAppender.appendIgnoringWhitespace(char)
, CharAppender.appendIgnoringPadding(char, char)
or CharAppender.appendIgnoringWhitespaceAndPadding(char, char)
public void reset()
CharAppender
reset
in interface CharAppender
public void append(DefaultCharAppender appender)
appender
- The DefaultCharAppender instance got get contents from.public final void resetWhitespaceCount()
CharAppender
This is the number of whitespaces accumulated using CharAppender.appendIgnoringWhitespace(char)
, CharAppender.appendIgnoringPadding(char, char)
or CharAppender.appendIgnoringWhitespaceAndPadding(char, char)
A subsequent call to CharAppender.whitespaceCount()
should return 0.
resetWhitespaceCount
in interface CharAppender
public final char[] getChars()
CharAppender
getChars
in interface CharAppender
public void fill(char ch, int length)
CharAppender
fill
in interface CharAppender
ch
- the character to appendlength
- the number of times the given character should be appended.public void prepend(char ch)
prepend
in interface CharAppender
ch
- the character to prepend in front of the current accumulated value.public void prepend(char ch1, char ch2)
CharAppender
prepend
in interface CharAppender
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.public void prepend(char[] chars)
CharAppender
prepend
in interface CharAppender
chars
- the character sequence to prepend in front of the current accumulated value.public final void updateWhitespace()
updateWhitespace
in interface CharAppender
public char appendUntil(char ch, CharInput input, char stop)
CharAppender
appendUntil
in interface CharAppender
ch
- the first character of the input to be appended.input
- the input whose the following characters will be appendedstop
- the stop characterpublic char appendUntil(char ch, CharInput input, char stop1, char stop2)
CharAppender
appendUntil
in interface CharAppender
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 characterpublic char appendUntil(char ch, CharInput input, char stop1, char stop2, char stop3)
CharAppender
appendUntil
in interface CharAppender
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 characterpublic void append(char[] ch, int from, int length)
CharAppender
append
in interface CharAppender
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.public final void append(char[] ch)
CharAppender
append
in interface CharAppender
ch
- the character arraypublic void append(String string, int from, int to)
CharAppender
append
in interface CharAppender
string
- the string whose characters will be appended.from
- the index of the first character to appendto
- the index of the last character to appendpublic final void append(String string)
CharAppender
String
append
in interface CharAppender
string
- the input Stringpublic final char charAt(int i)
charAt
in interface CharSequence
public final String subSequence(int from, int to)
subSequence
in interface CharSequence
public final void ignore(int count)
CharAppender
CharAppender.resetWhitespaceCount()
or CharAppender.updateWhitespace()
will undo this effect.ignore
in interface CharAppender
count
- the number of characters to ignorepublic void delete(int count)
CharAppender
CharAppender.updateWhitespace()
to recalculate the number of trailing whitespaces in the appended content.delete
in interface CharAppender
count
- the number of characters to delete.public int indexOf(char[] charSequence, int fromIndex)
CharAppender
indexOf
in interface CharAppender
charSequence
- the character sequence to look forfromIndex
- the starting index from where the search will begin.-1
if not foundpublic int indexOf(CharSequence charSequence, int fromIndex)
CharAppender
indexOf
in interface CharAppender
charSequence
- the character sequence to look forfromIndex
- the starting index from where the search will begin.-1
if not foundpublic boolean isEmpty()
CharAppender
String
.isEmpty
in interface CharAppender
CharAppender.getAndReset()
would return null
, otherwise false
.public int lastIndexOf(char ch)
CharAppender
lastIndexOf
in interface CharAppender
ch
- the character to look for-1
if not found.Copyright © 2019 Univocity Software Pty Ltd. All rights reserved.