jdk/src/share/classes/java/lang/CharSequence.java
changeset 2 90ce3da70b43
child 5506 202f599c92aa
equal deleted inserted replaced
0:fd16c54261b3 2:90ce3da70b43
       
     1 /*
       
     2  * Copyright 2000-2003 Sun Microsystems, Inc.  All Rights Reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.  Sun designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Sun in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    22  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    23  * have any questions.
       
    24  */
       
    25 
       
    26 package java.lang;
       
    27 
       
    28 
       
    29 /**
       
    30  * A <tt>CharSequence</tt> is a readable sequence of <code>char</code> values. This
       
    31  * interface provides uniform, read-only access to many different kinds of
       
    32  * <code>char</code> sequences.
       
    33  * A <code>char</code> value represents a character in the <i>Basic
       
    34  * Multilingual Plane (BMP)</i> or a surrogate. Refer to <a
       
    35  * href="Character.html#unicode">Unicode Character Representation</a> for details.
       
    36  *
       
    37  * <p> This interface does not refine the general contracts of the {@link
       
    38  * java.lang.Object#equals(java.lang.Object) equals} and {@link
       
    39  * java.lang.Object#hashCode() hashCode} methods.  The result of comparing two
       
    40  * objects that implement <tt>CharSequence</tt> is therefore, in general,
       
    41  * undefined.  Each object may be implemented by a different class, and there
       
    42  * is no guarantee that each class will be capable of testing its instances
       
    43  * for equality with those of the other.  It is therefore inappropriate to use
       
    44  * arbitrary <tt>CharSequence</tt> instances as elements in a set or as keys in
       
    45  * a map. </p>
       
    46  *
       
    47  * @author Mike McCloskey
       
    48  * @since 1.4
       
    49  * @spec JSR-51
       
    50  */
       
    51 
       
    52 public interface CharSequence {
       
    53 
       
    54     /**
       
    55      * Returns the length of this character sequence.  The length is the number
       
    56      * of 16-bit <code>char</code>s in the sequence.</p>
       
    57      *
       
    58      * @return  the number of <code>char</code>s in this sequence
       
    59      */
       
    60     int length();
       
    61 
       
    62     /**
       
    63      * Returns the <code>char</code> value at the specified index.  An index ranges from zero
       
    64      * to <tt>length() - 1</tt>.  The first <code>char</code> value of the sequence is at
       
    65      * index zero, the next at index one, and so on, as for array
       
    66      * indexing. </p>
       
    67      *
       
    68      * <p>If the <code>char</code> value specified by the index is a
       
    69      * <a href="Character.html#unicode">surrogate</a>, the surrogate
       
    70      * value is returned.
       
    71      *
       
    72      * @param   index   the index of the <code>char</code> value to be returned
       
    73      *
       
    74      * @return  the specified <code>char</code> value
       
    75      *
       
    76      * @throws  IndexOutOfBoundsException
       
    77      *          if the <tt>index</tt> argument is negative or not less than
       
    78      *          <tt>length()</tt>
       
    79      */
       
    80     char charAt(int index);
       
    81 
       
    82     /**
       
    83      * Returns a new <code>CharSequence</code> that is a subsequence of this sequence.
       
    84      * The subsequence starts with the <code>char</code> value at the specified index and
       
    85      * ends with the <code>char</code> value at index <tt>end - 1</tt>.  The length
       
    86      * (in <code>char</code>s) of the
       
    87      * returned sequence is <tt>end - start</tt>, so if <tt>start == end</tt>
       
    88      * then an empty sequence is returned. </p>
       
    89      *
       
    90      * @param   start   the start index, inclusive
       
    91      * @param   end     the end index, exclusive
       
    92      *
       
    93      * @return  the specified subsequence
       
    94      *
       
    95      * @throws  IndexOutOfBoundsException
       
    96      *          if <tt>start</tt> or <tt>end</tt> are negative,
       
    97      *          if <tt>end</tt> is greater than <tt>length()</tt>,
       
    98      *          or if <tt>start</tt> is greater than <tt>end</tt>
       
    99      */
       
   100     CharSequence subSequence(int start, int end);
       
   101 
       
   102     /**
       
   103      * Returns a string containing the characters in this sequence in the same
       
   104      * order as this sequence.  The length of the string will be the length of
       
   105      * this sequence. </p>
       
   106      *
       
   107      * @return  a string consisting of exactly this sequence of characters
       
   108      */
       
   109     public String toString();
       
   110 
       
   111 }