Class DefaultCharAppender
- java.lang.Object
-
- com.univocity.parsers.common.input.DefaultCharAppender
-
- All Implemented Interfaces:
CharAppender
,java.lang.CharSequence
- Direct Known Subclasses:
ExpandingCharAppender
public class DefaultCharAppender extends java.lang.Object implements CharAppender
Default implementation of theCharAppender
interface
-
-
Constructor Summary
Constructors Constructor Description DefaultCharAppender(int maxLength, java.lang.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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
append(char ch)
Appends the given character.void
append(char[] ch)
Appends characters from an input arrayvoid
append(char[] ch, int from, int length)
Appends characters from an input arrayvoid
append(int ch)
Appends the given codepoint.void
append(int[] ch)
Appends codepoints from an input arrayvoid
append(DefaultCharAppender appender)
Appends the contents of another DefaultCharAppender, discarding any of its trailing whitespace charactersvoid
append(java.lang.String string)
Appends characters from an inputString
void
append(java.lang.String string, int from, int to)
Appends the contents of a String to this appendervoid
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 foundchar
appendUntil(char ch, CharInput input, char stop1, char stop2)
Appends characters from the input, until a stop character is foundchar
appendUntil(char ch, CharInput input, char stop1, char stop2, char stop3)
Appends characters from the input, until a stop character is foundchar
charAt(int i)
void
fill(char ch, int length)
Adds a sequence of repeated characters to the input.java.lang.String
getAndReset()
Returns the accumulated value as a String, discarding any trailing whitespace characters identified when usingappendIgnoringWhitespace(char)
,appendIgnoringPadding(char, char)
orappendIgnoringWhitespaceAndPadding(char, char)
char[]
getChars()
Returns the internal character array.char[]
getCharsAndReset()
Returns the accumulated characters, discarding any trailing whitespace characters identified when usingappendIgnoringWhitespace(char)
,appendIgnoringPadding(char, char)
orappendIgnoringWhitespaceAndPadding(char, char)
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 charactervoid
prepend(char[] chars)
Prepends the current accumulated value a sequence of charactersvoid
prepend(char ch1, char ch2)
Prepends the current accumulated value with a couple of charactersvoid
reset()
Clears the accumulated value and the whitespace count.void
resetWhitespaceCount()
Resets the number of whitespaces accumulated after the last non-whitespace character.java.lang.String
subSequence(int from, int to)
java.lang.String
toString()
Returns the accumulated value as a String, discarding any trailing whitespace characters identified when usingappendIgnoringWhitespace(char)
,appendIgnoringPadding(char, char)
orappendIgnoringWhitespaceAndPadding(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.
-
-
-
Constructor Detail
-
DefaultCharAppender
public DefaultCharAppender(int maxLength, java.lang.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. 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 Detail
-
appendIgnoringPadding
public void appendIgnoringPadding(char ch, char padding)
Description copied from interface:CharAppender
Appends 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:
appendIgnoringPadding
in interfaceCharAppender
- Parameters:
ch
- character to appendpadding
- the padding character to ignore
-
appendIgnoringWhitespaceAndPadding
public void appendIgnoringWhitespaceAndPadding(char ch, char padding)
Description copied from interface:CharAppender
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.)- Specified by:
appendIgnoringWhitespaceAndPadding
in interfaceCharAppender
- Parameters:
ch
- character to appendpadding
- the padding character to ignore
-
appendIgnoringWhitespace
public void appendIgnoringWhitespace(char ch)
Description copied from interface:CharAppender
Appends the given character and marks it as ignored if it is a whitespace (ch <= ' '
)- Specified by:
appendIgnoringWhitespace
in interfaceCharAppender
- Parameters:
ch
- character to append
-
append
public void append(char ch)
Description copied from interface:CharAppender
Appends the given character.- Specified by:
append
in interfaceCharAppender
- Parameters:
ch
- the character to append
-
append
public final void append(int ch)
Description copied from interface:CharAppender
Appends the given codepoint.- Specified by:
append
in interfaceCharAppender
- Parameters:
ch
- the codepoint to append
-
append
public final void append(int[] ch)
Description copied from interface:CharAppender
Appends codepoints from an input array- Specified by:
append
in interfaceCharAppender
- Parameters:
ch
- the codepoint array
-
getAndReset
public java.lang.String 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
emptyValue
attribute defined in the constructor of this class.- Specified by:
getAndReset
in interfaceCharAppender
- Returns:
- a String containing the accumulated characters without the trailing white spaces. Or the
emptyValue
defined in the constructor of this class.
-
toString
public final java.lang.String 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
emptyValue
attribute defined in the constructor of this class.- Specified by:
toString
in interfacejava.lang.CharSequence
- Overrides:
toString
in classjava.lang.Object
- Returns:
- a String containing the accumulated characters without the trailing white spaces. Or the
emptyValue
defined in the constructor of this class.
-
length
public final int length()
Description copied from interface:CharAppender
Returns the current accumulated value length (the sum of all appended characters - whitespaceCount).- Specified by:
length
in interfaceCharAppender
- Specified by:
length
in interfacejava.lang.CharSequence
- 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
emptyValue
attribute defined in the constructor of this class.- Specified by:
getCharsAndReset
in interfaceCharAppender
- Returns:
- a character array containing the accumulated characters without the trailing white spaces. Or the characters of the
emptyValue
defined in the constructor of this class.
-
whitespaceCount
public final int whitespaceCount()
Description copied from interface:CharAppender
Returns 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:
whitespaceCount
in 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:CharAppender
Clears the accumulated value and the whitespace count.- Specified by:
reset
in interfaceCharAppender
-
append
public void append(DefaultCharAppender appender)
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:CharAppender
Resets 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:
resetWhitespaceCount
in interfaceCharAppender
-
getChars
public final char[] getChars()
Description copied from interface:CharAppender
Returns the internal character array.- Specified by:
getChars
in interfaceCharAppender
- Returns:
- the internal character array.
-
fill
public void fill(char ch, int length)
Description copied from interface:CharAppender
Adds a sequence of repeated characters to the input.- Specified by:
fill
in 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:
prepend
in 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:CharAppender
Prepends the current accumulated value with a couple of characters- Specified by:
prepend
in 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:CharAppender
Prepends the current accumulated value a sequence of characters- Specified by:
prepend
in 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:
updateWhitespace
in interfaceCharAppender
-
appendUntil
public char appendUntil(char ch, CharInput input, char stop)
Description copied from interface:CharAppender
Appends characters from the input, until a stop character is found- Specified by:
appendUntil
in 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
public char appendUntil(char ch, CharInput input, char stop1, char stop2)
Description copied from interface:CharAppender
Appends characters from the input, until a stop character is found- Specified by:
appendUntil
in 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
public char appendUntil(char ch, CharInput input, char stop1, char stop2, char stop3)
Description copied from interface:CharAppender
Appends characters from the input, until a stop character is found- Specified by:
appendUntil
in 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:CharAppender
Appends characters from an input array- Specified by:
append
in 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:CharAppender
Appends characters from an input array- Specified by:
append
in interfaceCharAppender
- Parameters:
ch
- the character array
-
append
public void append(java.lang.String string, int from, int to)
Description copied from interface:CharAppender
Appends the contents of a String to this appender- Specified by:
append
in 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
public final void append(java.lang.String string)
Description copied from interface:CharAppender
Appends characters from an inputString
- Specified by:
append
in interfaceCharAppender
- Parameters:
string
- the input String
-
charAt
public final char charAt(int i)
- Specified by:
charAt
in interfacejava.lang.CharSequence
-
subSequence
public final java.lang.String subSequence(int from, int to)
- Specified by:
subSequence
in interfacejava.lang.CharSequence
-
-