Top Description Methods
com.univocity.parsers.common.input

public Interface CharAppender

extends CharSequence
Known Direct Implementers
com.univocity.parsers.common.input.DefaultCharAppender, com.univocity.parsers.common.input.NoopCharAppender

The general interface for classes responsible for appending characters efficiently while handling whitespaces and padding characters.

Calls to CharAppender#appendIgnoringWhitespace(char), CharAppender#appendIgnoringPadding(char, char) and CharAppender#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 <= ' '

Author
Univocity Software Pty Ltd - [email protected]

Method Summary

Modifier and TypeMethod and Description
public void
append(char
the character to append
ch
)

Appends the given character.

public void
append(int
the codepoint to append
ch
)

Appends the given codepoint.

public void
append(Object
the object whose String representation will be appended.
obj
)

Appends the String representation of a given object.

public void
append(char[]
the character array
ch
,
int
the position of the first character in the array to be appended
from
,
int
the number of characters to be appended from the given posiion.
length
)

Appends characters from an input array

public void
append(char[]
the character array
ch
)

Appends characters from an input array

public void
append(int[]
the codepoint array
ch
)

Appends codepoints from an input array

public void
append(String
the input String
string
)

Appends characters from an input String

public void
append(String
the string whose characters will be appended.
string
,
int
the index of the first character to append
from
,
int
the index of the last character to append
to
)

Appends the contents of a String to this appender

public void
appendIgnoringPadding(char
character to append
ch
,
char
the padding character to ignore
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.)

public void
appendIgnoringWhitespace(char
character to append
ch
)

Appends the given character and marks it as ignored if it is a whitespace (ch <= ' ')

public void
appendIgnoringWhitespaceAndPadding(char
character to append
ch
,
char
the padding character to ignore
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.)

public char

Returns:

the stop character found on the input.
appendUntil
(char
the first character of the input to be appended.
ch
,
CharInput
the input whose the following characters will be appended
input
,
char
the stop character
stop
)

Appends characters from the input, until a stop character is found

public char

Returns:

one of the stop characters found on the input.
appendUntil
(char
the first character of the input to be appended.
ch
,
CharInput
the input whose the following characters will be appended
input
,
char
the first stop character
stop1
,
char
the second stop character
stop2
)

Appends characters from the input, until a stop character is found

public char

Returns:

one of the stop characters found on the input.
appendUntil
(char
the first character of the input to be appended.
ch
,
CharInput
the input whose the following characters will be appended
input
,
char
the first stop character
stop1
,
char
the second stop character
stop2
,
char
the third stop character
stop3
)

Appends characters from the input, until a stop character is found

public void
delete(int
the number of characters to delete.
count
)

Deletes a given number of characters from the end of the appended content.

public void
fill(char
the character to append
ch
,
int
the number of times the given character should be appended.
length
)

Adds a sequence of repeated characters to the input.

public String

Returns:

a String containing the accumulated characters without the trailing whitespaces.
getAndReset
()

Returns the accumulated value as a String, discarding any trailing whitespace characters identified when using CharAppender#appendIgnoringWhitespace(char), CharAppender#appendIgnoringPadding(char, char) or CharAppender#appendIgnoringWhitespaceAndPadding(char, char)

