rt/emul/compact/src/main/java/java/text/CharacterIterator.java
author Jaroslav Tulach <jtulach@netbeans.org>
Thu, 03 Oct 2013 15:40:35 +0200
branchjdk7-b147
changeset 1334 588d5bf7a560
permissions -rw-r--r--
Set of JDK classes needed to run javac
jtulach@1334
     1
/*
jtulach@1334
     2
 * Copyright (c) 1996, 2000, Oracle and/or its affiliates. All rights reserved.
jtulach@1334
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jtulach@1334
     4
 *
jtulach@1334
     5
 * This code is free software; you can redistribute it and/or modify it
jtulach@1334
     6
 * under the terms of the GNU General Public License version 2 only, as
jtulach@1334
     7
 * published by the Free Software Foundation.  Oracle designates this
jtulach@1334
     8
 * particular file as subject to the "Classpath" exception as provided
jtulach@1334
     9
 * by Oracle in the LICENSE file that accompanied this code.
jtulach@1334
    10
 *
jtulach@1334
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
jtulach@1334
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jtulach@1334
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
jtulach@1334
    14
 * version 2 for more details (a copy is included in the LICENSE file that
jtulach@1334
    15
 * accompanied this code).
jtulach@1334
    16
 *
jtulach@1334
    17
 * You should have received a copy of the GNU General Public License version
jtulach@1334
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
jtulach@1334
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jtulach@1334
    20
 *
jtulach@1334
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jtulach@1334
    22
 * or visit www.oracle.com if you need additional information or have any
jtulach@1334
    23
 * questions.
jtulach@1334
    24
 */
jtulach@1334
    25
jtulach@1334
    26
/*
jtulach@1334
    27
 * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
jtulach@1334
    28
 * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
jtulach@1334
    29
 *
jtulach@1334
    30
 * The original version of this source code and documentation
jtulach@1334
    31
 * is copyrighted and owned by Taligent, Inc., a wholly-owned
jtulach@1334
    32
 * subsidiary of IBM. These materials are provided under terms
jtulach@1334
    33
 * of a License Agreement between Taligent and Sun. This technology
jtulach@1334
    34
 * is protected by multiple US and International patents.
jtulach@1334
    35
 *
jtulach@1334
    36
 * This notice and attribution to Taligent may not be removed.
jtulach@1334
    37
 * Taligent is a registered trademark of Taligent, Inc.
jtulach@1334
    38
 *
jtulach@1334
    39
 */
jtulach@1334
    40
jtulach@1334
    41
package java.text;
jtulach@1334
    42
jtulach@1334
    43
jtulach@1334
    44
/**
jtulach@1334
    45
 * This interface defines a protocol for bidirectional iteration over text.
jtulach@1334
    46
 * The iterator iterates over a bounded sequence of characters.  Characters
jtulach@1334
    47
 * are indexed with values beginning with the value returned by getBeginIndex() and
jtulach@1334
    48
 * continuing through the value returned by getEndIndex()-1.
jtulach@1334
    49
 * <p>
jtulach@1334
    50
 * Iterators maintain a current character index, whose valid range is from
jtulach@1334
    51
 * getBeginIndex() to getEndIndex(); the value getEndIndex() is included to allow
jtulach@1334
    52
 * handling of zero-length text ranges and for historical reasons.
jtulach@1334
    53
 * The current index can be retrieved by calling getIndex() and set directly
jtulach@1334
    54
 * by calling setIndex(), first(), and last().
jtulach@1334
    55
 * <p>
jtulach@1334
    56
 * The methods previous() and next() are used for iteration. They return DONE if
jtulach@1334
    57
 * they would move outside the range from getBeginIndex() to getEndIndex() -1,
jtulach@1334
    58
 * signaling that the iterator has reached the end of the sequence. DONE is
jtulach@1334
    59
 * also returned by other methods to indicate that the current index is
jtulach@1334
    60
 * outside this range.
jtulach@1334
    61
 *
jtulach@1334
    62
 * <P>Examples:<P>
jtulach@1334
    63
 *
jtulach@1334
    64
 * Traverse the text from start to finish
jtulach@1334
    65
 * <pre>
jtulach@1334
    66
 * public void traverseForward(CharacterIterator iter) {
jtulach@1334
    67
 *     for(char c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) {
jtulach@1334
    68
 *         processChar(c);
jtulach@1334
    69
 *     }
jtulach@1334
    70
 * }
jtulach@1334
    71
 * </pre>
jtulach@1334
    72
 *
jtulach@1334
    73
 * Traverse the text backwards, from end to start
jtulach@1334
    74
 * <pre>
jtulach@1334
    75
 * public void traverseBackward(CharacterIterator iter) {
jtulach@1334
    76
 *     for(char c = iter.last(); c != CharacterIterator.DONE; c = iter.previous()) {
jtulach@1334
    77
 *         processChar(c);
jtulach@1334
    78
 *     }
jtulach@1334
    79
 * }
jtulach@1334
    80
 * </pre>
jtulach@1334
    81
 *
jtulach@1334
    82
 * Traverse both forward and backward from a given position in the text.
jtulach@1334
    83
 * Calls to notBoundary() in this example represents some
jtulach@1334
    84
 * additional stopping criteria.
jtulach@1334
    85
 * <pre>
jtulach@1334
    86
 * public void traverseOut(CharacterIterator iter, int pos) {
jtulach@1334
    87
 *     for (char c = iter.setIndex(pos);
jtulach@1334
    88
 *              c != CharacterIterator.DONE && notBoundary(c);
jtulach@1334
    89
 *              c = iter.next()) {
jtulach@1334
    90
 *     }
jtulach@1334
    91
 *     int end = iter.getIndex();
jtulach@1334
    92
 *     for (char c = iter.setIndex(pos);
jtulach@1334
    93
 *             c != CharacterIterator.DONE && notBoundary(c);
jtulach@1334
    94
 *             c = iter.previous()) {
jtulach@1334
    95
 *     }
jtulach@1334
    96
 *     int start = iter.getIndex();
jtulach@1334
    97
 *     processSection(start, end);
jtulach@1334
    98
 * }
jtulach@1334
    99
 * </pre>
jtulach@1334
   100
 *
jtulach@1334
   101
 * @see StringCharacterIterator
jtulach@1334
   102
 * @see AttributedCharacterIterator
jtulach@1334
   103
 */
