Class SimpleCharacterIterator

java.lang.Object
org.apache.sis.internal.util.SimpleCharacterIterator
All Implemented Interfaces:
Serializable, CharSequence, Cloneable, CharacterIterator
Direct Known Subclasses:
FormattedCharacterIterator

public class SimpleCharacterIterator extends Object implements CharacterIterator, CharSequence, Serializable
A simple implementation of the CharacterIterator interface as a wrapper around a given CharSequence.
Since:
0.3
Version:
0.3
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private int
    The index of the next character to be returned by the iterator.
    protected static final int
    Index of the first character that we can return.
    private static final long
    For cross-version compatibility.
    protected final CharSequence
    The wrapped character sequence.
    protected int
    The upper index (index after the last character that we can return).

    Fields inherited from interface java.text.CharacterIterator

    DONE
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new character iterator for the given character sequence.
  • Method Summary

    Modifier and Type
    Method
    Description
    final char
    charAt(int index)
    Returns the character at the given index.
    Returns a copy of this iterator.
    final char
    Gets the character at the current position.
    final char
    Sets the position to the beginning and returns the character at that position.
    final int
    Returns the start index of the text.
    final int
    Returns the end index of the text.
    final int
    Returns the current index.
    final char
    Sets the position to the end and returns the character at that position.
    final int
    Returns the number of characters.
    final char
    Increments the iterator's index by one and returns the character at the new index.
    final char
    Decrements the iterator's index by one and returns the character at the new index.
    final char
    setIndex(int position)
    Sets the position to the specified position in the text and returns that character.
    subSequence(int start, int end)
    Returns a sub-sequence of the wrapped text.
    final String
    Returns a string representation of the wrapped character sequence.

    Methods inherited from class java.lang.Object

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

    Methods inherited from interface java.lang.CharSequence

    chars, codePoints, isEmpty
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      For cross-version compatibility.
      See Also:
    • text

      protected final CharSequence text
      The wrapped character sequence.
    • lower

      protected static final int lower
      Index of the first character that we can return. Fixed to 0 for now, but declared as a variable in case we want to support non-zero start index in a future version.
      See Also:
    • upper

      protected int upper
      The upper index (index after the last character that we can return). This field is not final because some classes need to update it, for example if text is a growing StringBuffer.
    • index

      private int index
      The index of the next character to be returned by the iterator.
  • Constructor Details

    • SimpleCharacterIterator

      public SimpleCharacterIterator(CharSequence text)
      Creates a new character iterator for the given character sequence.
      Parameters:
      text - the character sequence to wrap.
  • Method Details

    • first

      public final char first()
      Sets the position to the beginning and returns the character at that position.
      Specified by:
      first in interface CharacterIterator
    • last

      public final char last()
      Sets the position to the end and returns the character at that position.
      Specified by:
      last in interface CharacterIterator
    • current

      public final char current()
      Gets the character at the current position.
      Specified by:
      current in interface CharacterIterator
    • next

      public final char next()
      Increments the iterator's index by one and returns the character at the new index.
      Specified by:
      next in interface CharacterIterator
    • previous

      public final char previous()
      Decrements the iterator's index by one and returns the character at the new index.
      Specified by:
      previous in interface CharacterIterator
    • charAt

      public final char charAt(int index)
      Returns the character at the given index.
      Specified by:
      charAt in interface CharSequence
    • setIndex

      public final char setIndex(int position)
      Sets the position to the specified position in the text and returns that character.
      Specified by:
      setIndex in interface CharacterIterator
    • getIndex

      public final int getIndex()
      Returns the current index.
      Specified by:
      getIndex in interface CharacterIterator
    • getBeginIndex

      public final int getBeginIndex()
      Returns the start index of the text.
      Specified by:
      getBeginIndex in interface CharacterIterator
    • getEndIndex

      public final int getEndIndex()
      Returns the end index of the text.
      Specified by:
      getEndIndex in interface CharacterIterator
    • length

      public final int length()
      Returns the number of characters.
      Specified by:
      length in interface CharSequence
    • subSequence

      public final CharSequence subSequence(int start, int end)
      Returns a sub-sequence of the wrapped text.
      Specified by:
      subSequence in interface CharSequence
    • clone

      public Object clone()
      Returns a copy of this iterator.
      Specified by:
      clone in interface CharacterIterator
      Overrides:
      clone in class Object
    • toString

      public final String toString()
      Returns a string representation of the wrapped character sequence.
      Specified by:
      toString in interface CharSequence
      Overrides:
      toString in class Object