The internal accumulated value is discarded after invoking this method (as in CharAppender#reset())

public char[]

Returns:

the internal character array.
getChars
()

Returns the internal character array.

public char[]

Returns:

a character array containing the accumulated characters without the trailing whitespaces.
getCharsAndReset
()

Returns the accumulated characters, discarding any trailing whitespace characters identified when using CharAppender#appendIgnoringWhitespace(char), CharAppender#appendIgnoringPadding(char, char) or CharAppender#appendIgnoringWhitespaceAndPadding(char, char)

The internal accumulated value is discarded after invoking this method (as in CharAppender#reset())

public void
ignore(int
the number of characters to ignore
count
)

Ignores the given number of characters at the end of the appended content, effectively marking these as whitespace.

public int

Returns:

the position of the given character in the appended content, -1 if not found
indexOf
(char
the character to look for
ch
,
int
the starting index from where the search will begin.
from
)

Returns first the position of a given character

public int

Returns:

the position of the given character sequence in the appended content, -1 if not found
indexOf
(char[]
the character sequence to look for
charSequence
,
int
the starting index from where the search will begin.
from
)

Returns first the position of a given character sequence

public int

Returns:

the position of the given character sequence in the appended content, -1 if not found
indexOf
(CharSequence
the character sequence to look for
charSequence
,
int
the starting index from where the search will begin.
from
)

Returns first the position of a given character sequence

public int

Returns:

the position any one of the given characters in the appended content, -1 if none found
indexOfAny
(char[]
the characters to look for
chars
,
int
the starting index from where the search will begin.
from
)

Returns the first position of any given character

public boolean

Returns:

true calling getAndReset() would return null, otherwise false.
isEmpty
()

Redeclares as abstract: java.lang.CharSequence.isEmpty.

Indicates whether this appender represents an empty String.
public int

Returns:

the last position of the given character in the appended content, or -1 if not found.
lastIndexOf
(char
the character to look for
ch
)

Returns the last index of a given character in the current appended (characters that have been marked as whitespace will be ignored)

public int

Returns:

the current accumulated value length (the sum of all appended characters - whitespaceCount).
length
()

Redeclares java.lang.CharSequence.length.

Returns the current accumulated value length (the sum of all appended characters - whitespaceCount).
public void
prepend(char
the character to prepend in front of the current accumulated value.
ch
)

Prepends the current accumulated value with a character

public void
prepend(char
the first character to prepend in front of the current accumulated value.
ch1
,
char
the second character to prepend in front of the current accumulated value.
ch2
)

Prepends the current accumulated value with a couple of characters

public void
prepend(char[]
the character sequence to prepend in front of the current accumulated value.
chars
)

Prepends the current accumulated value a sequence of characters

public void
remove(int
the starting position in the buffer (inclusive)
from
,
int
the number of characters to accumulate from the given start position
length
)

Removes a section from the appended content

public void
reset()

Clears the accumulated value and the whitespace count.

public void
resetWhitespaceCount()

Resets the number of whitespaces accumulated after the last non-whitespace character.

public String

Returns:

a String with the section of characters accumulated by this appender.
substring
(int
the starting position in the buffer
from
,
int
the number of characters to accumulate from the given start position
length
)

Returns a section of the appended content

public void
updateWhitespace()

Updates the internal whitespace count of this appender to trim trailing whitespaces.

public int
whitespaceCount()

Returns the current number of whitespaces accumulated after the last non-whitespace character.

Inherited from java.lang.CharSequence:
charAtcharscodePointscomparesubSequencetoString

Method Detail

appendback to summary
public void append(char ch)

Appends the given character.

Parameters
ch:char

the character to append

appendback to summary
public void append(int ch)

Appends the given codepoint.

Parameters
ch:int

the codepoint to append

appendback to summary
public void append(Object obj)

Appends the String representation of a given object.

Parameters
obj:Object

the object whose String representation will be appended.

appendback to summary
public void append(char[] ch, int from, int length)

Appends characters from an input array

Parameters
ch:char[]

the character array

from:int

the position of the first character in the array to be appended

length:int

the number of characters to be appended from the given posiion.

appendback to summary
public void append(char[] ch)

Appends characters from an input array

Parameters
ch:char[]

the character array

appendback to summary
public void append(int[] ch)

Appends codepoints from an input array

Parameters
ch:int[]

the codepoint array

appendback to summary
public void append(String string)

Appends characters from an input String

Parameters
string:String

the input String

appendback to summary
public void append(String string, int from, int to)

Appends the contents of a String to this appender

Parameters
string:String

the string whose characters will be appended.

from:int

the index of the first character to append

to:int

the index of the last character to append

appendIgnoringPaddingback to summary
public 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.)

Parameters
ch:char

character to append

padding:char

the padding character to ignore

appendIgnoringWhitespaceback to summary
public void appendIgnoringWhitespace(char ch)

Appends the given character and marks it as ignored if it is a whitespace (ch <= ' ')

Parameters
ch:char

character to append

appendIgnoringWhitespaceAndPaddingback to summary
public 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.)

Parameters
ch:char

character to append

padding:char

the padding character to ignore

appendUntilback to summary
public char appendUntil(char ch, CharInput input, char stop)

Appends characters from the input, until a stop character is found

Parameters
ch:char

the first character of the input to be appended.

input:CharInput

the input whose the following characters will be appended

stop:char

the stop character

Returns:char

the stop character found on the input.

appendUntilback to summary
public char appendUntil(char ch, CharInput input, char stop1, char stop2)

Appends characters from the input, until a stop character is found

Parameters
ch:char

the first character of the input to be appended.

input:CharInput

the input whose the following characters will be appended

stop1:char

the first stop character

stop2:char

the second stop character

Returns:char

one of the stop characters found on the input.

appendUntilback to summary
public char appendUntil(char ch, CharInput input, char stop1, char stop2, char stop3)

Appends characters from the input, until a stop character is found

Parameters
ch:char

the first character of the input to be appended.

input:CharInput

the input whose the following characters will be appended

stop1:char

the first stop character

stop2:char

the second stop character

stop3:char

the third stop character

Returns:char

one of the stop characters found on the input.

deleteback to summary
public void delete(int count)

Deletes a given number of characters from the end of the appended content. Will reset the internal whitespace count if any. Invoke updateWhitespace() to recalculate the number of trailing whitespaces in the appended content.

Parameters
count:int

the number of characters to delete.

fillback to summary
public void fill(char ch, int length)

Adds a sequence of repeated characters to the input.

