Constructors Summary |
---|
public StringCharacterIterator(String text)Constructs an iterator with an initial index of 0.
this(text, 0);
|
public StringCharacterIterator(String text, int pos)Constructs an iterator with the specified initial index.
this(text, 0, text.length(), pos);
|
public StringCharacterIterator(String text, int begin, int end, int pos)Constructs an iterator over the given range of the given string, with the
index set at the specified position.
if (text == null)
throw new NullPointerException();
this.text = text;
if (begin < 0 || begin > end || end > text.length())
throw new IllegalArgumentException("Invalid substring range");
if (pos < begin || pos > end)
throw new IllegalArgumentException("Invalid position");
this.begin = begin;
this.end = end;
this.pos = pos;
|
Methods Summary |
---|
public java.lang.Object | clone()Creates a copy of this iterator.
try {
StringCharacterIterator other
= (StringCharacterIterator) super.clone();
return other;
}
catch (CloneNotSupportedException e) {
throw new InternalError();
}
|
public char | current()Implements CharacterIterator.current() for String.
if (pos >= begin && pos < end) {
return text.charAt(pos);
}
else {
return DONE;
}
|
public boolean | equals(java.lang.Object obj)Compares the equality of two StringCharacterIterator objects.
if (this == obj)
return true;
if (!(obj instanceof StringCharacterIterator))
return false;
StringCharacterIterator that = (StringCharacterIterator) obj;
if (hashCode() != that.hashCode())
return false;
if (!text.equals(that.text))
return false;
if (pos != that.pos || begin != that.begin || end != that.end)
return false;
return true;
|
public char | first()Implements CharacterIterator.first() for String.
pos = begin;
return current();
|
public int | getBeginIndex()Implements CharacterIterator.getBeginIndex() for String.
return begin;
|
public int | getEndIndex()Implements CharacterIterator.getEndIndex() for String.
return end;
|
public int | getIndex()Implements CharacterIterator.getIndex() for String.
return pos;
|
public int | hashCode()Computes a hashcode for this iterator.
return text.hashCode() ^ pos ^ begin ^ end;
|
public char | last()Implements CharacterIterator.last() for String.
if (end != begin) {
pos = end - 1;
} else {
pos = end;
}
return current();
|
public char | next()Implements CharacterIterator.next() for String.
if (pos < end - 1) {
pos++;
return text.charAt(pos);
}
else {
pos = end;
return DONE;
}
|
public char | previous()Implements CharacterIterator.previous() for String.
if (pos > begin) {
pos--;
return text.charAt(pos);
}
else {
return DONE;
}
|
public char | setIndex(int p)Implements CharacterIterator.setIndex() for String.
if (p < begin || p > end)
throw new IllegalArgumentException("Invalid index");
pos = p;
return current();
|
public void | setText(java.lang.String text)Reset this iterator to point to a new string. This package-visible
method is used by other java.text classes that want to avoid allocating
new StringCharacterIterator objects every time their setText method
is called.
if (text == null)
throw new NullPointerException();
this.text = text;
this.begin = 0;
this.end = text.length();
this.pos = 0;
|