jdk/src/java.base/share/classes/java/lang/CharSequence.java
changeset 32033 bf24e33c7919
parent 25859 3317bb8137f4
child 42225 07097c84db68
equal deleted inserted replaced
32032:22badc53802f 32033:bf24e33c7919
    32 import java.util.function.IntConsumer;
    32 import java.util.function.IntConsumer;
    33 import java.util.stream.IntStream;
    33 import java.util.stream.IntStream;
    34 import java.util.stream.StreamSupport;
    34 import java.util.stream.StreamSupport;
    35 
    35 
    36 /**
    36 /**
    37  * A <tt>CharSequence</tt> is a readable sequence of <code>char</code> values. This
    37  * A {@code CharSequence} is a readable sequence of {@code char} values. This
    38  * interface provides uniform, read-only access to many different kinds of
    38  * interface provides uniform, read-only access to many different kinds of
    39  * <code>char</code> sequences.
    39  * {@code char} sequences.
    40  * A <code>char</code> value represents a character in the <i>Basic
    40  * A {@code char} value represents a character in the <i>Basic
    41  * Multilingual Plane (BMP)</i> or a surrogate. Refer to <a
    41  * Multilingual Plane (BMP)</i> or a surrogate. Refer to <a
    42  * href="Character.html#unicode">Unicode Character Representation</a> for details.
    42  * href="Character.html#unicode">Unicode Character Representation</a> for details.
    43  *
    43  *
    44  * <p> This interface does not refine the general contracts of the {@link
    44  * <p> This interface does not refine the general contracts of the {@link
    45  * java.lang.Object#equals(java.lang.Object) equals} and {@link
    45  * java.lang.Object#equals(java.lang.Object) equals} and {@link
    46  * java.lang.Object#hashCode() hashCode} methods.  The result of comparing two
    46  * java.lang.Object#hashCode() hashCode} methods.  The result of comparing two
    47  * objects that implement <tt>CharSequence</tt> is therefore, in general,
    47  * objects that implement {@code CharSequence} is therefore, in general,
    48  * undefined.  Each object may be implemented by a different class, and there
    48  * undefined.  Each object may be implemented by a different class, and there
    49  * is no guarantee that each class will be capable of testing its instances
    49  * is no guarantee that each class will be capable of testing its instances
    50  * for equality with those of the other.  It is therefore inappropriate to use
    50  * for equality with those of the other.  It is therefore inappropriate to use
    51  * arbitrary <tt>CharSequence</tt> instances as elements in a set or as keys in
    51  * arbitrary {@code CharSequence} instances as elements in a set or as keys in
    52  * a map. </p>
    52  * a map. </p>
    53  *
    53  *
    54  * @author Mike McCloskey
    54  * @author Mike McCloskey
    55  * @since 1.4
    55  * @since 1.4
    56  * @spec JSR-51
    56  * @spec JSR-51
    58 
    58 
    59 public interface CharSequence {
    59 public interface CharSequence {
    60 
    60 
    61     /**
    61     /**
    62      * Returns the length of this character sequence.  The length is the number
    62      * Returns the length of this character sequence.  The length is the number
    63      * of 16-bit <code>char</code>s in the sequence.
    63      * of 16-bit {@code char}s in the sequence.
    64      *
    64      *
    65      * @return  the number of <code>char</code>s in this sequence
    65      * @return  the number of {@code char}s in this sequence
    66      */
    66      */
    67     int length();
    67     int length();
    68 
    68 
    69     /**
    69     /**
    70      * Returns the <code>char</code> value at the specified index.  An index ranges from zero
    70      * Returns the {@code char} value at the specified index.  An index ranges from zero
    71      * to <tt>length() - 1</tt>.  The first <code>char</code> value of the sequence is at
    71      * to {@code length() - 1}.  The first {@code char} value of the sequence is at
    72      * index zero, the next at index one, and so on, as for array
    72      * index zero, the next at index one, and so on, as for array
    73      * indexing.
    73      * indexing.
    74      *
    74      *
    75      * <p>If the <code>char</code> value specified by the index is a
    75      * <p>If the {@code char} value specified by the index is a
    76      * <a href="{@docRoot}/java/lang/Character.html#unicode">surrogate</a>, the surrogate
    76      * <a href="{@docRoot}/java/lang/Character.html#unicode">surrogate</a>, the surrogate
    77      * value is returned.
    77      * value is returned.
    78      *
    78      *
    79      * @param   index   the index of the <code>char</code> value to be returned
    79      * @param   index   the index of the {@code char} value to be returned
    80      *
    80      *
    81      * @return  the specified <code>char</code> value
    81      * @return  the specified {@code char} value
    82      *
    82      *
    83      * @throws  IndexOutOfBoundsException
    83      * @throws  IndexOutOfBoundsException
    84      *          if the <tt>index</tt> argument is negative or not less than
    84      *          if the {@code index} argument is negative or not less than
    85      *          <tt>length()</tt>
    85      *          {@code length()}
    86      */
    86      */
    87     char charAt(int index);
    87     char charAt(int index);
    88 
    88 
    89     /**
    89     /**
    90      * Returns a <code>CharSequence</code> that is a subsequence of this sequence.
    90      * Returns a {@code CharSequence} that is a subsequence of this sequence.
    91      * The subsequence starts with the <code>char</code> value at the specified index and
    91      * The subsequence starts with the {@code char} value at the specified index and
    92      * ends with the <code>char</code> value at index <tt>end - 1</tt>.  The length
    92      * ends with the {@code char} value at index {@code end - 1}.  The length
    93      * (in <code>char</code>s) of the
    93      * (in {@code char}s) of the
    94      * returned sequence is <tt>end - start</tt>, so if <tt>start == end</tt>
    94      * returned sequence is {@code end - start}, so if {@code start == end}
    95      * then an empty sequence is returned.
    95      * then an empty sequence is returned.
    96      *
    96      *
    97      * @param   start   the start index, inclusive
    97      * @param   start   the start index, inclusive
    98      * @param   end     the end index, exclusive
    98      * @param   end     the end index, exclusive
    99      *
    99      *
   100      * @return  the specified subsequence
   100      * @return  the specified subsequence
   101      *
   101      *
   102      * @throws  IndexOutOfBoundsException
   102      * @throws  IndexOutOfBoundsException
   103      *          if <tt>start</tt> or <tt>end</tt> are negative,
   103      *          if {@code start} or {@code end} are negative,
   104      *          if <tt>end</tt> is greater than <tt>length()</tt>,
   104      *          if {@code end} is greater than {@code length()},
   105      *          or if <tt>start</tt> is greater than <tt>end</tt>
   105      *          or if {@code start} is greater than {@code end}
   106      */
   106      */
   107     CharSequence subSequence(int start, int end);
   107     CharSequence subSequence(int start, int end);
   108 
   108 
   109     /**
   109     /**
   110      * Returns a string containing the characters in this sequence in the same
   110      * Returns a string containing the characters in this sequence in the same