FileDocCategorySizeDatePackage
CharArrayIterator.javaAPI DocJava SE 5 API4396Fri Aug 26 14:56:50 BST 2005java.awt.font

CharArrayIterator

public class CharArrayIterator extends Object implements CharacterIterator

Fields Summary
private char[]
chars
private int
pos
private int
begin
Constructors Summary
CharArrayIterator(char[] chars)

        
        reset(chars, 0);
    
CharArrayIterator(char[] chars, int begin)

        
        reset(chars, begin);
    
Methods Summary
public java.lang.Objectclone()
Create a copy of this iterator

return
A copy of this

        CharArrayIterator c = new CharArrayIterator(chars, begin);
        c.pos = this.pos;
        return c;
    
public charcurrent()
Gets the character at the current position (as returned by getIndex()).

return
the character at the current position or DONE if the current position is off the end of the text.
see
getIndex

        
        if (pos >= 0 && pos < chars.length) {
            return chars[pos];
        }
        else {
            return DONE;
        }
    
public charfirst()
Sets the position to getBeginIndex() and returns the character at that position.

return
the first character in the text, or DONE if the text is empty
see
getBeginIndex

        
        pos = 0;
        return current();
    
public intgetBeginIndex()
Returns the start index of the text.

return
the index at which the text begins.

        return begin;
    
public intgetEndIndex()
Returns the end index of the text. This index is the index of the first character following the end of the text.

return
the index after the last character in the text

        return begin+chars.length;
    
public intgetIndex()
Returns the current index.

return
the current index.

        return begin+pos;
    
public charlast()
Sets the position to getEndIndex()-1 (getEndIndex() if the text is empty) and returns the character at that position.

return
the last character in the text, or DONE if the text is empty
see
getEndIndex

        
        if (chars.length > 0) {
            pos = chars.length-1;
        }
        else {
            pos = 0;
        }
        return current();
    
public charnext()
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.

return
the character at the new position or DONE if the new position is off the end of the text range.

       
        if (pos < chars.length-1) {
            pos++;
            return chars[pos];
        }
        else {
            pos = chars.length;
            return DONE;
        }
    
public charprevious()
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.

return
the character at the new position or DONE if the current position is equal to getBeginIndex().

        
        if (pos > 0) {
            pos--;
            return chars[pos];
        }
        else {
            pos = 0;
            return DONE;
        }
    
voidreset(char[] chars)

        reset(chars, 0);
    
voidreset(char[] chars, int begin)

        
        this.chars = chars;
        this.begin = begin;
        pos = 0;
    
public charsetIndex(int position)
Sets the position to the specified position in the text and returns that character.

param
position the position within the text. Valid values range from getBeginIndex() to getEndIndex(). An IllegalArgumentException is thrown if an invalid value is supplied.
return
the character at the specified position or DONE if the specified position is equal to getEndIndex()

        
        position -= begin;
        if (position < 0 || position > chars.length) {
            throw new IllegalArgumentException("Invalid index");
        }
        pos = position;
        return current();