J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 1997-2002 Sun Microsystems, Inc. All Rights Reserved. |
| 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 |
| 7 | * published by the Free Software Foundation. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun in the LICENSE file that accompanied this code. |
| 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 | * |
| 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | package java.text; |
| 27 | |
| 28 | /** |
| 29 | * An Annotation object is used as a wrapper for a text attribute value if |
| 30 | * the attribute has annotation characteristics. These characteristics are: |
| 31 | * <ul> |
| 32 | * <li>The text range that the attribute is applied to is critical to the |
| 33 | * semantics of the range. That means, the attribute cannot be applied to subranges |
| 34 | * of the text range that it applies to, and, if two adjacent text ranges have |
| 35 | * the same value for this attribute, the attribute still cannot be applied to |
| 36 | * the combined range as a whole with this value. |
| 37 | * <li>The attribute or its value usually do no longer apply if the underlying text is |
| 38 | * changed. |
| 39 | * </ul> |
| 40 | * |
| 41 | * An example is grammatical information attached to a sentence: |
| 42 | * For the previous sentence, you can say that "an example" |
| 43 | * is the subject, but you cannot say the same about "an", "example", or "exam". |
| 44 | * When the text is changed, the grammatical information typically becomes invalid. |
| 45 | * Another example is Japanese reading information (yomi). |
| 46 | * |
| 47 | * <p> |
| 48 | * Wrapping the attribute value into an Annotation object guarantees that |
| 49 | * adjacent text runs don't get merged even if the attribute values are equal, |
| 50 | * and indicates to text containers that the attribute should be discarded if |
| 51 | * the underlying text is modified. |
| 52 | * |
| 53 | * @see AttributedCharacterIterator |
| 54 | * @since 1.2 |
| 55 | */ |
| 56 | |
| 57 | public class Annotation { |
| 58 | |
| 59 | /** |
| 60 | * Constructs an annotation record with the given value, which |
| 61 | * may be null. |
| 62 | * @param value The value of the attribute |
| 63 | */ |
| 64 | public Annotation(Object value) { |
| 65 | this.value = value; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Returns the value of the attribute, which may be null. |
| 70 | */ |
| 71 | public Object getValue() { |
| 72 | return value; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Returns the String representation of this Annotation. |
| 77 | */ |
| 78 | public String toString() { |
| 79 | return getClass().getName() + "[value=" + value + "]"; |
| 80 | } |
| 81 | |
| 82 | private Object value; |
| 83 | |
| 84 | }; |