1. /*
  2. * @(#)CharSequence.java 1.8 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.lang;
  8. /**
  9. * A <tt>CharSequence</tt> is a readable sequence of <code>char</code> values. This
  10. * interface provides uniform, read-only access to many different kinds of
  11. * <code>char</code> sequences.
  12. * A <code>char</code> value represents a character in the <i>Basic
  13. * Multilingual Plane (BMP)</i> or a surrogate. Refer to <a
  14. * href="Character.html#unicode">Unicode Character Representation</a> for details.
  15. *
  16. * <p> This interface does not refine the general contracts of the {@link
  17. * java.lang.Object#equals(java.lang.Object) equals} and {@link
  18. * java.lang.Object#hashCode() hashCode} methods. The result of comparing two
  19. * objects that implement <tt>CharSequence</tt> is therefore, in general,
  20. * undefined. Each object may be implemented by a different class, and there
  21. * is no guarantee that each class will be capable of testing its instances
  22. * for equality with those of the other. It is therefore inappropriate to use
  23. * arbitrary <tt>CharSequence</tt> instances as elements in a set or as keys in
  24. * a map. </p>
  25. *
  26. * @author Mike McCloskey
  27. * @version 1.8 03/12/19
  28. * @since 1.4
  29. * @spec JSR-51
  30. */
  31. public interface CharSequence {
  32. /**
  33. * Returns the length of this character sequence. The length is the number
  34. * of 16-bit <code>char</code>s in the sequence.</p>
  35. *
  36. * @return the number of <code>char</code>s in this sequence
  37. */
  38. int length();
  39. /**
  40. * Returns the <code>char</code> value at the specified index. An index ranges from zero
  41. * to <tt>length() - 1</tt>. The first <code>char</code> value of the sequence is at
  42. * index zero, the next at index one, and so on, as for array
  43. * indexing. </p>
  44. *
  45. * <p>If the <code>char</code> value specified by the index is a
  46. * <a href="Character.html#unicode">surrogate</a>, the surrogate
  47. * value is returned.
  48. *
  49. * @param index the index of the <code>char</code> value to be returned
  50. *
  51. * @return the specified <code>char</code> value
  52. *
  53. * @throws IndexOutOfBoundsException
  54. * if the <tt>index</tt> argument is negative or not less than
  55. * <tt>length()</tt>
  56. */
  57. char charAt(int index);
  58. /**
  59. * Returns a new <code>CharSequence</code> that is a subsequence of this sequence.
  60. * The subsequence starts with the <code>char</code> value at the specified index and
  61. * ends with the <code>char</code> value at index <tt>end - 1</tt>. The length
  62. * (in <code>char</code>s) of the
  63. * returned sequence is <tt>end - start</tt>, so if <tt>start == end</tt>
  64. * then an empty sequence is returned. </p>
  65. *
  66. * @param start the start index, inclusive
  67. * @param end the end index, exclusive
  68. *
  69. * @return the specified subsequence
  70. *
  71. * @throws IndexOutOfBoundsException
  72. * if <tt>start</tt> or <tt>end</tt> are negative,
  73. * if <tt>end</tt> is greater than <tt>length()</tt>,
  74. * or if <tt>start</tt> is greater than <tt>end</tt>
  75. */
  76. CharSequence subSequence(int start, int end);
  77. /**
  78. * Returns a string containing the characters in this sequence in the same
  79. * order as this sequence. The length of the string will be the length of
  80. * this sequence. </p>
  81. *
  82. * @return a string consisting of exactly this sequence of characters
  83. */
  84. public String toString();
  85. }