com.univocity.parsers.common.input
Interface CharAppender

All Known Implementing Classes:
DefaultCharAppender, NoopCharAppender, WriterCharAppender

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 <= ' '

Author:
uniVocity Software Pty Ltd - [email protected]

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

appendIgnoringWhitespace

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

Parameters:
ch - character to append

appendIgnoringPadding

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.)

Parameters:
ch - character to append

appendIgnoringWhitespaceAndPadding

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.)

Parameters:
ch - character to append

append

void append(char ch)
Appends the given character.

Parameters:
ch - the character to append

length

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

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

whitespaceCount

int whitespaceCount()
Returns the current number of whitespaces accumulated after the last non-whitespace character.

This is the number of whitespaces accumulated using appendIgnoringWhitespace(char), appendIgnoringPadding(char) or appendIgnoringWhitespaceAndPadding(char)

Returns:
the number of whitespaces accumulated using appendIgnoringWhitespace(char), appendIgnoringPadding(char) or appendIgnoringWhitespaceAndPadding(char)

resetWhitespaceCount

void resetWhitespaceCount()
Resets the number of whitespaces accumulated after the last non-whitespace character.

This is the number of whitespaces accumulated using appendIgnoringWhitespace(char), appendIgnoringPadding(char) or appendIgnoringWhitespaceAndPadding(char)

A subsequent call to whitespaceCount() should return 0.


getAndReset

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

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

Returns:
a String containing the accumulated characters without the trailing whitespaces.

reset

void reset()
Clears the accumulated value and the whitespace count.


getCharsAndReset

char[] getCharsAndReset()
Returns the accumulated characters, discarding any trailing whitespace characters identified when using appendIgnoringWhitespace(char), appendIgnoringPadding(char) or appendIgnoringWhitespaceAndPadding(char)

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

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


Copyright © 2014 uniVocity Software Pty Ltd. All rights reserved.