src/java.base/share/classes/java/text/StringCharacterIterator.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 45434 jdk/src/java.base/share/classes/java/text/StringCharacterIterator.java@4582657c7260
child 58288 48e480e56aad
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 14342
diff changeset
     2
 * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * The original version of this source code and documentation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * is copyrighted and owned by Taligent, Inc., a wholly-owned
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * subsidiary of IBM. These materials are provided under terms
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * of a License Agreement between Taligent and Sun. This technology
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * is protected by multiple US and International patents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * This notice and attribution to Taligent may not be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * Taligent is a registered trademark of Taligent, Inc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
package java.text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <code>StringCharacterIterator</code> implements the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <code>CharacterIterator</code> protocol for a <code>String</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * The <code>StringCharacterIterator</code> class iterates over the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * entire <code>String</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @see CharacterIterator
45434
4582657c7260 8181082: class-level since tag issues in java.base & java.datatransfer module
mli
parents: 25859
diff changeset
    50
 * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
public final class StringCharacterIterator implements CharacterIterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private String text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private int begin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private int end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    // invariant: begin <= pos <= end
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private int pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * Constructs an iterator with an initial index of 0.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 14342
diff changeset
    63
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 14342
diff changeset
    64
     * @param text the {@code String} to be iterated over
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public StringCharacterIterator(String text)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        this(text, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * Constructs an iterator with the specified initial index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * @param  text   The String to be iterated over
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * @param  pos    Initial iterator position
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public StringCharacterIterator(String text, int pos)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    this(text, 0, text.length(), pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * Constructs an iterator over the given range of the given string, with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * index set at the specified position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * @param  text   The String to be iterated over
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @param  begin  Index of the first character
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @param  end    Index of the character following the last character
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @param  pos    Initial iterator position
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public StringCharacterIterator(String text, int begin, int end, int pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        if (text == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        this.text = text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        if (begin < 0 || begin > end || end > text.length())
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            throw new IllegalArgumentException("Invalid substring range");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        if (pos < begin || pos > end)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            throw new IllegalArgumentException("Invalid position");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        this.begin = begin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        this.end = end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        this.pos = pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Reset this iterator to point to a new string.  This package-visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * method is used by other java.text classes that want to avoid allocating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * new StringCharacterIterator objects every time their setText method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @param  text   The String to be iterated over
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public void setText(String text) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        if (text == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        this.text = text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        this.begin = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        this.end = text.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        this.pos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * Implements CharacterIterator.first() for String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @see CharacterIterator#first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    public char first()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        pos = begin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        return current();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * Implements CharacterIterator.last() for String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @see CharacterIterator#last
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public char last()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        if (end != begin) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            pos = end - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            pos = end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        return current();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * Implements CharacterIterator.setIndex() for String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * @see CharacterIterator#setIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public char setIndex(int p)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    if (p < begin || p > end)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            throw new IllegalArgumentException("Invalid index");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        pos = p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        return current();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * Implements CharacterIterator.current() for String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @see CharacterIterator#current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    public char current()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        if (pos >= begin && pos < end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            return text.charAt(pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            return DONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * Implements CharacterIterator.next() for String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @see CharacterIterator#next
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    public char next()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        if (pos < end - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            pos++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            return text.charAt(pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            pos = end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            return DONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * Implements CharacterIterator.previous() for String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @see CharacterIterator#previous
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    public char previous()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        if (pos > begin) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            pos--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            return text.charAt(pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            return DONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * Implements CharacterIterator.getBeginIndex() for String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * @see CharacterIterator#getBeginIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    public int getBeginIndex()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        return begin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * Implements CharacterIterator.getEndIndex() for String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * @see CharacterIterator#getEndIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    public int getEndIndex()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        return end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * Implements CharacterIterator.getIndex() for String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @see CharacterIterator#getIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    public int getIndex()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        return pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * Compares the equality of two StringCharacterIterator objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @param obj the StringCharacterIterator object to be compared with.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @return true if the given obj is the same as this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * StringCharacterIterator object; false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    public boolean equals(Object obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        if (this == obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        if (!(obj instanceof StringCharacterIterator))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        StringCharacterIterator that = (StringCharacterIterator) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        if (hashCode() != that.hashCode())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        if (!text.equals(that.text))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        if (pos != that.pos || begin != that.begin || end != that.end)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * Computes a hashcode for this iterator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * @return A hash code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    public int hashCode()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        return text.hashCode() ^ pos ^ begin ^ end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * Creates a copy of this iterator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @return A copy of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    public Object clone()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            StringCharacterIterator other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            = (StringCharacterIterator) super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            return other;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        catch (CloneNotSupportedException e) {
10419
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 5506
diff changeset
   278
            throw new InternalError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
}