net.sf.okapi.common.annotation

## Class GenericAnnotation

- java.lang.Object
- - net.sf.okapi.common.annotation.GenericAnnotation

- Direct Known Subclasses:
    IssueAnnotation

      public class GenericAnnotation
      extends java.lang.Object

  Generic annotation allowing access with field names and multiple instance on the same object.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `GenericAnnotation(java.lang.String type)` Creates a new annotation for a given type.
    `GenericAnnotation(java.lang.String type, java.lang.Object... list)` Creates a new annotation for a given type.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `addAnnotation(Code code, GenericAnnotation ann)` Adds an annotation to an inline code.
    `static void` | `addAnnotation(ITextUnit tu, GenericAnnotation ann)` Adds an annotation to a text unit.
    `static void` | `addAnnotation(TextContainer tc, GenericAnnotation ann)` Adds an annotation to a text container.
    `GenericAnnotation` | `clone()`
    `void` | `fromString(java.lang.String storage)`
    `java.lang.Boolean` | `getBoolean(java.lang.String name)`
    `java.lang.Double` | `getDouble(java.lang.String name)`
    `int` | `getFieldCount()`
    `java.lang.Integer` | `getInteger(java.lang.String name)`
    `java.lang.String` | `getString(java.lang.String name)` Gets the string value for a given field.
    `java.lang.String` | `getType()` Gets the type of annotation.
    `void` | `setBoolean(java.lang.String name, java.lang.Boolean value)` sets a boolean field.
    `void` | `setDouble(java.lang.String name, java.lang.Double value)`
    `void` | `setFields(java.lang.Object... list)` Sets a list of key+values pairs for this annotation.
    `void` | `setInteger(java.lang.String name, java.lang.Integer value)`
    `void` | `setString(java.lang.String name, java.lang.String value)` Sets a string field.
    `java.lang.String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### GenericAnnotation

          public GenericAnnotation(java.lang.String type)

      Creates a new annotation for a given type.

      Note that it is technically to have two annotations with the same type but different fields. This is a side effect of the capability to access the annotation in a generic way. The user is responsible for keeping consistent types of annotations.

      Parameters:
        `type` - the identifier of the type (cannot be null or empty).

    - #### GenericAnnotation

          public GenericAnnotation(java.lang.String type,
                           java.lang.Object... list)

      Creates a new annotation for a given type. With a list of fields. This method simply call the `setFields(Object...)` method after creating the annotation.
      Parameters:
        `type` - the identifier of the type (cannot be null or empty).
        `list` - the list of key+value pairs to set.

  - ### Method Detail

    - #### addAnnotation

          public static void addAnnotation(ITextUnit tu,
                           GenericAnnotation ann)

      Adds an annotation to a text unit. If the text unit has no annotation set attached yet one is created and attached, otherwise the annotation to add is added to the existing set.
      Parameters:
        `tu` - the text unit where to attach the annotation.
        `ann` - the annotation to attach (if null, nothing is attached).

    - #### addAnnotation

          public static void addAnnotation(TextContainer tc,
                           GenericAnnotation ann)

      Adds an annotation to a text container. If the text container has no annotation set attached yet one is created and attached, otherwise the annotation to add is added to the existing set.
      Parameters:
        `tc` - the text container where to attach the annotation.
        `ann` - the annotation to attach (if null, nothing is attached).

    - #### addAnnotation

          public static void addAnnotation(Code code,
                           GenericAnnotation ann)

      Adds an annotation to an inline code. If the inline code has no annotation set attached yet one is created and attached, otherwise the annotation to add is added to the existing set.
      Parameters:
        `code` - the code where to add the annotation.
        `ann` - the annotation to add (if null, nothing is attached).

    - #### setFields

          public void setFields(java.lang.Object... list)

      Sets a list of key+values pairs for this annotation. Each pair must be made of a string that is the name of the field, and an object that is the value to set. The object can be null in that case: the key is not set or deleted. Only supported types must be used.
      Parameters:
        `list` - the list of key+value pairs to set.

    - #### clone

          public GenericAnnotation clone()

      Overrides:
        `clone` in class `java.lang.Object`

    - #### getType

          public java.lang.String getType()

      Gets the type of annotation.
      Returns:
        the type identifier for the annotation.

    - #### getString

          public java.lang.String getString(java.lang.String name)

      Gets the string value for a given field.
      Parameters:
        `name` - the name of the field.
      Returns:
        the field's value as a string.

    - #### setString

          public void setString(java.lang.String name,
                       java.lang.String value)

      Sets a string field.
      Parameters:
        `name` - the name of the field to set.
        `value` - the value to set, use null to remove the field.

    - #### getBoolean

          public java.lang.Boolean getBoolean(java.lang.String name)

    - #### setBoolean

          public void setBoolean(java.lang.String name,
                        java.lang.Boolean value)

      sets a boolean field.
      Parameters:
        `name` - the name of the field to set.
        `value` - the value to set, use null to remove the field.

    - #### getDouble

          public java.lang.Double getDouble(java.lang.String name)

    - #### setDouble

          public void setDouble(java.lang.String name,
                       java.lang.Double value)

    - #### getInteger

          public java.lang.Integer getInteger(java.lang.String name)

    - #### setInteger

          public void setInteger(java.lang.String name,
                        java.lang.Integer value)

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`

    - #### fromString

          public void fromString(java.lang.String storage)

    - #### getFieldCount

          public int getFieldCount()