jdk/src/share/classes/java/lang/CharSequence.java
author mduigou
Wed, 01 May 2013 08:35:09 -0700
changeset 17210 8a90d05f28d8
parent 14342 8435a30053c1
child 18141 acb3c688a1b8
permissions -rw-r--r--
8012665: add CharSequence.chars, CharSequence.codePoints Reviewed-by: martin, alanb, ulfzibis, mduigou Contributed-by: Stuart Marks <stuart.marks@oracle.com>, Henry Jen <henry.jen@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
17210
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
     2
 * Copyright (c) 2000, 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
package java.lang;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
17210
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
    28
import java.util.NoSuchElementException;
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
    29
import java.util.PrimitiveIterator;
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
    30
import java.util.Spliterator;
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
    31
import java.util.Spliterators;
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
    32
import java.util.function.IntConsumer;
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
    33
import java.util.stream.IntStream;
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
    34
import java.util.stream.StreamSupport;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * A <tt>CharSequence</tt> is a readable sequence of <code>char</code> values. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * interface provides uniform, read-only access to many different kinds of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <code>char</code> sequences.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * A <code>char</code> value represents a character in the <i>Basic
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * Multilingual Plane (BMP)</i> or a surrogate. Refer to <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * href="Character.html#unicode">Unicode Character Representation</a> for details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <p> This interface does not refine the general contracts of the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * java.lang.Object#equals(java.lang.Object) equals} and {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * java.lang.Object#hashCode() hashCode} methods.  The result of comparing two
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * objects that implement <tt>CharSequence</tt> is therefore, in general,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * undefined.  Each object may be implemented by a different class, and there
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * is no guarantee that each class will be capable of testing its instances
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * for equality with those of the other.  It is therefore inappropriate to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * arbitrary <tt>CharSequence</tt> instances as elements in a set or as keys in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * a map. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @author Mike McCloskey
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * @spec JSR-51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
public interface CharSequence {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * Returns the length of this character sequence.  The length is the number
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * of 16-bit <code>char</code>s in the sequence.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * @return  the number of <code>char</code>s in this sequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    int length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * Returns the <code>char</code> value at the specified index.  An index ranges from zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * to <tt>length() - 1</tt>.  The first <code>char</code> value of the sequence is at
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * index zero, the next at index one, and so on, as for array
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * indexing. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * <p>If the <code>char</code> value specified by the index is a
8982
19c972e3d3ee 7009422: Two dead links in Swing API documentation
rupashka
parents: 5506
diff changeset
    76
     * <a href="{@docRoot}/java/lang/Character.html#unicode">surrogate</a>, the surrogate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * value is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @param   index   the index of the <code>char</code> value to be returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @return  the specified <code>char</code> value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @throws  IndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     *          if the <tt>index</tt> argument is negative or not less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *          <tt>length()</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    char charAt(int index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * Returns a new <code>CharSequence</code> that is a subsequence of this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * The subsequence starts with the <code>char</code> value at the specified index and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * ends with the <code>char</code> value at index <tt>end - 1</tt>.  The length
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * (in <code>char</code>s) of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * returned sequence is <tt>end - start</tt>, so if <tt>start == end</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * then an empty sequence is returned. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @param   start   the start index, inclusive
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @param   end     the end index, exclusive
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @return  the specified subsequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @throws  IndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     *          if <tt>start</tt> or <tt>end</tt> are negative,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *          if <tt>end</tt> is greater than <tt>length()</tt>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *          or if <tt>start</tt> is greater than <tt>end</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    CharSequence subSequence(int start, int end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * Returns a string containing the characters in this sequence in the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * order as this sequence.  The length of the string will be the length of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * this sequence. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @return  a string consisting of exactly this sequence of characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public String toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
17210
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   118
    /**
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   119
     * Returns a stream of {@code int} zero-extending the {@code char} values
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   120
     * from this sequence.  Any char which maps to a <a
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   121
     * href="{@docRoot}/java/lang/Character.html#unicode">surrogate code
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   122
     * point</a> is passed through uninterpreted.
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   123
     *
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   124
     * <p>If the sequence is mutated while the stream is being read, the
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   125
     * result is undefined.
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   126
     *
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   127
     * @return an IntStream of char values from this sequence
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   128
     * @since 1.8
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   129
     */
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   130
    public default IntStream chars() {
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   131
        class CharIterator implements PrimitiveIterator.OfInt {
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   132
            int cur = 0;
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   133
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   134
            public boolean hasNext() {
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   135
                return cur < length();
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   136
            }
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   137
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   138
            public int nextInt() {
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   139
                if (hasNext()) {
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   140
                    return charAt(cur++);
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   141
                } else {
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   142
                    throw new NoSuchElementException();
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   143
                }
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   144
            }
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   145
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   146
            @Override
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   147
            public void forEachRemaining(IntConsumer block) {
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   148
                for (; cur < length(); cur++) {
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   149
                    block.accept(charAt(cur));
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   150
                }
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   151
            }
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   152
        }
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   153
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   154
        return StreamSupport.intStream(() ->
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   155
                Spliterators.spliterator(
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   156
                        new CharIterator(),
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   157
                        length(),
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   158
                        Spliterator.ORDERED),
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   159
                Spliterator.SUBSIZED | Spliterator.SIZED | Spliterator.ORDERED);
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   160
    }
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   161
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   162
    /**
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   163
     * Returns a stream of code point values from this sequence.  Any surrogate
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   164
     * pairs encountered in the sequence are combined as if by {@linkplain
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   165
     * Character#toCodePoint Character.toCodePoint} and the result is passed
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   166
     * to the stream. Any other code units, including ordinary BMP characters,
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   167
     * unpaired surrogates, and undefined code units, are zero-extended to
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   168
     * {@code int} values which are then passed to the stream.
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   169
     *
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   170
     * <p>If the sequence is mutated while the stream is being read, the result
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   171
     * is undefined.
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   172
     *
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   173
     * @return an IntStream of Unicode code points from this sequence
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   174
     * @since 1.8
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   175
     */
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   176
    public default IntStream codePoints() {
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   177
        class CodePointIterator implements PrimitiveIterator.OfInt {
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   178
            int cur = 0;
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   179
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   180
            @Override
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   181
            public void forEachRemaining(IntConsumer block) {
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   182
                while (cur < length()) {
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   183
                    int cp = Character.codePointAt(CharSequence.this, cur);
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   184
                    cur += Character.charCount(cp);
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   185
                    block.accept(cp);
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   186
                }
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   187
            }
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   188
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   189
            public boolean hasNext() {
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   190
                return cur < length();
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   191
            }
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   192
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   193
            public int nextInt() {
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   194
                if (!hasNext()) {
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   195
                    throw new NoSuchElementException();
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   196
                }
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   197
                int cp = Character.codePointAt(CharSequence.this, cur);
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   198
                cur += Character.charCount(cp);
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   199
                return cp;
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   200
            }
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   201
        }
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   202
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   203
        return StreamSupport.intStream(() ->
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   204
                Spliterators.spliteratorUnknownSize(
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   205
                        new CodePointIterator(),
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   206
                        Spliterator.ORDERED),
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   207
                Spliterator.SUBSIZED | Spliterator.SIZED | Spliterator.ORDERED);
8a90d05f28d8 8012665: add CharSequence.chars, CharSequence.codePoints
mduigou
parents: 14342
diff changeset
   208
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
}