2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.lib.editor.util;
45
* Abstract implementation of character sequence
46
* with {@link String}-like implementation
47
* of <CODE>hashCode()</CODE> and <CODE>equals()</CODE>.
49
* @author Miloslav Metelka
53
public abstract class AbstractCharSequence implements CharSequence {
56
* Returns the length of this character sequence. The length is the number
57
* of 16-bit Unicode characters in the sequence. </p>
59
* @return the number of characters in this sequence
61
public abstract int length();
64
* Returns the character at the specified index. An index ranges from zero
65
* to <tt>length() - 1</tt>. The first character of the sequence is at
66
* index zero, the next at index one, and so on, as for array
69
* @param index the index of the character to be returned
71
* @return the specified character
73
* @throws IndexOutOfBoundsException
74
* if the <tt>index</tt> argument is negative or not less than
77
public abstract char charAt(int index);
80
private String toString(int start, int end) {
81
return CharSequenceUtilities.toString(this, start, end);
85
* Return subsequence of this character sequence.
86
* The returned character sequence is only as stable as is this character
89
* @param start >=0 starting index of the subsequence within this
91
* @param end >=0 ending index of the subsequence within this
94
public CharSequence subSequence(int start, int end) {
95
return new CharSubSequence(this, start, end);
98
public String toString() {
99
return toString(0, length());
103
* Subclass providing string-like implementation
104
* of <code>hashCode()</code> and <code>equals()</code>
105
* method accepting strings with the same content
106
* like charsequence has.
108
* This makes the class suitable for matching to strings
111
* <b>NOTE</b>: Matching is just uni-directional
112
* i.e. charsequence.equals(string) works
113
* but string.equals(charsequence) does not.
115
public static abstract class StringLike extends AbstractCharSequence {
117
public int hashCode() {
118
return CharSequenceUtilities.stringLikeHashCode(this);
121
public boolean equals(Object o) {
122
return CharSequenceUtilities.equals(this, o);
125
public CharSequence subSequence(int start, int end) {
126
return new CharSubSequence.StringLike(this, start, end);