Class DefaultCharAppender

java.lang.Object
com.univocity.parsers.common.input.DefaultCharAppender
All Implemented Interfaces:
CharAppender, CharSequence
Direct Known Subclasses:
ExpandingCharAppender

public class DefaultCharAppender extends Object implements CharAppender
Default implementation of the CharAppender interface
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) char[]
     
    (package private) final char[]
     
    (package private) final String
     
    (package private) int
     
    (package private) int
     
    (package private) final int
     
  • Constructor Summary

    Constructors
    Constructor
    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.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    append(char ch)
    Appends the given character.
    final void
    append(char[] ch)
    Appends characters from an input array
    void
    append(char[] ch, int from, int length)
    Appends characters from an input array
    final void
    append(int ch)
    Appends the given codepoint.
    final void
    append(int[] ch)
    Appends codepoints from an input array
    void
    Appends the contents of another DefaultCharAppender, discarding any of its trailing whitespace characters
    final void
    Appends the String representation of a given object.
    final 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
    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
    final 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.
    Returns the accumulated value as a String, discarding any trailing whitespace characters identified when using appendIgnoringWhitespace(char), appendIgnoringPadding(char, char) or appendIgnoringWhitespaceAndPadding(char, char)
    final char[]
    Returns the internal character array.
    char[]
    Returns the accumulated characters, discarding any trailing whitespace characters identified when using appendIgnoringWhitespace(char), appendIgnoringPadding(char, char) or appendIgnoringWhitespaceAndPadding(char, char)
    final 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
    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)
    final int
    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
    Clears the accumulated value and the whitespace count.
    final void
    Resets the number of whitespaces accumulated after the last non-whitespace character.
    final String
    subSequence(int from, int to)
     
    substring(int from, int length)
    Returns a section of the appended content
    final String
    Returns the accumulated value as a String, discarding any trailing whitespace characters identified when using appendIgnoringWhitespace(char), appendIgnoringPadding(char, char) or appendIgnoringWhitespaceAndPadding(char, char)
    final void
    Updates the internal whitespace count of this appender to trim trailing whitespaces.
    final int
    Returns the current number of whitespaces accumulated after the last non-whitespace character.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.lang.CharSequence

    chars, codePoints
  • Field Details

    • whitespaceRangeStart

      final int whitespaceRangeStart
    • emptyChars

      final char[] emptyChars
    • chars

      char[] chars
    • index

      int index
    • emptyValue

      final String emptyValue
    • whitespaceCount

      int whitespaceCount
  • Constructor Details

    • DefaultCharAppender

      public 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. The padding character is defaulted to a whitespace character ' '.
      Parameters:
      maxLength - maximum limit of characters to append
      emptyValue - default value to return when no characters have been accumulated
      whitespaceRangeStart - starting range of characters considered to be whitespace.
  • Method Details

    • 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 interface CharAppender
      Parameters:
      ch - character to append
      padding - 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 interface CharAppender
      Parameters:
      ch - character to append
      padding - 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 interface CharAppender
      Parameters:
      ch - character to append
    • indexOf

      public int indexOf(char ch, int from)
      Description copied from interface: CharAppender
      Returns first the position of a given character
      Specified by:
      indexOf in interface CharAppender
      Parameters:
      ch - the character to look for
      from - the starting index from where the search will begin.
      Returns:
      the position of the given character in the appended content, -1 if not found
    • indexOfAny

      public int indexOfAny(char[] chars, int from)
      Description copied from interface: CharAppender
      Returns the first position of any given character
      Specified by:
      indexOfAny in interface CharAppender
      Parameters:
      chars - the characters to look for
      from - the starting index from where the search will begin.
      Returns:
      the position any one of the given characters in the appended content, -1 if none found
    • substring

      public String substring(int from, int length)
      Description copied from interface: CharAppender
      Returns a section of the appended content
      Specified by:
      substring in interface CharAppender
      Parameters:
      from - the starting position in the buffer
      length - the number of characters to accumulate from the given start position
      Returns:
      a String with the section of characters accumulated by this appender.
    • remove

      public void remove(int from, int length)
      Description copied from interface: CharAppender
      Removes a section from the appended content
      Specified by:
      remove in interface CharAppender
      Parameters:
      from - the starting position in the buffer (inclusive)
      length - the number of characters to accumulate from the given start position
    • append

      public void append(char ch)
      Description copied from interface: CharAppender
      Appends the given character.
      Specified by:
      append in interface CharAppender
      Parameters:
      ch - the character to append
    • append

      public final void append(Object o)
      Description copied from interface: CharAppender
      Appends the String representation of a given object.
      Specified by:
      append in interface CharAppender
      Parameters:
      o - the object whose String representation will be appended.
    • append

      public final void append(int ch)
      Description copied from interface: CharAppender
      Appends the given codepoint.
      Specified by:
      append in interface CharAppender
      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 interface CharAppender
      Parameters:
      ch - the codepoint array
    • getAndReset

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

      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 interface CharAppender
      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 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)

      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 interface CharSequence
      Overrides:
      toString in class 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 interface CharAppender
      Specified by:
      length in interface 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 using 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.

      Specified by:
      getCharsAndReset in interface CharAppender
      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) or CharAppender.appendIgnoringWhitespaceAndPadding(char, char)

      Specified by:
      whitespaceCount in interface CharAppender
      Returns:
      the number of whitespaces accumulated using CharAppender.appendIgnoringWhitespace(char), CharAppender.appendIgnoringPadding(char, char) or CharAppender.appendIgnoringWhitespaceAndPadding(char, char)
    • reset

      public void reset()
      Description copied from interface: CharAppender
      Clears the accumulated value and the whitespace count.
      Specified by:
      reset in interface CharAppender
    • 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) or CharAppender.appendIgnoringWhitespaceAndPadding(char, char)

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

      Specified by:
      resetWhitespaceCount in interface CharAppender
    • getChars

      public final char[] getChars()
      Description copied from interface: CharAppender
      Returns the internal character array.
      Specified by:
      getChars in interface CharAppender
      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 interface CharAppender
      Parameters:
      ch - the character to append
      length - 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 interface CharAppender
      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 interface CharAppender
      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 interface CharAppender
      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 interface CharAppender
    • 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 interface CharAppender
      Parameters:
      ch - the first character of the input to be appended.
      input - the input whose the following characters will be appended
      stop - 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 interface CharAppender
      Parameters:
      ch - the first character of the input to be appended.
      input - the input whose the following characters will be appended
      stop1 - the first stop character
      stop2 - 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 interface CharAppender
      Parameters:
      ch - the first character of the input to be appended.
      input - the input whose the following characters will be appended
      stop1 - the first stop character
      stop2 - the second stop character
      stop3 - 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 interface CharAppender
      Parameters:
      ch - the character array
      from - the position of the first character in the array to be appended
      length - 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 interface CharAppender
      Parameters:
      ch - the character array
    • append

      public void append(String string, int from, int to)
      Description copied from interface: CharAppender
      Appends the contents of a String to this appender
      Specified by:
      append in interface CharAppender
      Parameters:
      string - the string whose characters will be appended.
      from - the index of the first character to append
      to - the index of the last character to append
    • append

      public final void append(String string)
      Description copied from interface: CharAppender
      Appends characters from an input String
      Specified by:
      append in interface CharAppender
      Parameters:
      string - the input String
    • charAt

      public final char charAt(int i)
      Specified by:
      charAt in interface CharSequence
    • subSequence

      public final String subSequence(int from, int to)
      Specified by:
      subSequence in interface CharSequence
    • ignore

      public final void ignore(int count)
      Description copied from interface: CharAppender
      Ignores the given number of characters at the end of the appended content, effectively marking these as whitespace. Invoking CharAppender.resetWhitespaceCount() or CharAppender.updateWhitespace() will undo this effect.
      Specified by:
      ignore in interface CharAppender
      Parameters:
      count - the number of characters to ignore
    • delete

      public void delete(int count)
      Description copied from interface: CharAppender
      Deletes a given number of characters from the end of the appended content. Will reset the internal whitespace count if any. Invoke CharAppender.updateWhitespace() to recalculate the number of trailing whitespaces in the appended content.
      Specified by:
      delete in interface CharAppender
      Parameters:
      count - the number of characters to delete.
    • indexOf

      public int indexOf(char[] charSequence, int fromIndex)
      Description copied from interface: CharAppender
      Returns first the position of a given character sequence
      Specified by:
      indexOf in interface CharAppender
      Parameters:
      charSequence - the character sequence to look for
      fromIndex - the starting index from where the search will begin.
      Returns:
      the position of the given character sequence in the appended content, -1 if not found
    • indexOf

      public int indexOf(CharSequence charSequence, int fromIndex)
      Description copied from interface: CharAppender
      Returns first the position of a given character sequence
      Specified by:
      indexOf in interface CharAppender
      Parameters:
      charSequence - the character sequence to look for
      fromIndex - the starting index from where the search will begin.
      Returns:
      the position of the given character sequence in the appended content, -1 if not found
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: CharAppender
      Indicates whether this appender represents an empty String.
      Specified by:
      isEmpty in interface CharAppender
      Specified by:
      isEmpty in interface CharSequence
      Returns:
      true calling CharAppender.getAndReset() would return null, otherwise false.
    • lastIndexOf

      public int lastIndexOf(char ch)
      Description copied from interface: CharAppender
      Returns the last index of a given character in the current appended (characters that have been marked as whitespace will be ignored)
      Specified by:
      lastIndexOf in interface CharAppender
      Parameters:
      ch - the character to look for
      Returns:
      the last position of the given character in the appended content, or -1 if not found.