net.sf.okapi.lib.xliff2.core

## Class Tags

- java.lang.Object
- - net.sf.okapi.lib.xliff2.core.Tags

- All Implemented Interfaces:
    java.lang.Iterable<Tag>

      public class Tags
      extends java.lang.Object
      implements java.lang.Iterable<Tag>

  Represents a collection of tags for a specific content.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Tags(Store store)` Creates a new `Tags` object.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `add(PCont tag)` Adds a protected content tag to this object.
    `int` | `add(Tag tag)` Adds a tag to this collection.
    `Tag` | `get(java.lang.CharSequence ctext, int pos)` Gets the `MTag` or `CTag` for a given reference in a coded text.
    `Tag` | `get(int key)` Gets the `MTag` or `CTag` for a given key.
    `Tag` | `get(java.lang.String id, TagType tagType)` Gets the tag for a given id and tag type.
    `Tag` | `getClosingTag(java.lang.String id)` Gets the closing tag for a given tag ID.
    `Tag` | `getClosingTag(Tag openingTag)` Gets the closing tag for a given opening tag.
    `CTag` | `getCTag(java.lang.CharSequence ctext, int pos)` Gets the `CTag` for a given reference in a coded text.
    `CTag` | `getCTag(int key)` Gets the `CTag` for a given key.
    `int` | `getKey(Tag tag)` Gets the key for a given code or marker.
    `MTag` | `getMTag(java.lang.CharSequence ctext, int pos)` Gets the `MTag` for a given reference in a coded text.
    `MTag` | `getMTag(int key)` Gets the `MTag` for a given key.
    `CTag` | `getOpeningCTag(java.lang.String id)` Gets the opening `CTag` for a given id.
    `MTag` | `getOpeningMTag(java.lang.String id)` Gets the opening `MTag` for a given id.
    `Tag` | `getOpeningTag(java.lang.String id)` Gets the opening tag for a given tag ID.
    `Tag` | `getOpeningTag(Tag closingTag)` Gets the opening tag for a given closing tag.
    `PCont` | `getPCont(java.lang.CharSequence ctext, int pos)` Gets the `PCont` for a given reference in a coded text.
    `PCont` | `getPCont(int key)` Gets the `PCont` for a given key.
    `int` | `getPContCount()` Gets the number of protected content items in this object.
    `Store` | `getStore()` Gets the store associated with this collection.
    `boolean` | `hasCTagWithData()` Indicates if this collection of tags has at least one code with original data.
    `int` | `hashCode()`
    `java.util.Iterator<Tag>` | `iterator()` Creates an iterator for the `CTag` and `MTag` objects in this collection.
    `java.util.Iterator<PCont>` | `iteratorPCont()` Creates an iterator for the `PCont` objects in this collection.
    `void` | `remove(int key)` Removes a tag for a given key.
    `void` | `removePCont(int key)` Removes the `PCont` object for a given key.
    `protected void` | `resetPContLastValue()`
    `int` | `size()` Gets the number of `CTag` and `MTag` tags in this collection.

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

      `clone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### Tags

          public Tags(Store store)

      Creates a new `Tags` object.
      Parameters:
        `store` - the shared `Store` for this object.

  - ### Method Detail

    - #### hashCode

          public int hashCode()

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

    - #### resetPContLastValue

          protected void resetPContLastValue()

    - #### hasCTagWithData

          public boolean hasCTagWithData()

      Indicates if this collection of tags has at least one code with original data.
      Returns:
        true if the collection has at least one code with original data, false otherwise.

    - #### getClosingTag

          public Tag getClosingTag(Tag openingTag)

      Gets the closing tag for a given opening tag.
      Parameters:
        `openingTag` - the opening tag.
      Returns:
        the closing tag, or null if it is not found.

    - #### getClosingTag

          public Tag getClosingTag(java.lang.String id)

      Gets the closing tag for a given tag ID.
      Parameters:
        `id` - the ID of the closing tag to search for.
      Returns:
        the closing tag, or null if no tag with the given ID is found.

    - #### getOpeningTag

          public Tag getOpeningTag(Tag closingTag)

      Gets the opening tag for a given closing tag.
      Parameters:
        `closingTag` - the closing tag.
      Returns:
        the opening tag, or null if it is not found.

    - #### getOpeningTag

          public Tag getOpeningTag(java.lang.String id)

      Gets the opening tag for a given tag ID.
      Parameters:
        `id` - the ID of the opening tag to search for.
      Returns:
        the opening tag, or null if no tag with the given ID is found.

    - #### getOpeningCTag

          public CTag getOpeningCTag(java.lang.String id)

      Gets the opening `CTag` for a given id.
      Parameters:
        `id` - the ID of the opening tag to search for.
      Returns:
        the opening `CTag` or null if no tag with the given ID is found.
      Throws:
        `InvalidParameterException` - if a tag is found but it is not a `CTag` object.

    - #### getOpeningMTag

          public MTag getOpeningMTag(java.lang.String id)

      Gets the opening `MTag` for a given id.
      Parameters:
        `id` - the ID of the opening tag to search for.
      Returns:
        the opening `MTag` or null if no tag with the given ID is found.
      Throws:
        `InvalidParameterException` - if a tag is found but it is not a `MTag` object.

    - #### size

          public int size()

      Gets the number of `CTag` and `MTag` tags in this collection.
      Returns:
        the number of `CTag` and `MTag` tags in this collection.

    - #### getPContCount

          public int getPContCount()

      Gets the number of protected content items in this object.
      Returns:
        the number of protected content items in this object.

    - #### getStore

          public Store getStore()

      Gets the store associated with this collection.
      Returns:
        the store associated with this collection.

    - #### get

          public Tag get(int key)

      Gets the `MTag` or `CTag` for a given key.
      Parameters:
        `key` - the key of the annotation or code tag to retrieve.
      Returns:
        the tag for the given key, or null if there is no corresponding tag.

    - #### get

          public Tag get(java.lang.CharSequence ctext,
                int pos)

      Gets the `MTag` or `CTag` for a given reference in a coded text.
      Parameters:
        `ctext` - the coded text (e.g. String or StringBuilder object).
        `pos` - the position of the first character of the reference.
      Returns:
        the tag for the given tag reference, or null if there is no corresponding tag.

    - #### getCTag

          public CTag getCTag(int key)

      Gets the `CTag` for a given key.
      Parameters:
        `key` - the key of the code tag to retrieve.
      Returns:
        the tag for the given key, or null if there is no corresponding tag.

    - #### getCTag

          public CTag getCTag(java.lang.CharSequence ctext,
                     int pos)

      Gets the `CTag` for a given reference in a coded text.
      Parameters:
        `ctext` - the coded text (e.g. String or StringBuilder object).
        `pos` - the position of the first character of the reference.
      Returns:
        the tag for the given tag reference, or null if there is no corresponding tag.

    - #### getMTag

          public MTag getMTag(int key)

      Gets the `MTag` for a given key.
      Parameters:
        `key` - the key of the code tag to retrieve.
      Returns:
        the tag for the given key, or null if there is no corresponding tag.

    - #### getMTag

          public MTag getMTag(java.lang.CharSequence ctext,
                     int pos)

      Gets the `MTag` for a given reference in a coded text.
      Parameters:
        `ctext` - the coded text (e.g. String or StringBuilder object).
        `pos` - the position of the first character of the reference.
      Returns:
        the tag for the given tag reference, or null if there is no corresponding tag.

    - #### get

          public Tag get(java.lang.String id,
                TagType tagType)

      Gets the tag for a given id and tag type.
      Parameters:
        `id` - the id of the tag to retrieve.
        `tagType` - the tag type of the tag to retrieve.
      Returns:
        the tag for the given id and tag type, or null if it is not found.

    - #### getPCont

          public PCont getPCont(int key)

      Gets the `PCont` for a given key.
      Parameters:
        `key` - the key of the protected content tag to retrieve.
      Returns:
        the tag for the given key, or null if there is no corresponding tag.

    - #### getPCont

          public PCont getPCont(java.lang.CharSequence ctext,
                       int pos)

      Gets the `PCont` for a given reference in a coded text.
      Parameters:
        `ctext` - the coded text (e.g. String or StringBuilder object).
        `pos` - the position of the first character of the reference.
      Returns:
        the tag for the given key, or null if there is no corresponding tag.

    - #### getKey

          public int getKey(Tag tag)

      Gets the key for a given code or marker.
      Parameters:
        `tag` - the tag to lookup.
      Returns:
        the key of the given tag, or -1 if not found.

    - #### add

          public int add(Tag tag)

      Adds a tag to this collection.
      Parameters:
        `tag` - the marker to add.
      Returns:
        the key of the new marker reference.

    - #### add

          public int add(PCont tag)

      Adds a protected content tag to this object.
      Parameters:
        `tag` - the marker to add.
      Returns:
        the key of the new protected content marker reference.

    - #### iterator

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

      Creates an iterator for the `CTag` and `MTag` objects in this collection.
      Specified by:
        `iterator` in interface `java.lang.Iterable<Tag>`
      Returns:
        a new iterator for `CTag` and `MTag`.

    - #### iteratorPCont

          public java.util.Iterator<PCont> iteratorPCont()

      Creates an iterator for the `PCont` objects in this collection.
      Returns:
        a new iterator for `PCont`.

    - #### remove

          public void remove(int key)

      Removes a tag for a given key.

      Warning: This method does not remove the corresponding tag reference in the coded text.

      Parameters:
        `key` - the key of the tag to remove.
      Throws:
        `java.lang.IndexOutOfBoundsException` - if the key is not found.

    - #### removePCont

          public void removePCont(int key)

      Removes the `PCont` object for a given key.

      Warning: This method does not remove the corresponding reference in the coded text.

      Parameters:
        `key` - the key of the tag to remove.
      Throws:
        `java.lang.IndexOutOfBoundsException` - if the key is not found.