Class Tags

  • All Implemented Interfaces:
    Iterable<Tag>

    public class Tags
    extends Object
    implements Iterable<Tag>
    Represents a collection of tags for a specific content.
    • 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 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​(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​(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​(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​(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.
      • isEmpty

        public boolean isEmpty()
        Returns true if this tags contains no tag.
        Returns:
        true if this tags contains no tag
      • 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​(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​(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​(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​(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​(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.
      • iteratorPCont

        public 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:
        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:
        IndexOutOfBoundsException - if the key is not found.