author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 25859 | jdk/src/java.base/share/classes/java/text/AttributedCharacterIterator.java@3317bb8137f4 |
child 57956 | e0b8b019d2f5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
14342
diff
changeset
|
2 |
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.text; |
|
27 |
||
28 |
import java.io.InvalidObjectException; |
|
29 |
import java.io.Serializable; |
|
30 |
import java.util.HashMap; |
|
31 |
import java.util.Map; |
|
32 |
import java.util.Set; |
|
33 |
||
34 |
/** |
|
7503
44968dff12a7
6203034: [AC] AttributedCharacterIterator methods works wrong (run with respect differs from spec)
okutsu
parents:
5506
diff
changeset
|
35 |
* An {@code AttributedCharacterIterator} allows iteration through both text and |
2 | 36 |
* related attribute information. |
37 |
* |
|
38 |
* <p> |
|
39 |
* An attribute is a key/value pair, identified by the key. No two |
|
40 |
* attributes on a given character can have the same key. |
|
41 |
* |
|
42 |
* <p>The values for an attribute are immutable, or must not be mutated |
|
43 |
* by clients or storage. They are always passed by reference, and not |
|
44 |
* cloned. |
|
45 |
* |
|
46 |
* <p>A <em>run with respect to an attribute</em> is a maximum text range for |
|
47 |
* which: |
|
48 |
* <ul> |
|
7503
44968dff12a7
6203034: [AC] AttributedCharacterIterator methods works wrong (run with respect differs from spec)
okutsu
parents:
5506
diff
changeset
|
49 |
* <li>the attribute is undefined or {@code null} for the entire range, or |
44968dff12a7
6203034: [AC] AttributedCharacterIterator methods works wrong (run with respect differs from spec)
okutsu
parents:
5506
diff
changeset
|
50 |
* <li>the attribute value is defined and has the same non-{@code null} value for the |
2 | 51 |
* entire range. |
52 |
* </ul> |
|
53 |
* |
|
54 |
* <p>A <em>run with respect to a set of attributes</em> is a maximum text range for |
|
55 |
* which this condition is met for each member attribute. |
|
56 |
* |
|
7503
44968dff12a7
6203034: [AC] AttributedCharacterIterator methods works wrong (run with respect differs from spec)
okutsu
parents:
5506
diff
changeset
|
57 |
* <p>When getting a run with no explicit attributes specified (i.e., |
44968dff12a7
6203034: [AC] AttributedCharacterIterator methods works wrong (run with respect differs from spec)
okutsu
parents:
5506
diff
changeset
|
58 |
* calling {@link #getRunStart()} and {@link #getRunLimit()}), any |
44968dff12a7
6203034: [AC] AttributedCharacterIterator methods works wrong (run with respect differs from spec)
okutsu
parents:
5506
diff
changeset
|
59 |
* contiguous text segments having the same attributes (the same set |
44968dff12a7
6203034: [AC] AttributedCharacterIterator methods works wrong (run with respect differs from spec)
okutsu
parents:
5506
diff
changeset
|
60 |
* of attribute/value pairs) are treated as separate runs if the |
44968dff12a7
6203034: [AC] AttributedCharacterIterator methods works wrong (run with respect differs from spec)
okutsu
parents:
5506
diff
changeset
|
61 |
* attributes have been given to those text segments separately. |
44968dff12a7
6203034: [AC] AttributedCharacterIterator methods works wrong (run with respect differs from spec)
okutsu
parents:
5506
diff
changeset
|
62 |
* |
2 | 63 |
* <p>The returned indexes are limited to the range of the iterator. |
64 |
* |
|
65 |
* <p>The returned attribute information is limited to runs that contain |
|
66 |
* the current character. |
|
67 |
* |
|
68 |
* <p> |
|
7503
44968dff12a7
6203034: [AC] AttributedCharacterIterator methods works wrong (run with respect differs from spec)
okutsu
parents:
5506
diff
changeset
|
69 |
* Attribute keys are instances of {@link AttributedCharacterIterator.Attribute} and its |
44968dff12a7
6203034: [AC] AttributedCharacterIterator methods works wrong (run with respect differs from spec)
okutsu
parents:
5506
diff
changeset
|
70 |
* subclasses, such as {@link java.awt.font.TextAttribute}. |
2 | 71 |
* |
72 |
* @see AttributedCharacterIterator.Attribute |
|
73 |
* @see java.awt.font.TextAttribute |
|
74 |
* @see AttributedString |
|
75 |
* @see Annotation |
|
76 |
* @since 1.2 |
|
77 |
*/ |
|
78 |
||
79 |
public interface AttributedCharacterIterator extends CharacterIterator { |
|
80 |
||
81 |
/** |
|
82 |
* Defines attribute keys that are used to identify text attributes. These |
|
7503
44968dff12a7
6203034: [AC] AttributedCharacterIterator methods works wrong (run with respect differs from spec)
okutsu
parents:
5506
diff
changeset
|
83 |
* keys are used in {@code AttributedCharacterIterator} and {@code AttributedString}. |
2 | 84 |
* @see AttributedCharacterIterator |
85 |
* @see AttributedString |
|
86 |
* @since 1.2 |
|
87 |
*/ |
|
88 |
||
89 |
public static class Attribute implements Serializable { |
|
90 |
||
91 |
/** |
|
7503
44968dff12a7
6203034: [AC] AttributedCharacterIterator methods works wrong (run with respect differs from spec)
okutsu
parents:
5506
diff
changeset
|
92 |
* The name of this {@code Attribute}. The name is used primarily by {@code readResolve} |
2 | 93 |
* to look up the corresponding predefined instance when deserializing |
94 |
* an instance. |
|
95 |
* @serial |
|
96 |
*/ |
|
97 |
private String name; |
|
98 |
||
99 |
// table of all instances in this class, used by readResolve |
|
12848 | 100 |
private static final Map<String, Attribute> instanceMap = new HashMap<>(7); |
2 | 101 |
|
102 |
/** |
|
7503
44968dff12a7
6203034: [AC] AttributedCharacterIterator methods works wrong (run with respect differs from spec)
okutsu
parents:
5506
diff
changeset
|
103 |
* Constructs an {@code Attribute} with the given name. |
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
14342
diff
changeset
|
104 |
* |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
14342
diff
changeset
|
105 |
* @param name the name of {@code Attribute} |
2 | 106 |
*/ |
107 |
protected Attribute(String name) { |
|
108 |
this.name = name; |
|
109 |
if (this.getClass() == Attribute.class) { |
|
110 |
instanceMap.put(name, this); |
|
111 |
} |
|
112 |
} |
|
113 |
||
114 |
/** |
|
115 |
* Compares two objects for equality. This version only returns true |
|
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
14342
diff
changeset
|
116 |
* for {@code x.equals(y)} if {@code x} and {@code y} refer |
2 | 117 |
* to the same object, and guarantees this for all subclasses. |
118 |
*/ |
|
119 |
public final boolean equals(Object obj) { |
|
120 |
return super.equals(obj); |
|
121 |
} |
|
122 |
||
123 |
/** |
|
124 |
* Returns a hash code value for the object. This version is identical to |
|
7503
44968dff12a7
6203034: [AC] AttributedCharacterIterator methods works wrong (run with respect differs from spec)
okutsu
parents:
5506
diff
changeset
|
125 |
* the one in {@code Object}, but is also final. |
2 | 126 |
*/ |
127 |
public final int hashCode() { |
|
128 |
return super.hashCode(); |
|
129 |
} |
|
130 |
||
131 |
/** |
|
132 |
* Returns a string representation of the object. This version returns the |
|
7503
44968dff12a7
6203034: [AC] AttributedCharacterIterator methods works wrong (run with respect differs from spec)
okutsu
parents:
5506
diff
changeset
|
133 |
* concatenation of class name, {@code "("}, a name identifying the attribute |
44968dff12a7
6203034: [AC] AttributedCharacterIterator methods works wrong (run with respect differs from spec)
okutsu
parents:
5506
diff
changeset
|
134 |
* and {@code ")"}. |
2 | 135 |
*/ |
136 |
public String toString() { |
|
137 |
return getClass().getName() + "(" + name + ")"; |
|
138 |
} |
|
139 |
||
140 |
/** |
|
141 |
* Returns the name of the attribute. |
|
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
14342
diff
changeset
|
142 |
* |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
14342
diff
changeset
|
143 |
* @return the name of {@code Attribute} |
2 | 144 |
*/ |
145 |
protected String getName() { |
|
146 |
return name; |
|
147 |
} |
|
148 |
||
149 |
/** |
|
150 |
* Resolves instances being deserialized to the predefined constants. |
|
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
14342
diff
changeset
|
151 |
* |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
14342
diff
changeset
|
152 |
* @return the resolved {@code Attribute} object |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
14342
diff
changeset
|
153 |
* @throws InvalidObjectException if the object to resolve is not |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
14342
diff
changeset
|
154 |
* an instance of {@code Attribute} |
2 | 155 |
*/ |
156 |
protected Object readResolve() throws InvalidObjectException { |
|
157 |
if (this.getClass() != Attribute.class) { |
|
158 |
throw new InvalidObjectException("subclass didn't correctly implement readResolve"); |
|
159 |
} |
|
160 |
||
12848 | 161 |
Attribute instance = instanceMap.get(getName()); |
2 | 162 |
if (instance != null) { |
163 |
return instance; |
|
164 |
} else { |
|
165 |
throw new InvalidObjectException("unknown attribute name"); |
|
166 |
} |
|
167 |
} |
|
168 |
||
169 |
/** |
|
170 |
* Attribute key for the language of some text. |
|
7503
44968dff12a7
6203034: [AC] AttributedCharacterIterator methods works wrong (run with respect differs from spec)
okutsu
parents:
5506
diff
changeset
|
171 |
* <p> Values are instances of {@link java.util.Locale Locale}. |
2 | 172 |
* @see java.util.Locale |
173 |
*/ |
|
174 |
public static final Attribute LANGUAGE = new Attribute("language"); |
|
175 |
||
176 |
/** |
|
177 |
* Attribute key for the reading of some text. In languages where the written form |
|
178 |
* and the pronunciation of a word are only loosely related (such as Japanese), |
|
179 |
* it is often necessary to store the reading (pronunciation) along with the |
|
180 |
* written form. |
|
7503
44968dff12a7
6203034: [AC] AttributedCharacterIterator methods works wrong (run with respect differs from spec)
okutsu
parents:
5506
diff
changeset
|
181 |
* <p>Values are instances of {@link Annotation} holding instances of {@link String}. |
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
14342
diff
changeset
|
182 |
* |
2 | 183 |
* @see Annotation |
184 |
* @see java.lang.String |
|
185 |
*/ |
|
186 |
public static final Attribute READING = new Attribute("reading"); |
|
187 |
||
188 |
/** |
|
189 |
* Attribute key for input method segments. Input methods often break |
|
190 |
* up text into segments, which usually correspond to words. |
|
7503
44968dff12a7
6203034: [AC] AttributedCharacterIterator methods works wrong (run with respect differs from spec)
okutsu
parents:
5506
diff
changeset
|
191 |
* <p>Values are instances of {@link Annotation} holding a {@code null} reference. |
2 | 192 |
* @see Annotation |
193 |
*/ |
|
194 |
public static final Attribute INPUT_METHOD_SEGMENT = new Attribute("input_method_segment"); |
|
195 |
||
196 |
// make sure the serial version doesn't change between compiler versions |
|
197 |
private static final long serialVersionUID = -9142742483513960612L; |
|
198 |
||
199 |
}; |
|
200 |
||
201 |
/** |
|
202 |
* Returns the index of the first character of the run |
|
203 |
* with respect to all attributes containing the current character. |
|
7503
44968dff12a7
6203034: [AC] AttributedCharacterIterator methods works wrong (run with respect differs from spec)
okutsu
parents:
5506
diff
changeset
|
204 |
* |
44968dff12a7
6203034: [AC] AttributedCharacterIterator methods works wrong (run with respect differs from spec)
okutsu
parents:
5506
diff
changeset
|
205 |
* <p>Any contiguous text segments having the same attributes (the |
44968dff12a7
6203034: [AC] AttributedCharacterIterator methods works wrong (run with respect differs from spec)
okutsu
parents:
5506
diff
changeset
|
206 |
* same set of attribute/value pairs) are treated as separate runs |
44968dff12a7
6203034: [AC] AttributedCharacterIterator methods works wrong (run with respect differs from spec)
okutsu
parents:
5506
diff
changeset
|
207 |
* if the attributes have been given to those text segments separately. |
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
14342
diff
changeset
|
208 |
* |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
14342
diff
changeset
|
209 |
* @return the index of the first character of the run |
2 | 210 |
*/ |
211 |
public int getRunStart(); |
|
212 |
||
213 |
/** |
|
214 |
* Returns the index of the first character of the run |
|
7503
44968dff12a7
6203034: [AC] AttributedCharacterIterator methods works wrong (run with respect differs from spec)
okutsu
parents:
5506
diff
changeset
|
215 |
* with respect to the given {@code attribute} containing the current character. |
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
14342
diff
changeset
|
216 |
* |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
14342
diff
changeset
|
217 |
* @param attribute the desired attribute. |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
14342
diff
changeset
|
218 |
* @return the index of the first character of the run |
2 | 219 |
*/ |
220 |
public int getRunStart(Attribute attribute); |
|
221 |
||
222 |
/** |
|
223 |
* Returns the index of the first character of the run |
|
7503
44968dff12a7
6203034: [AC] AttributedCharacterIterator methods works wrong (run with respect differs from spec)
okutsu
parents:
5506
diff
changeset
|
224 |
* with respect to the given {@code attributes} containing the current character. |
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
14342
diff
changeset
|
225 |
* |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
14342
diff
changeset
|
226 |
* @param attributes a set of the desired attributes. |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
14342
diff
changeset
|
227 |
* @return the index of the first character of the run |
2 | 228 |
*/ |
229 |
public int getRunStart(Set<? extends Attribute> attributes); |
|
230 |
||
231 |
/** |
|
232 |
* Returns the index of the first character following the run |
|
233 |
* with respect to all attributes containing the current character. |
|
7503
44968dff12a7
6203034: [AC] AttributedCharacterIterator methods works wrong (run with respect differs from spec)
okutsu
parents:
5506
diff
changeset
|
234 |
* |
44968dff12a7
6203034: [AC] AttributedCharacterIterator methods works wrong (run with respect differs from spec)
okutsu
parents:
5506
diff
changeset
|
235 |
* <p>Any contiguous text segments having the same attributes (the |
44968dff12a7
6203034: [AC] AttributedCharacterIterator methods works wrong (run with respect differs from spec)
okutsu
parents:
5506
diff
changeset
|
236 |
* same set of attribute/value pairs) are treated as separate runs |
44968dff12a7
6203034: [AC] AttributedCharacterIterator methods works wrong (run with respect differs from spec)
okutsu
parents:
5506
diff
changeset
|
237 |
* if the attributes have been given to those text segments separately. |
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
14342
diff
changeset
|
238 |
* |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
14342
diff
changeset
|
239 |
* @return the index of the first character following the run |
2 | 240 |
*/ |
241 |
public int getRunLimit(); |
|
242 |
||
243 |
/** |
|
244 |
* Returns the index of the first character following the run |
|
7503
44968dff12a7
6203034: [AC] AttributedCharacterIterator methods works wrong (run with respect differs from spec)
okutsu
parents:
5506
diff
changeset
|
245 |
* with respect to the given {@code attribute} containing the current character. |
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
14342
diff
changeset
|
246 |
* |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
14342
diff
changeset
|
247 |
* @param attribute the desired attribute |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
14342
diff
changeset
|
248 |
* @return the index of the first character following the run |
2 | 249 |
*/ |
250 |
public int getRunLimit(Attribute attribute); |
|
251 |
||
252 |
/** |
|
253 |
* Returns the index of the first character following the run |
|
7503
44968dff12a7
6203034: [AC] AttributedCharacterIterator methods works wrong (run with respect differs from spec)
okutsu
parents:
5506
diff
changeset
|
254 |
* with respect to the given {@code attributes} containing the current character. |
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
14342
diff
changeset
|
255 |
* |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
14342
diff
changeset
|
256 |
* @param attributes a set of the desired attributes |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
14342
diff
changeset
|
257 |
* @return the index of the first character following the run |
2 | 258 |
*/ |
259 |
public int getRunLimit(Set<? extends Attribute> attributes); |
|
260 |
||
261 |
/** |
|
262 |
* Returns a map with the attributes defined on the current |
|
263 |
* character. |
|
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
14342
diff
changeset
|
264 |
* |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
14342
diff
changeset
|
265 |
* @return a map with the attributes defined on the current character |
2 | 266 |
*/ |
267 |
public Map<Attribute,Object> getAttributes(); |
|
268 |
||
269 |
/** |
|
7503
44968dff12a7
6203034: [AC] AttributedCharacterIterator methods works wrong (run with respect differs from spec)
okutsu
parents:
5506
diff
changeset
|
270 |
* Returns the value of the named {@code attribute} for the current character. |
44968dff12a7
6203034: [AC] AttributedCharacterIterator methods works wrong (run with respect differs from spec)
okutsu
parents:
5506
diff
changeset
|
271 |
* Returns {@code null} if the {@code attribute} is not defined. |
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
14342
diff
changeset
|
272 |
* |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
14342
diff
changeset
|
273 |
* @param attribute the desired attribute |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
14342
diff
changeset
|
274 |
* @return the value of the named {@code attribute} or {@code null} |
2 | 275 |
*/ |
276 |
public Object getAttribute(Attribute attribute); |
|
277 |
||
278 |
/** |
|
279 |
* Returns the keys of all attributes defined on the |
|
280 |
* iterator's text range. The set is empty if no |
|
281 |
* attributes are defined. |
|
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
14342
diff
changeset
|
282 |
* |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
14342
diff
changeset
|
283 |
* @return the keys of all attributes |
2 | 284 |
*/ |
285 |
public Set<Attribute> getAllAttributeKeys(); |
|
286 |
}; |