jdk/src/share/classes/java/text/StringCharacterIterator.java
author sherman
Tue, 30 Aug 2011 11:53:11 -0700
changeset 10419 12c063b39232
parent 5506 202f599c92aa
child 14342 8435a30053c1
permissions -rw-r--r--
7084245: Update usages of InternalError to use exception chaining Summary: to use new InternalError constructor with cause chainning Reviewed-by: alanb, ksrini, xuelei, neugens Contributed-by: sebastian.sickelmann@gmx.de
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1996, 2002, 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.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public StringCharacterIterator(String text)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        this(text, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * Constructs an iterator with the specified initial index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * @param  text   The String to be iterated over
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * @param  pos    Initial iterator position
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public StringCharacterIterator(String text, int pos)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    this(text, 0, text.length(), pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * Constructs an iterator over the given range of the given string, with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * index set at the specified position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @param  text   The String to be iterated over
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @param  begin  Index of the first character
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @param  end    Index of the character following the last character
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * @param  pos    Initial iterator position
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public StringCharacterIterator(String text, int begin, int end, int pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        if (text == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        this.text = text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        if (begin < 0 || begin > end || end > text.length())
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            throw new IllegalArgumentException("Invalid substring range");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        if (pos < begin || pos > end)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            throw new IllegalArgumentException("Invalid position");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        this.begin = begin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        this.end = end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        this.pos = pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * Reset this iterator to point to a new string.  This package-visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * method is used by other java.text classes that want to avoid allocating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * new StringCharacterIterator objects every time their setText method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @param  text   The String to be iterated over
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public void setText(String text) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        if (text == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        this.text = text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        this.begin = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        this.end = text.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        this.pos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * Implements CharacterIterator.first() for String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @see CharacterIterator#first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public char first()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        pos = begin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        return current();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * Implements CharacterIterator.last() for String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @see CharacterIterator#last
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public char last()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        if (end != begin) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            pos = end - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            pos = end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        return current();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * Implements CharacterIterator.setIndex() for String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @see CharacterIterator#setIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public char setIndex(int p)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    if (p < begin || p > end)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            throw new IllegalArgumentException("Invalid index");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        pos = p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        return current();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * Implements CharacterIterator.current() for String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @see CharacterIterator#current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    public char current()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        if (pos >= begin && pos < end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            return text.charAt(pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            return DONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * Implements CharacterIterator.next() for String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @see CharacterIterator#next
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public char next()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        if (pos < end - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            pos++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            return text.charAt(pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            pos = end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            return DONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * Implements CharacterIterator.previous() for String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @see CharacterIterator#previous
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public char previous()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        if (pos > begin) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            pos--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            return text.charAt(pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            return DONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * Implements CharacterIterator.getBeginIndex() for String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @see CharacterIterator#getBeginIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public int getBeginIndex()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        return begin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * Implements CharacterIterator.getEndIndex() for String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @see CharacterIterator#getEndIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    public int getEndIndex()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        return end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * Implements CharacterIterator.getIndex() for String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @see CharacterIterator#getIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    public int getIndex()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        return pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * Compares the equality of two StringCharacterIterator objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @param obj the StringCharacterIterator object to be compared with.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @return true if the given obj is the same as this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * StringCharacterIterator object; false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    public boolean equals(Object obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        if (this == obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        if (!(obj instanceof StringCharacterIterator))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        StringCharacterIterator that = (StringCharacterIterator) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        if (hashCode() != that.hashCode())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        if (!text.equals(that.text))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        if (pos != that.pos || begin != that.begin || end != that.end)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * Computes a hashcode for this iterator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @return A hash code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    public int hashCode()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        return text.hashCode() ^ pos ^ begin ^ end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * Creates a copy of this iterator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @return A copy of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    public Object clone()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            StringCharacterIterator other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            = (StringCharacterIterator) super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            return other;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        catch (CloneNotSupportedException e) {
10419
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 5506
diff changeset
   275
            throw new InternalError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
}