Package datastructure

Class Attributable

java.lang.Object
datastructure.Attributable
Direct Known Subclasses:
Contig, Feature, Sample, SequenceType, VariantInformation

public class Attributable extends Object
Base class for entities that can have attributes.

This class provides methods to manage attributes associated with an entity. Attributes are stored as key-value pairs in a TreeMap, allowing efficient retrieval, addition, extension, and removal of attributes. It also supports operations like checking for the existence of attributes and converting attributes to a string representation.

  • Constructor Details

    • Attributable

      protected Attributable()
      Constructor of Attributable.

      Initializes an empty attributes map for the entity.

  • Method Details

    • setAttribute

      public void setAttribute(String key, String value)
      Adds an attribute to this entity. If an attribute with the same key already exists, it will be overwritten.
      Parameters:
      key - The key of the attribute.
      value - The value of the attribute.
    • setAttributes

      public void setAttributes(Map<String,String> attributes)
      Adds multiple attributes to this entity. Existing attributes with the same keys will be overwritten.
      Parameters:
      attributes - A map of attributes to associate with this entity.
    • addAttributeIfAbsent

      public void addAttributeIfAbsent(String key, String value)
      Adds an attribute to this entity only if it does not already exist.
      Parameters:
      key - The key of the attribute.
      value - The value of the attribute.
    • addAttributesIfAbsent

      public void addAttributesIfAbsent(Map<String,String> attributes)
      Adds multiple attributes to this entity only if they do not already exist.
      Parameters:
      attributes - A map of attributes to associate with this entity.
    • extendAttribute

      public void extendAttribute(String key, String value)
      Extends an attribute by appending a value to the existing value. Commas are used to separate values. If the value already exists, it will not be added again.
      Parameters:
      key - The key of the attribute.
      value - The value to append to the attribute.
    • extendAttributes

      public void extendAttributes(Map<String,String> attributes)
      Extends multiple attributes by appending values to the existing values. Commas are used to separate values.
      Parameters:
      attributes - A map of attributes to extend.
    • getAttribute

      public String getAttribute(String key)
      Retrieves the value of an attribute associated with this entity. If the attribute does not exist, Constants.EMPTY is returned.
      Parameters:
      key - The key of the attribute to retrieve.
      Returns:
      The value of the attribute, or Constants.EMPTY if the attribute does not exist.
    • getAttributeAsCollection

      public Collection<String> getAttributeAsCollection(String key)
      Retrieves the value of an attribute as a collection of strings.

      The attribute value is split into individual elements using the comma (`,`) as a delimiter. If the attribute does not exist, an empty collection is returned.

      Parameters:
      key - The key of the attribute to retrieve.
      Returns:
      A collection of strings representing the split values of the attribute, or an empty collection if the attribute does not exist.
    • getAttributes

      public Map<String,String> getAttributes()
      Retrieves all attributes associated with this entity.
      Returns:
      A map of all attributes.
    • hasAttribute

      public boolean hasAttribute(String key)
      Checks if an attribute with the specified key exists in this entity.
      Parameters:
      key - The key of the attribute to query.
      Returns:
      true if the attribute exists, false otherwise.
    • hasAttributes

      public boolean hasAttributes()
      Checks if this entity has any attributes.
      Returns:
      true if at least one attribute exists, false otherwise.
    • removeAttribute

      public void removeAttribute(String key)
      Removes an attribute with the specified key from this entity.
      Parameters:
      key - The key of the attribute to remove.
    • clearAttributes

      public void clearAttributes()
      Removes all attributes from this entity.
    • attributesAsString

      public String attributesAsString()
      Converts the attributes of this entity to a string representation in the format KEY=VALUE;....
      Returns:
      A string representation of the attributes.
    • attributesAsString

      public String attributesAsString(Collection<String> except)
      Converts the attributes of this entity to a string representation in the format KEY=VALUE;..., excluding attributes with keys in the specified collection.
      Parameters:
      except - A collection of keys to exclude from the string representation.
      Returns:
      A string representation of the attributes, excluding the specified keys.