Package model

Class Attributes

java.lang.Object
model.Attributes
Direct Known Subclasses:
Contig, Feature, Sample, SequenceType, Variant

public class Attributes extends Object
Base class for entities to store arbitrary attributes as Strings.

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

  • Method Details

    • 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.
    • hasAnyAttribute

      public boolean hasAnyAttribute()
      Checks if this entity has any attribute.
      Returns:
      true if at least one attribute exists, false otherwise.
    • 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.
    • getAttributeOrDefault

      public String getAttributeOrDefault(String key, String defaultValue)
      Retrieves the value of an attribute associated with this entity. If the attribute does not exist, the specified default value is returned.
      Parameters:
      key - The key of the attribute to retrieve.
      defaultValue - The default value to return if the attribute does not exist.
      Returns:
      The value of the attribute, or the specified default value if the attribute does not exist.
    • getAttributeSet

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

      This method fetches the value of the specified attribute key from the attributes map. The value is split into individual elements using a comma (`,`) as the delimiter. If the attribute does not exist, an empty collection is returned.

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

      public Map<String,String> getAttributes()
      Retrieves all attributes associated with this entity.

      This method provides an unmodifiable view of the attributes map, ensuring that the original map cannot be modified externally. The attributes are stored as key-value pairs, where both the key and value are String.

      Returns:
      An unmodifiable Map containing all attributes associated with this entity.
    • attributesAsString

      public String attributesAsString(String separator)
      Converts the attributes of this entity to a string representation..
      Parameters:
      separator - The separator to use between key-value pairs.
      Returns:
      A string representation of the attributes.
    • attributesAsString

      public String attributesAsString(Collection<String> except, String separator)
      Converts the attributes of this entity to a string representation, excluding attributes with keys in the specified collection.
      Parameters:
      except - A collection of keys to exclude from the string representation.
      separator - The separator to use between key-value pairs.
      Returns:
      A string representation of the attributes, excluding the specified keys.
    • 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.
    • setAttributeIfAbsent

      public void setAttributeIfAbsent(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.
    • setAttributesIfAbsent

      public void setAttributesIfAbsent(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.
    • 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.