001/* CharacterIterator.java -- Iterate over a character range 002 Copyright (C) 1998, 2001, 2005 Free Software Foundation, Inc. 003 004This file is part of GNU Classpath. 005 006GNU Classpath is free software; you can redistribute it and/or modify 007it under the terms of the GNU General Public License as published by 008the Free Software Foundation; either version 2, or (at your option) 009any later version. 010 011GNU Classpath is distributed in the hope that it will be useful, but 012WITHOUT ANY WARRANTY; without even the implied warranty of 013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014General Public License for more details. 015 016You should have received a copy of the GNU General Public License 017along with GNU Classpath; see the file COPYING. If not, write to the 018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 01902110-1301 USA. 020 021Linking this library statically or dynamically with other modules is 022making a combined work based on this library. Thus, the terms and 023conditions of the GNU General Public License cover the whole 024combination. 025 026As a special exception, the copyright holders of this library give you 027permission to link this library with independent modules to produce an 028executable, regardless of the license terms of these independent 029modules, and to copy and distribute the resulting executable under 030terms of your choice, provided that you also meet, for each linked 031independent module, the terms and conditions of the license of that 032module. An independent module is a module which is not derived from 033or based on this library. If you modify this library, you may extend 034this exception to your version of the library, but you are not 035obligated to do so. If you do not wish to do so, delete this 036exception statement from your version. */ 037 038 039package java.text; 040 041/** 042 * This interface defines a mechanism for iterating over a range of 043 * characters. For a given range of text, a beginning and ending index, 044 * as well as a current index are defined. These values can be queried 045 * by the methods in this interface. Additionally, various methods allow 046 * the index to be set. 047 * 048 * @author Aaron M. Renn (arenn@urbanophile.com) 049 */ 050public interface CharacterIterator extends Cloneable 051{ 052 /** 053 * This is a special constant value that is returned when the beginning or 054 * end of the character range has been reached. 055 */ 056 char DONE = '\uFFFF'; 057 058 /** 059 * This method returns the character at the current index position 060 * 061 * @return The character at the current index position. 062 */ 063 char current(); 064 065 /** 066 * This method increments the current index and then returns the character 067 * at the new index value. If the index is already at 068 * <code>getEndIndex() - 1</code>, it will not be incremented. 069 * 070 * @return The character at the position of the incremented index value, 071 * or {@link #DONE} if the index has reached getEndIndex() - 1 072 */ 073 char next(); 074 075 /** 076 * This method decrements the current index and then returns the character 077 * at the new index value. If the index value is already at the beginning 078 * index, it will not be decremented. 079 * 080 * @return The character at the position of the decremented index value, 081 * or {@link #DONE} if index was already equal to the beginning index 082 * value. 083 */ 084 char previous(); 085 086 /** 087 * This method sets the index value to the beginning of the range and returns 088 * the character there. 089 * 090 * @return The character at the beginning of the range, or {@link #DONE} if 091 * the range is empty. 092 */ 093 char first(); 094 095 /** 096 * This method sets the index value to <code>getEndIndex() - 1</code> and 097 * returns the character there. If the range is empty, then the index value 098 * will be set equal to the beginning index. 099 * 100 * @return The character at the end of the range, or {@link #DONE} if the 101 * range is empty. 102 */ 103 char last(); 104 105 /** 106 * This method returns the current value of the index. 107 * 108 * @return The current index value 109 */ 110 int getIndex(); 111 112 /** 113 * This method sets the value of the index to the specified value, then 114 * returns the character at that position. 115 * 116 * @param index The new index value. 117 * 118 * @return The character at the new index value or {@link #DONE} if the index 119 * value is equal to {@link #getEndIndex()}. 120 */ 121 char setIndex (int index) throws IllegalArgumentException; 122 123 /** 124 * This method returns the character position of the first character in the 125 * range. 126 * 127 * @return The index of the first character in the range. 128 */ 129 int getBeginIndex(); 130 131 /** 132 * This method returns the character position of the end of the text range. 133 * This will actually be the index of the first character following the 134 * end of the range. In the event the text range is empty, this will be 135 * equal to the first character in the range. 136 * 137 * @return The index of the end of the range. 138 */ 139 int getEndIndex(); 140 141 /** 142 * This method creates a copy of this <code>CharacterIterator</code>. 143 * 144 * @return A copy of this <code>CharacterIterator</code>. 145 */ 146 Object clone(); 147 148} // interface CharacterIterator