jdk/src/java.base/share/classes/java/text/StringCharacterIterator.java
author mchung
Fri, 22 May 2015 16:43:39 -0700
changeset 30789 9eca83469588
parent 25859 3317bb8137f4
child 45434 4582657c7260
permissions -rw-r--r--
8074431: Remove native2ascii tool Reviewed-by: erikj, alanb, okutsu, mfang, naoto
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
public final class StringCharacterIterator implements CharacterIterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private String text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private int begin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private int end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    // invariant: begin <= pos <= end
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private int pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * 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
    62
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 14342
diff changeset
    63
     * @param text the {@code String} to be iterated over
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public StringCharacterIterator(String text)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        this(text, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * Constructs an iterator with the specified initial index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * @param  text   The String to be iterated over
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * @param  pos    Initial iterator position
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public StringCharacterIterator(String text, int pos)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    this(text, 0, text.length(), pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * Constructs an iterator over the given range of the given string, with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * index set at the specified position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @param  text   The String to be iterated over
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * @param  begin  Index of the first character
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @param  end    Index of the character following the last character
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @param  pos    Initial iterator position
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public StringCharacterIterator(String text, int begin, int end, int pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        if (text == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        this.text = text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        if (begin < 0 || begin > end || end > text.length())
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            throw new IllegalArgumentException("Invalid substring range");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        if (pos < begin || pos > end)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            throw new IllegalArgumentException("Invalid position");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        this.begin = begin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        this.end = end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        this.pos = pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * Reset this iterator to point to a new string.  This package-visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * method is used by other java.text classes that want to avoid allocating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * new StringCharacterIterator objects every time their setText method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @param  text   The String to be iterated over
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public void setText(String text) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        if (text == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        this.text = text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        this.begin = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        this.end = text.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        this.pos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * Implements CharacterIterator.first() for String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @see CharacterIterator#first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public char first()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        pos = begin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        return current();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Implements CharacterIterator.last() for String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @see CharacterIterator#last
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public char last()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        if (end != begin) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            pos = end - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            pos = end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        return current();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * Implements CharacterIterator.setIndex() for String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @see CharacterIterator#setIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public char setIndex(int p)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    if (p < begin || p > end)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            throw new IllegalArgumentException("Invalid index");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        pos = p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        return current();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * Implements CharacterIterator.current() for String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @see CharacterIterator#current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public char current()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        if (pos >= begin && pos < end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            return text.charAt(pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            return DONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
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
     * Implements CharacterIterator.next() for String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @see CharacterIterator#next
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    public char next()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        if (pos < end - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            pos++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            return text.charAt(pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            pos = end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            return DONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
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
     * Implements CharacterIterator.previous() for String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @see CharacterIterator#previous
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    public char previous()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        if (pos > begin) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            pos--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            return text.charAt(pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            return DONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        }
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
     * Implements CharacterIterator.getBeginIndex() for String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * @see CharacterIterator#getBeginIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    public int getBeginIndex()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        return begin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * Implements CharacterIterator.getEndIndex() for String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @see CharacterIterator#getEndIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    public int getEndIndex()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        return end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * Implements CharacterIterator.getIndex() for String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @see CharacterIterator#getIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    public int getIndex()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        return pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * Compares the equality of two StringCharacterIterator objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @param obj the StringCharacterIterator object to be compared with.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @return true if the given obj is the same as this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * StringCharacterIterator object; false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    public boolean equals(Object obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        if (this == obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        if (!(obj instanceof StringCharacterIterator))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        StringCharacterIterator that = (StringCharacterIterator) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        if (hashCode() != that.hashCode())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        if (!text.equals(that.text))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        if (pos != that.pos || begin != that.begin || end != that.end)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * Computes a hashcode for this iterator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @return A hash code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    public int hashCode()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        return text.hashCode() ^ pos ^ begin ^ end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * Creates a copy of this iterator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @return A copy of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    public Object clone()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            StringCharacterIterator other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            = (StringCharacterIterator) super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            return other;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        catch (CloneNotSupportedException e) {
10419
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 5506
diff changeset
   277
            throw new InternalError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
}