jtulach@1334
   104
jtulach@1334
   105
public interface CharacterIterator extends Cloneable
jtulach@1334
   106
{
jtulach@1334
   107
jtulach@1334
   108
    /**
jtulach@1334
   109
     * Constant that is returned when the iterator has reached either the end
jtulach@1334
   110
     * or the beginning of the text. The value is '\\uFFFF', the "not a
jtulach@1334
   111
     * character" value which should not occur in any valid Unicode string.
jtulach@1334
   112
     */
jtulach@1334
   113
    public static final char DONE = '\uFFFF';
jtulach@1334
   114
jtulach@1334
   115
    /**
jtulach@1334
   116
     * Sets the position to getBeginIndex() and returns the character at that
jtulach@1334
   117
     * position.
jtulach@1334
   118
     * @return the first character in the text, or DONE if the text is empty
jtulach@1334
   119
     * @see #getBeginIndex()
jtulach@1334
   120
     */
jtulach@1334
   121
    public char first();
jtulach@1334
   122
jtulach@1334
   123
    /**
jtulach@1334
   124
     * Sets the position to getEndIndex()-1 (getEndIndex() if the text is empty)
jtulach@1334
   125
     * and returns the character at that position.
jtulach@1334
   126
     * @return the last character in the text, or DONE if the text is empty
jtulach@1334
   127
     * @see #getEndIndex()
jtulach@1334
   128
     */
jtulach@1334
   129
    public char last();
jtulach@1334
   130
jtulach@1334
   131
    /**
jtulach@1334
   132
     * Gets the character at the current position (as returned by getIndex()).
jtulach@1334
   133
     * @return the character at the current position or DONE if the current
jtulach@1334
   134
     * position is off the end of the text.
jtulach@1334
   135
     * @see #getIndex()
jtulach@1334
   136
     */
jtulach@1334
   137
    public char current();
jtulach@1334
   138
jtulach@1334
   139
    /**
jtulach@1334
   140
     * Increments the iterator's index by one and returns the character
jtulach@1334
   141
     * at the new index.  If the resulting index is greater or equal
jtulach@1334
   142
     * to getEndIndex(), the current index is reset to getEndIndex() and
jtulach@1334
   143
     * a value of DONE is returned.
jtulach@1334
   144
     * @return the character at the new position or DONE if the new
jtulach@1334
   145
     * position is off the end of the text range.
jtulach@1334
   146
     */
jtulach@1334
   147
    public char next();
jtulach@1334
   148
jtulach@1334
   149
    /**
jtulach@1334
   150
     * Decrements the iterator's index by one and returns the character
jtulach@1334
   151
     * at the new index. If the current index is getBeginIndex(), the index
jtulach@1334
   152
     * remains at getBeginIndex() and a value of DONE is returned.
jtulach@1334
   153
     * @return the character at the new position or DONE if the current
jtulach@1334
   154
     * position is equal to getBeginIndex().
jtulach@1334
   155
     */
jtulach@1334
   156
    public char previous();
jtulach@1334
   157
jtulach@1334
   158
    /**
jtulach@1334
   159
     * Sets the position to the specified position in the text and returns that
jtulach@1334
   160
     * character.
jtulach@1334
   161
     * @param position the position within the text.  Valid values range from
jtulach@1334
   162
     * getBeginIndex() to getEndIndex().  An IllegalArgumentException is thrown
jtulach@1334
   163
     * if an invalid value is supplied.
jtulach@1334
   164
     * @return the character at the specified position or DONE if the specified position is equal to getEndIndex()
jtulach@1334
   165
     */
jtulach@1334
   166
    public char setIndex(int position);
jtulach@1334
   167
jtulach@1334
   168
    /**
jtulach@1334
   169
     * Returns the start index of the text.
jtulach@1334
   170
     * @return the index at which the text begins.
jtulach@1334
   171
     */
jtulach@1334
   172
    public int getBeginIndex();
jtulach@1334
   173
jtulach@1334
   174
    /**
jtulach@1334
   175
     * Returns the end index of the text.  This index is the index of the first
jtulach@1334
   176
     * character following the end of the text.
jtulach@1334
   177
     * @return the index after the last character in the text
jtulach@1334
   178
     */
jtulach@1334
   179
    public int getEndIndex();
jtulach@1334
   180
jtulach@1334
   181
    /**
jtulach@1334
   182
     * Returns the current index.
jtulach@1334
   183
     * @return the current index.
jtulach@1334
   184
     */
jtulach@1334
   185
    public int getIndex();
jtulach@1334
   186
jtulach@1334
   187
    /**
jtulach@1334
   188
     * Create a copy of this iterator
jtulach@1334
   189
     * @return A copy of this
jtulach@1334
   190
     */
jtulach@1334
   191
    public Object clone();
jtulach@1334
   192
jtulach@1334
   193
}