| 1 | /* AttributedCharacterIterator.java -- Iterate over attributes
|
|---|
| 2 | Copyright (C) 1998, 1999 Free Software Foundation, Inc.
|
|---|
| 3 |
|
|---|
| 4 | This file is part of GNU Classpath.
|
|---|
| 5 |
|
|---|
| 6 | GNU Classpath is free software; you can redistribute it and/or modify
|
|---|
| 7 | it under the terms of the GNU General Public License as published by
|
|---|
| 8 | the Free Software Foundation; either version 2, or (at your option)
|
|---|
| 9 | any later version.
|
|---|
| 10 |
|
|---|
| 11 | GNU Classpath is distributed in the hope that it will be useful, but
|
|---|
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 14 | General Public License for more details.
|
|---|
| 15 |
|
|---|
| 16 | You should have received a copy of the GNU General Public License
|
|---|
| 17 | along with GNU Classpath; see the file COPYING. If not, write to the
|
|---|
| 18 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|---|
| 19 | 02111-1307 USA.
|
|---|
| 20 |
|
|---|
| 21 | Linking this library statically or dynamically with other modules is
|
|---|
| 22 | making a combined work based on this library. Thus, the terms and
|
|---|
| 23 | conditions of the GNU General Public License cover the whole
|
|---|
| 24 | combination.
|
|---|
| 25 |
|
|---|
| 26 | As a special exception, the copyright holders of this library give you
|
|---|
| 27 | permission to link this library with independent modules to produce an
|
|---|
| 28 | executable, regardless of the license terms of these independent
|
|---|
| 29 | modules, and to copy and distribute the resulting executable under
|
|---|
| 30 | terms of your choice, provided that you also meet, for each linked
|
|---|
| 31 | independent module, the terms and conditions of the license of that
|
|---|
| 32 | module. An independent module is a module which is not derived from
|
|---|
| 33 | or based on this library. If you modify this library, you may extend
|
|---|
| 34 | this exception to your version of the library, but you are not
|
|---|
| 35 | obligated to do so. If you do not wish to do so, delete this
|
|---|
| 36 | exception statement from your version. */
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 | package java.text;
|
|---|
| 40 |
|
|---|
| 41 | import java.io.Serializable;
|
|---|
| 42 | import java.io.InvalidObjectException;
|
|---|
| 43 | import java.util.Set;
|
|---|
| 44 | import 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 ([email protected])
|
|---|
| 59 | */
|
|---|
| 60 | public 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 | */
|
|---|
| 70 | public 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 | */
|
|---|
| 83 | public 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 | */
|
|---|
| 91 | public 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 | */
|
|---|
| 98 | public 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 | */
|
|---|
| 111 | private 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 | */
|
|---|
| 125 | protected
|
|---|
| 126 | Attribute(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 | */
|
|---|
| 142 | protected String
|
|---|
| 143 | getName()
|
|---|
| 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 | */
|
|---|
| 160 | protected Object
|
|---|
| 161 | readResolve() 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 | */
|
|---|
| 190 | public final boolean
|
|---|
| 191 | equals(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 | */
|
|---|
| 206 | public final int
|
|---|
| 207 | hashCode()
|
|---|
| 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 | */
|
|---|
| 219 | public String
|
|---|
| 220 | toString()
|
|---|
| 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 | */
|
|---|
| 239 | public abstract Set
|
|---|
| 240 | getAllAttributeKeys();
|
|---|
| 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 | */
|
|---|
| 250 | public abstract Map
|
|---|
| 251 | getAttributes();
|
|---|
| 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 | */
|
|---|
| 264 | public abstract Object
|
|---|
| 265 | getAttribute(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 | */
|
|---|
| 275 | public abstract int
|
|---|
| 276 | getRunStart();
|
|---|
| 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 | */
|
|---|
| 289 | public abstract int
|
|---|
| 290 | getRunStart(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 | */
|
|---|
| 302 | public abstract int
|
|---|
| 303 | getRunStart(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 | */
|
|---|
| 313 | public abstract int
|
|---|
| 314 | getRunLimit();
|
|---|
| 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 | */
|
|---|
| 327 | public abstract int
|
|---|
| 328 | getRunLimit(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 | */
|
|---|
| 340 | public abstract int
|
|---|
| 341 | getRunLimit(AttributedCharacterIterator.Attribute attrib);
|
|---|
| 342 |
|
|---|
| 343 | } // interface AttributedCharacterIterator
|
|---|
| 344 |
|
|---|