Package datastructure
Class Attributable
java.lang.Object
datastructure.Attributable
- Direct Known Subclasses:
Contig
,Feature
,Sample
,SequenceType
,VariantInformation
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAttributeIfAbsent
(String key, String value) Adds an attribute to this entity only if it does not already exist.void
addAttributesIfAbsent
(Map<String, String> attributes) Adds multiple attributes to this entity only if they do not already exist.Converts the attributes of this entity to a string representation in the formatKEY=VALUE;...
.attributesAsString
(Collection<String> except) Converts the attributes of this entity to a string representation in the formatKEY=VALUE;...
, excluding attributes with keys in the specified collection.void
Removes all attributes from this entity.void
extendAttribute
(String key, String value) Extends an attribute by appending a value to the existing value.void
extendAttributes
(Map<String, String> attributes) Extends multiple attributes by appending values to the existing values.getAttribute
(String key) Retrieves the value of an attribute associated with this entity.Retrieves the value of an attribute as a collection of strings.Retrieves all attributes associated with this entity.boolean
hasAttribute
(String key) Checks if an attribute with the specified key exists in this entity.boolean
Checks if this entity has any attributes.void
removeAttribute
(String key) Removes an attribute with the specified key from this entity.void
setAttribute
(String key, String value) Adds an attribute to this entity.void
setAttributes
(Map<String, String> attributes) Adds multiple attributes to this entity.
-
Constructor Details
-
Attributable
protected Attributable()Constructor ofAttributable
.Initializes an empty attributes map for the entity.
-
-
Method Details
-
setAttribute
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
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
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
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
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
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
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
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
Retrieves all attributes associated with this entity.- Returns:
- A map of all attributes.
-
hasAttribute
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
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
Converts the attributes of this entity to a string representation in the formatKEY=VALUE;...
.- Returns:
- A string representation of the attributes.
-
attributesAsString
Converts the attributes of this entity to a string representation in the formatKEY=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.
-