Constructors Summary |
---|
public StringCharacterIterator(String value)Constructs a new {@code StringCharacterIterator} on the specified string.
The begin and current indices are set to the beginning of the string, the
end index is set to the length of the string.
string = value;
start = offset = 0;
end = string.length();
|
public StringCharacterIterator(String value, int location)Constructs a new {@code StringCharacterIterator} on the specified string
with the current index set to the specified value. The begin index is set
to the beginning of the string, the end index is set to the length of the
string.
string = value;
start = 0;
end = string.length();
if (location < 0 || location > end) {
throw new IllegalArgumentException();
}
offset = location;
|
public StringCharacterIterator(String value, int start, int end, int location)Constructs a new {@code StringCharacterIterator} on the specified string
with the begin, end and current index set to the specified values.
string = value;
if (start < 0 || end > string.length() || start > end
|| location < start || location > end) {
throw new IllegalArgumentException();
}
this.start = start;
this.end = end;
offset = location;
|
Methods Summary |
---|
public java.lang.Object | clone()Returns a new {@code StringCharacterIterator} with the same source
string, begin, end, and current index as this iterator.
try {
return super.clone();
} catch (CloneNotSupportedException e) {
return null;
}
|
public char | current()Returns the character at the current index in the source string.
if (offset == end) {
return DONE;
}
return string.charAt(offset);
|
public boolean | equals(java.lang.Object object)Compares the specified object with this {@code StringCharacterIterator}
and indicates if they are equal. In order to be equal, {@code object}
must be an instance of {@code StringCharacterIterator} that iterates over
the same sequence of characters with the same index.
if (!(object instanceof StringCharacterIterator)) {
return false;
}
StringCharacterIterator it = (StringCharacterIterator) object;
return string.equals(it.string) && start == it.start && end == it.end
&& offset == it.offset;
|
public char | first()Sets the current position to the begin index and returns the character at
the new position in the source string.
if (start == end) {
return DONE;
}
offset = start;
return string.charAt(offset);
|
public int | getBeginIndex()Returns the begin index in the source string.
return start;
|
public int | getEndIndex()Returns the end index in the source string.
return end;
|
public int | getIndex()Returns the current index in the source string.
return offset;
|
public int | hashCode()
return string.hashCode() + start + end + offset;
|
public char | last()Sets the current position to the end index - 1 and returns the character
at the new position.
if (start == end) {
return DONE;
}
offset = end - 1;
return string.charAt(offset);
|
public char | next()Increments the current index and returns the character at the new index.
if (offset >= (end - 1)) {
offset = end;
return DONE;
}
return string.charAt(++offset);
|
public char | previous()Decrements the current index and returns the character at the new index.
if (offset == start) {
return DONE;
}
return string.charAt(--offset);
|
public char | setIndex(int location)Sets the current index in the source string.
if (location < start || location > end) {
throw new IllegalArgumentException();
}
offset = location;
if (offset == end) {
return DONE;
}
return string.charAt(offset);
|
public void | setText(java.lang.String value)Sets the source string to iterate over. The begin and end positions are
set to the start and end of this string.
string = value;
start = offset = 0;
end = value.length();
|