source: trunk/gcc/libjava/java/text/AttributedCharacterIterator.java

Last change on this file was 2, checked in by bird, 22 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 9.8 KB
Line 
1/* AttributedCharacterIterator.java -- Iterate over attributes
2 Copyright (C) 1998, 1999 Free Software Foundation, Inc.
3
4This file is part of GNU Classpath.
5
6GNU Classpath is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU Classpath is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Classpath; see the file COPYING. If not, write to the
18Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
1902111-1307 USA.
20
21Linking this library statically or dynamically with other modules is
22making a combined work based on this library. Thus, the terms and
23conditions of the GNU General Public License cover the whole
24combination.
25
26As a special exception, the copyright holders of this library give you
27permission to link this library with independent modules to produce an
28executable, regardless of the license terms of these independent
29modules, and to copy and distribute the resulting executable under
30terms of your choice, provided that you also meet, for each linked
31independent module, the terms and conditions of the license of that
32module. An independent module is a module which is not derived from
33or based on this library. If you modify this library, you may extend
34this exception to your version of the library, but you are not
35obligated to do so. If you do not wish to do so, delete this
36exception statement from your version. */
37
38
39package java.text;
40
41import java.io.Serializable;
42import java.io.InvalidObjectException;
43import java.util.Set;
44import java.util.Map;
45
46/**
47 * This interface extends the <code>CharacterIterator</code> interface
48 * in order to support iteration over character attributes as well as
49 * over the characters themselves.
50 * <p>
51 * In addition to attributes of specific characters, this interface
52 * supports the concept of the "attribute run", which is an attribute
53 * that is defined for a particular value across an entire range of
54 * characters or which is undefined over a range of characters.
55 *
56 * @version 0.0
57 *
58 * @author Aaron M. Renn (arenn@urbanophile.com)
59 */
60public interface AttributedCharacterIterator extends CharacterIterator
61{
62
63/*
64 * Inner Classes
65 */
66
67/**
68 * This class defines attribute keys that are used as text attributes.
69 */
70public static class Attribute implements Serializable
71{
72
73/*************************************************************************/
74
75/*
76 * Static Variables
77 */
78
79/**
80 * This is the attribute for the language of the text. The value of
81 * attributes of this key type are instances of <code>Locale</code>.
82 */
83public static final Attribute LANGUAGE = new Attribute("LANGUAGE");
84
85/**
86 * This is the attribute for the reading form of text. This is used
87 * for storing pronunciation along with the written text for languages
88 * which need it. The value of attributes of this key type are
89 * instances of <code>Annotation</code> which wrappers a <code>String</code>.
90 */
91public static final Attribute READING = new Attribute("READING");
92
93/**
94 * This is the attribute for input method segments. The value of attributes
95 * of this key type are instances of <code>Annotation</code> which wrapper
96 * a <code>String</code>.
97 */
98public static final Attribute INPUT_METHOD_SEGMENT =
99 new Attribute("INPUT_METHOD_SEGMENT");
100
101/*************************************************************************/
102
103/*
104 * Instance Variables
105 */
106
107/**
108 * This is the name of the attribute key
109 * @serial
110 */
111private String name;
112
113/*************************************************************************/
114
115/*
116 * Constructors
117 */
118
119/**
120 * This method initializes a new instance of this class with the specified
121 * name.
122 *
123 * @param name The name of this attribute key.
124 */
125protected
126Attribute(String name)
127{
128 this.name = name;
129}
130
131/*************************************************************************/
132
133/*
134 * Instance Methods
135 */
136
137/**
138 * This method returns the name of this attribute.
139 *
140 * @return The attribute name
141 */
142protected String
143getName()
144{
145 return(name);
146}
147
148/*************************************************************************/
149
150/**
151 * This method resolves an instance of <code>AttributedCharacterIterator.Attribute</code>
152 * that is being deserialized to one of the three pre-defined attribute
153 * constants. It does this by comparing the names of the attributes. The
154 * constant that the deserialized object resolves to is returned.
155 *
156 * @return The resolved contant value
157 *
158 * @exception InvalidObjectException If the object being deserialized cannot be resolved.
159 */
160protected Object
161readResolve() throws InvalidObjectException
162{
163 if (this.equals(READING))
164 return(READING);
165
166 if (this.equals(LANGUAGE))
167 return(LANGUAGE);
168
169 if (this.equals(INPUT_METHOD_SEGMENT))
170 return(INPUT_METHOD_SEGMENT);
171
172 throw new InvalidObjectException("Can't resolve Attribute: " + getName());
173}
174
175/*************************************************************************/
176
177/**
178 * This method tests this object for equality against the specified object.
179 * The two objects will be considered equal if and only if:
180 * <ul>
181 * <li>The specified object is not <code>null</code>.
182 * <li>The specified object is an instance of <code>AttributedCharacterIterator.Attribute</code>.
183 * <li>The specified object has the same attribute name as this object.
184 * </ul>
185 *
186 * @param The <code>Object</code> to test for equality against this object.
187 *
188 * @return <code>true</code> if the specified object is equal to this one, <code>false</code> otherwise.
189 */
190public final boolean
191equals(Object obj)
192{
193 if (obj == this)
194 return(true);
195 else
196 return(false);
197}
198
199/*************************************************************************/
200
201/**
202 * This method returns a hash value for this object.
203 *
204 * @return A hash value for this object.
205 */
206public final int
207hashCode()
208{
209 return(super.hashCode());
210}
211
212/*************************************************************************/
213
214/**
215 * This method returns a <code>String</code> representation of this object.
216 *
217 * @return A <code>String</code> representation of this object.
218 */
219public String
220toString()
221{
222 return(getClass().getName() + "(" + getName() + ")");
223}
224
225} // Inner class Attribute
226
227/*************************************************************************/
228
229/*
230 * Instance Methods
231 */
232
233/**
234 * This method returns a list of all keys that are defined for the
235 * text range. This can be an empty list if no attributes are defined.
236 *
237 * @return A list of keys
238 */
239public abstract Set
240getAllAttributeKeys();
241
242/*************************************************************************/
243
244/**
245 * This method returns a <code>Map</code> of the attributed defined for
246 * the current character.
247 *
248 * @return A <code>Map</code> of the attributes for the current character.
249 */
250public abstract Map
251getAttributes();
252
253/*************************************************************************/
254
255/**
256 * This method returns the value of the specified attribute for the
257 * current character. If the attribute is not defined for the current
258 * character, <code>null</code> is returned.
259 *
260 * @param attrib The attribute to retrieve the value of.
261 *
262 * @return The value of the specified attribute
263 */
264public abstract Object
265getAttribute(AttributedCharacterIterator.Attribute attrib);
266
267/*************************************************************************/
268
269/**
270 * This method returns the index of the first character in the run that
271 * contains all attributes defined for the current character.
272 *
273 * @return The start index of the run
274 */
275public abstract int
276getRunStart();
277
278/*************************************************************************/
279
280/**
281 * This method returns the index of the first character in the run that
282 * contains all attributes in the specified <code>Set</code> defined for
283 * the current character.
284 *
285 * @param attribs The <code>Set</code> of attributes.
286 *
287 * @return The start index of the run.
288 */
289public abstract int
290getRunStart(Set attribs);
291
292/*************************************************************************/
293
294/**
295 * This method returns the index of the first character in the run that
296 * contains the specified attribute defined for the current character.
297 *
298 * @param attrib The attribute.
299 *
300 * @return The start index of the run.
301 */
302public abstract int
303getRunStart(AttributedCharacterIterator.Attribute attrib);
304
305/*************************************************************************/
306
307/**
308 * This method returns the index of the character after the end of the run
309 * that contains all attributed defined for the current character.
310 *
311 * @return The end index of the run.
312 */
313public abstract int
314getRunLimit();
315
316/*************************************************************************/
317
318/**
319 * This method returns the index of the character after the end of the run
320 * that contains all attributes in the specified <code>Set</code> defined
321 * for the current character.
322 *
323 * @param attribs The <code>Set</code> of attributes.
324 *
325 * @return The end index of the run.
326 */
327public abstract int
328getRunLimit(Set attribs);
329
330/*************************************************************************/
331
332/**
333 * This methods returns the index of the character after the end of the run
334 * that contains the specified attribute defined for the current character.
335 *
336 * @param attrib The attribute.
337 *
338 * @return The end index of the run.
339 */
340public abstract int
341getRunLimit(AttributedCharacterIterator.Attribute attrib);
342
343} // interface AttributedCharacterIterator
344
Note: See TracBrowser for help on using the repository browser.