Class Attributes
- Direct Known Subclasses:
Contig
,Feature
,Sample
,SequenceType
,Variant
String
s.
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 Summary
Modifier and TypeMethodDescriptionattributesAsString
(String separator) Converts the attributes of this entity to a string representation..attributesAsString
(Collection<String> except, String separator) Converts the attributes of this entity to a string representation, 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.getAttributeOrDefault
(String key, String defaultValue) Retrieves the value of an attribute associated with this entity.Retrieves all attributes associated with this entity.getAttributeSet
(String key) Retrieves the value of an attribute as a collection of strings.boolean
Checks if this entity has any attribute.boolean
hasAttribute
(String key) Checks if an attribute with the specified key exists in this entity.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
setAttributeIfAbsent
(String key, String value) Adds an attribute to this entity only if it does not already exist.void
setAttributes
(Map<String, String> attributes) Adds multiple attributes to this entity.void
setAttributesIfAbsent
(Map<String, String> attributes) Adds multiple attributes to this entity only if they do not already exist.
-
Method Details
-
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.
-
hasAnyAttribute
public boolean hasAnyAttribute()Checks if this entity has any attribute.- Returns:
true
if at least one attribute exists,false
otherwise.
-
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.
-
getAttributeOrDefault
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
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
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
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
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
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.
-
setAttributeIfAbsent
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
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.
-
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.
-