Parameters
ch:char

the character to append

length:int

the number of times the given character should be appended.

getAndResetback to summary
public String getAndReset()

Returns the accumulated value as a String, discarding any trailing whitespace characters identified when using CharAppender#appendIgnoringWhitespace(char), CharAppender#appendIgnoringPadding(char, char) or CharAppender#appendIgnoringWhitespaceAndPadding(char, char)

The internal accumulated value is discarded after invoking this method (as in CharAppender#reset())

Returns:String

a String containing the accumulated characters without the trailing whitespaces.

getCharsback to summary
public char[] getChars()

Returns the internal character array.

Returns:char[]

the internal character array.

getCharsAndResetback to summary
public char[] getCharsAndReset()

Returns the accumulated characters, discarding any trailing whitespace characters identified when using CharAppender#appendIgnoringWhitespace(char), CharAppender#appendIgnoringPadding(char, char) or CharAppender#appendIgnoringWhitespaceAndPadding(char, char)

The internal accumulated value is discarded after invoking this method (as in CharAppender#reset())

Returns:char[]

a character array containing the accumulated characters without the trailing whitespaces.

ignoreback to summary
public void ignore(int count)

Ignores the given number of characters at the end of the appended content, effectively marking these as whitespace. Invoking resetWhitespaceCount() or updateWhitespace() will undo this effect.

Parameters
count:int

the number of characters to ignore

indexOfback to summary
public int indexOf(char ch, int from)

Returns first the position of a given character

Parameters
ch:char

the character to look for

from:int

the starting index from where the search will begin.

Returns:int

the position of the given character in the appended content, -1 if not found

indexOfback to summary
public int indexOf(char[] charSequence, int from)

Returns first the position of a given character sequence

Parameters
charSequence:char[]

the character sequence to look for

from:int

the starting index from where the search will begin.

Returns:int

the position of the given character sequence in the appended content, -1 if not found

indexOfback to summary
public int indexOf(CharSequence charSequence, int from)

Returns first the position of a given character sequence

Parameters
charSequence:CharSequence

the character sequence to look for

from:int

the starting index from where the search will begin.

Returns:int

the position of the given character sequence in the appended content, -1 if not found

indexOfAnyback to summary
public int indexOfAny(char[] chars, int from)

Returns the first position of any given character

Parameters
chars:char[]

the characters to look for

from:int

the starting index from where the search will begin.

Returns:int

the position any one of the given characters in the appended content, -1 if none found

isEmptyback to summary
public boolean isEmpty()

Redeclares as abstract: java.lang.CharSequence.isEmpty.

Indicates whether this appender represents an empty String.

Returns:boolean

true calling getAndReset() would return null, otherwise false.

lastIndexOfback to summary
public 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)

Parameters
ch:char

the character to look for

Returns:int

the last position of the given character in the appended content, or -1 if not found.

lengthback to summary
public int length()

Redeclares java.lang.CharSequence.length.

Returns the current accumulated value length (the sum of all appended characters - whitespaceCount).

Returns:int

the current accumulated value length (the sum of all appended characters - whitespaceCount).

prependback to summary
public void prepend(char ch)

Prepends the current accumulated value with a character

Parameters
ch:char

the character to prepend in front of the current accumulated value.

prependback to summary
public void prepend(char ch1, char ch2)

Prepends the current accumulated value with a couple of characters

Parameters
ch1:char

the first character to prepend in front of the current accumulated value.

ch2:char

the second character to prepend in front of the current accumulated value.

prependback to summary
public void prepend(char[] chars)

Prepends the current accumulated value a sequence of characters

Parameters
chars:char[]

the character sequence to prepend in front of the current accumulated value.

removeback to summary
public void remove(int from, int length)

Removes a section from the appended content

Parameters
from:int

the starting position in the buffer (inclusive)

length:int

the number of characters to accumulate from the given start position

resetback to summary
public void reset()

Clears the accumulated value and the whitespace count.

resetWhitespaceCountback to summary
public void resetWhitespaceCount()

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) or CharAppender#appendIgnoringWhitespaceAndPadding(char, char)

A subsequent call to CharAppender#whitespaceCount() should return 0.

substringback to summary
public String substring(int from, int length)

Returns a section of the appended content

Parameters
from:int

the starting position in the buffer

length:int

the number of characters to accumulate from the given start position

Returns:String

a String with the section of characters accumulated by this appender.

updateWhitespaceback to summary
public void updateWhitespace()

Updates the internal whitespace count of this appender to trim trailing whitespaces.

whitespaceCountback to summary
public int whitespaceCount()

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) or CharAppender#appendIgnoringWhitespaceAndPadding(char, char)

Returns:int

the number of whitespaces accumulated using CharAppender#appendIgnoringWhitespace(char), CharAppender#appendIgnoringPadding(char, char) or CharAppender#appendIgnoringWhitespaceAndPadding(char, char)