Methods Summary |
---|
public java.lang.Object | clone()Create a copy of this iterator
CharArrayIterator c = new CharArrayIterator(chars, begin);
c.pos = this.pos;
return c;
|
public char | current()Gets the character at the current position (as returned by getIndex()).
if (pos >= 0 && pos < chars.length) {
return chars[pos];
}
else {
return DONE;
}
|
public char | first()Sets the position to getBeginIndex() and returns the character at that
position.
pos = 0;
return current();
|
public int | getBeginIndex()Returns the start index of the text.
return begin;
|
public int | getEndIndex()Returns the end index of the text. This index is the index of the first
character following the end of the text.
return begin+chars.length;
|
public int | getIndex()Returns the current index.
return begin+pos;
|
public char | last()Sets the position to getEndIndex()-1 (getEndIndex() if the text is empty)
and returns the character at that position.
if (chars.length > 0) {
pos = chars.length-1;
}
else {
pos = 0;
}
return current();
|
public char | next()Increments the iterator's index by one and returns the character
at the new index. If the resulting index is greater or equal
to getEndIndex(), the current index is reset to getEndIndex() and
a value of DONE is returned.
if (pos < chars.length-1) {
pos++;
return chars[pos];
}
else {
pos = chars.length;
return DONE;
}
|
public char | previous()Decrements the iterator's index by one and returns the character
at the new index. If the current index is getBeginIndex(), the index
remains at getBeginIndex() and a value of DONE is returned.
if (pos > 0) {
pos--;
return chars[pos];
}
else {
pos = 0;
return DONE;
}
|
void | reset(char[] chars)
reset(chars, 0);
|
void | reset(char[] chars, int begin)
this.chars = chars;
this.begin = begin;
pos = 0;
|
public char | setIndex(int position)Sets the position to the specified position in the text and returns that
character.
position -= begin;
if (position < 0 || position > chars.length) {
throw new IllegalArgumentException("Invalid index");
}
pos = position;
return current();
|