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 intThe index of the next character to be returned by the iterator.protected static final intIndex of the first character that we can return.private static final longFor cross-version compatibility.protected final CharSequenceThe wrapped character sequence.protected intThe 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 charcharAt(int index) Returns the character at the given index.clone()Returns a copy of this iterator.final charcurrent()Gets the character at the current position.final charfirst()Sets the position to the beginning and returns the character at that position.final intReturns the start index of the text.final intReturns the end index of the text.final intgetIndex()Returns the current index.final charlast()Sets the position to the end and returns the character at that position.final intlength()Returns the number of characters.final charnext()Increments the iterator's index by one and returns the character at the new index.final charprevious()Decrements the iterator's index by one and returns the character at the new index.final charsetIndex(int position) Sets the position to the specified position in the text and returns that character.final CharSequencesubSequence(int start, int end) Returns a sub-sequence of the wrapped text.final StringtoString()Returns a string representation of the wrapped character sequence.Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.CharSequence
chars, codePoints
-
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 iftextis 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:
firstin interfaceCharacterIterator
-
last
public final char last()Sets the position to the end and returns the character at that position.- Specified by:
lastin interfaceCharacterIterator
-
current
public final char current()Gets the character at the current position.- Specified by:
currentin interfaceCharacterIterator
-
next
public final char next()Increments the iterator's index by one and returns the character at the new index.- Specified by:
nextin interfaceCharacterIterator
-
previous
public final char previous()Decrements the iterator's index by one and returns the character at the new index.- Specified by:
previousin interfaceCharacterIterator
-
charAt
public final char charAt(int index) Returns the character at the given index.- Specified by:
charAtin interfaceCharSequence
-
setIndex
public final char setIndex(int position) Sets the position to the specified position in the text and returns that character.- Specified by:
setIndexin interfaceCharacterIterator
-
getIndex
public final int getIndex()Returns the current index.- Specified by:
getIndexin interfaceCharacterIterator
-
getBeginIndex
public final int getBeginIndex()Returns the start index of the text.- Specified by:
getBeginIndexin interfaceCharacterIterator
-
getEndIndex
public final int getEndIndex()Returns the end index of the text.- Specified by:
getEndIndexin interfaceCharacterIterator
-
length
public final int length()Returns the number of characters.- Specified by:
lengthin interfaceCharSequence
-
subSequence
Returns a sub-sequence of the wrapped text.- Specified by:
subSequencein interfaceCharSequence
-
clone
Returns a copy of this iterator.- Specified by:
clonein interfaceCharacterIterator- Overrides:
clonein classObject
-
toString
Returns a string representation of the wrapped character sequence.- Specified by:
toStringin interfaceCharSequence- Overrides:
toStringin classObject
-