jdk/src/share/classes/java/lang/CharSequence.java
author alanb
Fri, 02 Nov 2012 15:50:11 +0000
changeset 14342 8435a30053c1
parent 8982 19c972e3d3ee
child 17210 8a90d05f28d8
permissions -rw-r--r--
7197491: update copyright year to match last edit in jdk8 jdk repository Reviewed-by: chegar, ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 8982
diff changeset
     2
 * Copyright (c) 2000, 2011, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * A <tt>CharSequence</tt> is a readable sequence of <code>char</code> values. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * interface provides uniform, read-only access to many different kinds of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * <code>char</code> sequences.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * A <code>char</code> value represents a character in the <i>Basic
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * Multilingual Plane (BMP)</i> or a surrogate. Refer to <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * href="Character.html#unicode">Unicode Character Representation</a> for details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <p> This interface does not refine the general contracts of the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * java.lang.Object#equals(java.lang.Object) equals} and {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * java.lang.Object#hashCode() hashCode} methods.  The result of comparing two
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * objects that implement <tt>CharSequence</tt> is therefore, in general,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * undefined.  Each object may be implemented by a different class, and there
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * is no guarantee that each class will be capable of testing its instances
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * for equality with those of the other.  It is therefore inappropriate to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * arbitrary <tt>CharSequence</tt> instances as elements in a set or as keys in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * a map. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * @author Mike McCloskey
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @spec JSR-51
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 interface CharSequence {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * Returns the length of this character sequence.  The length is the number
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * of 16-bit <code>char</code>s in the sequence.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * @return  the number of <code>char</code>s in this sequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    int length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * Returns the <code>char</code> value at the specified index.  An index ranges from zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * to <tt>length() - 1</tt>.  The first <code>char</code> value of the sequence is at
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * index zero, the next at index one, and so on, as for array
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * indexing. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * <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
    69
     * <a href="{@docRoot}/java/lang/Character.html#unicode">surrogate</a>, the surrogate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * value is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * @param   index   the index of the <code>char</code> value to be returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * @return  the specified <code>char</code> value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * @throws  IndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *          if the <tt>index</tt> argument is negative or not less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     *          <tt>length()</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    char charAt(int index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * Returns a new <code>CharSequence</code> that is a subsequence of this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * The subsequence starts with the <code>char</code> value at the specified index and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * ends with the <code>char</code> value at index <tt>end - 1</tt>.  The length
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * (in <code>char</code>s) of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * returned sequence is <tt>end - start</tt>, so if <tt>start == end</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * then an empty sequence is returned. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @param   start   the start index, inclusive
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @param   end     the end index, exclusive
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @return  the specified subsequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @throws  IndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *          if <tt>start</tt> or <tt>end</tt> are negative,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     *          if <tt>end</tt> is greater than <tt>length()</tt>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *          or if <tt>start</tt> is greater than <tt>end</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    CharSequence subSequence(int start, int end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * Returns a string containing the characters in this sequence in the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * order as this sequence.  The length of the string will be the length of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * this sequence. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @return  a string consisting of exactly this sequence of characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    public String toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
}