rt/emul/compact/src/main/java/java/text/Annotation.java
author Jaroslav Tulach <jtulach@netbeans.org>
Thu, 03 Oct 2013 15:40:35 +0200
branchjdk7-b147
changeset 1334 588d5bf7a560
permissions -rw-r--r--
Set of JDK classes needed to run javac
jtulach@1334
     1
/*
jtulach@1334
     2
 * Copyright (c) 1997, 2002, Oracle and/or its affiliates. All rights reserved.
jtulach@1334
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jtulach@1334
     4
 *
jtulach@1334
     5
 * This code is free software; you can redistribute it and/or modify it
jtulach@1334
     6
 * under the terms of the GNU General Public License version 2 only, as
jtulach@1334
     7
 * published by the Free Software Foundation.  Oracle designates this
jtulach@1334
     8
 * particular file as subject to the "Classpath" exception as provided
jtulach@1334
     9
 * by Oracle in the LICENSE file that accompanied this code.
jtulach@1334
    10
 *
jtulach@1334
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
jtulach@1334
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jtulach@1334
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
jtulach@1334
    14
 * version 2 for more details (a copy is included in the LICENSE file that
jtulach@1334
    15
 * accompanied this code).
jtulach@1334
    16
 *
jtulach@1334
    17
 * You should have received a copy of the GNU General Public License version
jtulach@1334
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
jtulach@1334
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jtulach@1334
    20
 *
jtulach@1334
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jtulach@1334
    22
 * or visit www.oracle.com if you need additional information or have any
jtulach@1334
    23
 * questions.
jtulach@1334
    24
 */
jtulach@1334
    25
jtulach@1334
    26
package java.text;
jtulach@1334
    27
jtulach@1334
    28
/**
jtulach@1334
    29
* An Annotation object is used as a wrapper for a text attribute value if
jtulach@1334
    30
* the attribute has annotation characteristics. These characteristics are:
jtulach@1334
    31
* <ul>
jtulach@1334
    32
* <li>The text range that the attribute is applied to is critical to the
jtulach@1334
    33
* semantics of the range. That means, the attribute cannot be applied to subranges
jtulach@1334
    34
* of the text range that it applies to, and, if two adjacent text ranges have
jtulach@1334
    35
* the same value for this attribute, the attribute still cannot be applied to
jtulach@1334
    36
* the combined range as a whole with this value.
jtulach@1334
    37
* <li>The attribute or its value usually do no longer apply if the underlying text is
jtulach@1334
    38
* changed.
jtulach@1334
    39
* </ul>
jtulach@1334
    40
*
jtulach@1334
    41
* An example is grammatical information attached to a sentence:
jtulach@1334
    42
* For the previous sentence, you can say that "an example"
jtulach@1334
    43
* is the subject, but you cannot say the same about "an", "example", or "exam".
jtulach@1334
    44
* When the text is changed, the grammatical information typically becomes invalid.
jtulach@1334
    45
* Another example is Japanese reading information (yomi).
jtulach@1334
    46
*
jtulach@1334
    47
* <p>
jtulach@1334
    48
* Wrapping the attribute value into an Annotation object guarantees that
jtulach@1334
    49
* adjacent text runs don't get merged even if the attribute values are equal,
jtulach@1334
    50
* and indicates to text containers that the attribute should be discarded if
jtulach@1334
    51
* the underlying text is modified.
jtulach@1334
    52
*
jtulach@1334
    53
* @see AttributedCharacterIterator
jtulach@1334
    54
* @since 1.2
jtulach@1334
    55
*/
jtulach@1334
    56
jtulach@1334
    57
public class Annotation {
jtulach@1334
    58
jtulach@1334
    59
    /**
jtulach@1334
    60
     * Constructs an annotation record with the given value, which
jtulach@1334
    61
     * may be null.
jtulach@1334
    62
     * @param value The value of the attribute
jtulach@1334
    63
     */
jtulach@1334
    64
    public Annotation(Object value) {
jtulach@1334
    65
        this.value = value;
jtulach@1334
    66
    }
jtulach@1334
    67
jtulach@1334
    68
    /**
jtulach@1334
    69
     * Returns the value of the attribute, which may be null.
jtulach@1334
    70
     */
jtulach@1334
    71
    public Object getValue() {
jtulach@1334
    72
        return value;
jtulach@1334
    73
    }
jtulach@1334
    74
jtulach@1334
    75
    /**
jtulach@1334
    76
     * Returns the String representation of this Annotation.
jtulach@1334
    77
     */
jtulach@1334
    78
    public String toString() {
jtulach@1334
    79
        return getClass().getName() + "[value=" + value + "]";
jtulach@1334
    80
    }
jtulach@1334
    81
jtulach@1334
    82
    private Object value;
jtulach@1334
    83
jtulach@1334
    84
};