Package org.apache.sis.internal.util
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
FieldsModifier and TypeFieldDescriptionprivate 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
ConstructorsConstructorDescriptionCreates a new character iterator for the given character sequence. -
Method Summary
Modifier and TypeMethodDescriptionfinal char
charAt
(int index) Returns the character at the given index.clone()
Returns a copy of this iterator.final char
current()
Gets the character at the current position.final char
first()
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
getIndex()
Returns the current index.final char
last()
Sets the position to the end and returns the character at that position.final int
length()
Returns the number of characters.final char
next()
Increments the iterator's index by one and returns the character at the new index.final char
previous()
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.final CharSequence
subSequence
(int start, int end) Returns a sub-sequence of the wrapped text.final String
toString()
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 serialVersionUIDFor cross-version compatibility.- See Also:
-
text
The wrapped character sequence. -
lower
protected static final int lowerIndex 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 upperThe 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 iftext
is a growingStringBuffer
. -
index
private int indexThe index of the next character to be returned by the iterator.
-
-
Constructor Details
-
SimpleCharacterIterator
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 interfaceCharacterIterator
-
last
public final char last()Sets the position to the end and returns the character at that position.- Specified by:
last
in interfaceCharacterIterator
-
current
public final char current()Gets the character at the current position.- Specified by:
current
in interfaceCharacterIterator
-
next
public final char next()Increments the iterator's index by one and returns the character at the new index.- Specified by:
next
in interfaceCharacterIterator
-
previous
public final char previous()Decrements the iterator's index by one and returns the character at the new index.- Specified by:
previous
in interfaceCharacterIterator
-
charAt
public final char charAt(int index) Returns the character at the given index.- Specified by:
charAt
in interfaceCharSequence
-
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 interfaceCharacterIterator
-
getIndex
public final int getIndex()Returns the current index.- Specified by:
getIndex
in interfaceCharacterIterator
-
getBeginIndex
public final int getBeginIndex()Returns the start index of the text.- Specified by:
getBeginIndex
in interfaceCharacterIterator
-
getEndIndex
public final int getEndIndex()Returns the end index of the text.- Specified by:
getEndIndex
in interfaceCharacterIterator
-
length
public final int length()Returns the number of characters.- Specified by:
length
in interfaceCharSequence
-
subSequence
Returns a sub-sequence of the wrapped text.- Specified by:
subSequence
in interfaceCharSequence
-
clone
Returns a copy of this iterator.- Specified by:
clone
in interfaceCharacterIterator
- Overrides:
clone
in classObject
-
toString
Returns a string representation of the wrapped character sequence.- Specified by:
toString
in interfaceCharSequence
- Overrides:
toString
in classObject
-