FileDocCategorySizeDatePackage
StringCharacterIterator.javaAPI DocAndroid 1.5 API8931Wed May 06 22:41:06 BST 2009java.text

StringCharacterIterator

public final class StringCharacterIterator extends Object implements CharacterIterator
An implementation of {@link CharacterIterator} for strings.
since
Android 1.0

Fields Summary
String
string
int
start
int
end
int
offset
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.

param
value the source string to iterate over.
since
Android 1.0

        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.

param
value the source string to iterate over.
param
location the current index.
exception
IllegalArgumentException if {@code location} is negative or greater than the length of the source string.
since
Android 1.0

        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.

param
value the source string to iterate over.
param
start the index of the first character to iterate.
param
end the index one past the last character to iterate.
param
location the current index.
exception
IllegalArgumentException if {@code start < 0}, {@code start > end}, {@code location < start}, {@code location > end} or if {@code end} is greater than the length of {@code value}.
since
Android 1.0

        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.Objectclone()
Returns a new {@code StringCharacterIterator} with the same source string, begin, end, and current index as this iterator.

return
a shallow copy of this iterator.
see
java.lang.Cloneable
since
Android 1.0

        try {
            return super.clone();
        } catch (CloneNotSupportedException e) {
            return null;
        }
    
public charcurrent()
Returns the character at the current index in the source string.

return
the current character, or {@code DONE} if the current index is past the end.
since
Android 1.0

        if (offset == end) {
            return DONE;
        }
        return string.charAt(offset);
    
public booleanequals(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.

param
object the object to compare with this object.
return
{@code true} if the specified object is equal to this {@code StringCharacterIterator}; {@code false} otherwise.
see
#hashCode
since
Android 1.0

        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 charfirst()
Sets the current position to the begin index and returns the character at the new position in the source string.

return
the character at the begin index or {@code DONE} if the begin index is equal to the end index.
since
Android 1.0

        if (start == end) {
            return DONE;
        }
        offset = start;
        return string.charAt(offset);
    
public intgetBeginIndex()
Returns the begin index in the source string.

return
the index of the first character of the iteration.
since
Android 1.0

        return start;
    
public intgetEndIndex()
Returns the end index in the source string.

return
the index one past the last character of the iteration.
since
Android 1.0

        return end;
    
public intgetIndex()
Returns the current index in the source string.

return
the current index.
since
Android 1.0

        return offset;
    
public inthashCode()

        return string.hashCode() + start + end + offset;
    
public charlast()
Sets the current position to the end index - 1 and returns the character at the new position.

return
the character before the end index or {@code DONE} if the begin index is equal to the end index.
since
Android 1.0

        if (start == end) {
            return DONE;
        }
        offset = end - 1;
        return string.charAt(offset);
    
public charnext()
Increments the current index and returns the character at the new index.

return
the character at the next index, or {@code DONE} if the next index would be past the end.
since
Android 1.0

        if (offset >= (end - 1)) {
            offset = end;
            return DONE;
        }
        return string.charAt(++offset);
    
public charprevious()
Decrements the current index and returns the character at the new index.

return
the character at the previous index, or {@code DONE} if the previous index would be past the beginning.
since
Android 1.0

        if (offset == start) {
            return DONE;
        }
        return string.charAt(--offset);
    
public charsetIndex(int location)
Sets the current index in the source string.

param
location the index the current position is set to.
return
the character at the new index, or {@code DONE} if {@code location} is set to the end index.
exception
IllegalArgumentException if {@code location} is smaller than the begin index or greater than the end index.
since
Android 1.0

        if (location < start || location > end) {
            throw new IllegalArgumentException();
        }
        offset = location;
        if (offset == end) {
            return DONE;
        }
        return string.charAt(offset);
    
public voidsetText(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.

param
value the new source string.
since
Android 1.0

        string = value;
        start = offset = 0;
        end = value.length();