net.sf.okapi.common.annotation

## Class GenericAnnotations

- java.lang.Object
- - net.sf.okapi.common.resource.InlineAnnotation
  - - net.sf.okapi.common.annotation.GenericAnnotations

- All Implemented Interfaces:
    java.lang.Iterable<GenericAnnotation>, IAnnotation
  Direct Known Subclasses:
    ITSLQIAnnotations, ITSProvenanceAnnotations

      public class GenericAnnotations
      extends InlineAnnotation
      implements java.lang.Iterable<GenericAnnotation>

  Provides access to a list of `GenericAnnotation`. This annotation set assumes its data field is used to store a unique ID for the set.

  This annotation can be used inline as well as on structural objects.

- - ### Field Summary

    - ### Fields inherited from class net.sf.okapi.common.resource.InlineAnnotation

      `data`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `GenericAnnotations()` Creates an empty annotation set.
    `GenericAnnotations(GenericAnnotation annotation)` Creates an annotation set and add a given one.
    `GenericAnnotations(java.lang.String storage)` Creates an annotation set initialized with a storage string created with `toString()`.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `add(GenericAnnotation annotation)` Adds an existing annotation to this object.
    `GenericAnnotation` | `add(java.lang.String type)` Creates an new annotation and add it to this object.
    `void` | `addAll(GenericAnnotations annotations)` Adds all annotations of a given set of annotations to this object.
    `void` | `addAll(java.util.List<GenericAnnotation> newItems)` Adds all the annotations from a given list to this object.
    `static void` | `addAnnotations(Code code, GenericAnnotations newSet)` Adds a set of annotations to a given inline code.
    `static void` | `addAnnotations(IWithAnnotations nameable, GenericAnnotations newSet)` Adds a set of annotations to a given INameable object (e.g.
    `void` | `clear()` Removes all annotations from this list.
    `GenericAnnotations` | `clone()` Clones this annotation and make sure its still has a unique ID.
    `void` | `fromString(java.lang.String storage)` Initializes this annotation from a storage string originally obtained from `InlineAnnotation.toString()`.
    `java.util.List<GenericAnnotation>` | `getAllAnnotations()` Gets the unmodifiable list of all the annotation in this annotation set.
    `java.util.List<GenericAnnotation>` | `getAnnotations(java.lang.String type)` Gets a list of all the annotations of a given type.
    `GenericAnnotation` | `getFirstAnnotation(java.lang.String type)` Gets the first occurrence of an annotation for a given type.
    `boolean` | `hasAnnotation(java.lang.String type)` Indicates if there is at least one annotation of a given type.
    `java.util.Iterator<GenericAnnotation>` | `iterator()`
    `void` | `remove(GenericAnnotation annotation)` Removes a given annotation from this list.
    `int` | `size()` Gets the number of annotations in this annotation set.
    `java.lang.String` | `toString()` Gets a storage string representation of the whole annotation that can be used for serialization.

    - ### Methods inherited from class net.sf.okapi.common.resource.InlineAnnotation

      `getData, setData`

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

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

- - ### Constructor Detail

    - #### GenericAnnotations

          public GenericAnnotations()

      Creates an empty annotation set.

    - #### GenericAnnotations

          public GenericAnnotations(java.lang.String storage)

      Creates an annotation set initialized with a storage string created with `toString()`.
      Parameters:
        `storage` - the storage string to use.

    - #### GenericAnnotations

          public GenericAnnotations(GenericAnnotation annotation)

      Creates an annotation set and add a given one.
      Parameters:
        `annotation` - the annotation to add.

  - ### Method Detail

    - #### addAnnotations

          public static void addAnnotations(IWithAnnotations nameable,
                            GenericAnnotations newSet)

      Adds a set of annotations to a given INameable object (e.g. TextUnit, TextContainer, etc.). If the object has no annotation set already attached, one is created and attached, otherwise all the annotations of the set passed as argument are added to the existing set.
      Parameters:
        `nameable` - the object where to attached the new set.
        `newSet` - the new set to add (can be null: then nothing is attached).

    - #### addAnnotations

          public static void addAnnotations(Code code,
                            GenericAnnotations newSet)

      Adds a set of annotations to a given inline code. If the inline code has no annotation set attached yet one is created and attached, otherwise all the annotations of the set passed as argument are added to the existing set.
      Parameters:
        `code` - the code where to add the annotation.
        `newSet` - the new set to add (can be null: then nothing is attached).

    - #### clone

          public GenericAnnotations clone()

      Clones this annotation and make sure its still has a unique ID.
      Overrides:
        `clone` in class `InlineAnnotation`
      Returns:
        A new InlineAnnotation object that is a copy of this one.

    - #### size

          public int size()

      Gets the number of annotations in this annotation set.
      Returns:
        the number of annotations in this annotation set.

    - #### getAnnotations

          public java.util.List<GenericAnnotation> getAnnotations(java.lang.String type)

      Gets a list of all the annotations of a given type.

      The returned list is a new list but its items are the same as the items in the original list.

      Parameters:
        `type` - the type of annotation to look for.
      Returns:
        the list of all annotations of the given type, the list may be empty but is never null.

    - #### getFirstAnnotation

          public GenericAnnotation getFirstAnnotation(java.lang.String type)

      Gets the first occurrence of an annotation for a given type.
      Parameters:
        `type` - the type of annotation to retrieve.
      Returns:
        the first annotation of the given type, or null if none exists.

    - #### getAllAnnotations

          public java.util.List<GenericAnnotation> getAllAnnotations()

      Gets the unmodifiable list of all the annotation in this annotation set.
      Returns:
        the live list, or an empty one if there are no annotations.

    - #### hasAnnotation

          public boolean hasAnnotation(java.lang.String type)

      Indicates if there is at least one annotation of a given type.
      Parameters:
        `type` - the type of annotation to look for.
      Returns:
        true if there is at least one annotation of a given type, false otherwise.

    - #### clear

          public void clear()

      Removes all annotations from this list.

    - #### remove

          public void remove(GenericAnnotation annotation)

      Removes a given annotation from this list.
      Parameters:
        `annotation` - the annotation to remove.

    - #### add

          public GenericAnnotation add(java.lang.String type)

      Creates an new annotation and add it to this object.
      Parameters:
        `type` - the type of annotation to create.
      Returns:
        the new annotation.

    - #### add

          public void add(GenericAnnotation annotation)

      Adds an existing annotation to this object.
      Parameters:
        `annotation` - the annotation to add.

    - #### addAll

          public void addAll(GenericAnnotations annotations)

      Adds all annotations of a given set of annotations to this object.
      Parameters:
        `annotations` - the set of annotations to add.

    - #### addAll

          public void addAll(java.util.List<GenericAnnotation> newItems)

      Adds all the annotations from a given list to this object.
      Parameters:
        `newItems` - the list of annotations to add.

    - #### toString

          public java.lang.String toString()

      Description copied from class: `InlineAnnotation`
      Gets a storage string representation of the whole annotation that can be used for serialization.
      Specified by:
        `toString` in interface `IAnnotation`
      Overrides:
        `toString` in class `InlineAnnotation`
      Returns:
        The storage string representation of this annotation.

    - #### fromString

          public void fromString(java.lang.String storage)

      Description copied from class: `InlineAnnotation`
      Initializes this annotation from a storage string originally obtained from `InlineAnnotation.toString()`.
      Overrides:
        `fromString` in class `InlineAnnotation`
      Parameters:
        `storage` - The storage string to use for the initialization.

    - #### iterator

          public java.util.Iterator<GenericAnnotation> iterator()

      Specified by:
        `iterator` in interface `java.lang.Iterable<GenericAnnotation>`