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