Class HashMutableAttributes

All Implemented Interfaces:
Attributes, MutableAttributes

public class HashMutableAttributes extends AbstractMutableAttributes
A mutable attributes implementation using a HashMap for storage. HashMutableAttributes provides a thread-safe, mutable collection of attributes with type safety and validation capabilities.
Since:
1.0
See Also:
  • Constructor Details

    • HashMutableAttributes

      public HashMutableAttributes()
      Creates a new empty HashMutableAttributes instance.
    • HashMutableAttributes

      public HashMutableAttributes(Map<String,String> argValues) throws AttributeException
      Creates a new HashMutableAttributes instance with the specified string values.
      Parameters:
      argValues - a map of key-value pairs to initialize the attributes with
      Throws:
      AttributeException - if there is an error setting the attributes
    • HashMutableAttributes

      public HashMutableAttributes(HashMutableAttributes hashMutableAttributes)
      Creates a new HashMutableAttributes instance by copying from another instance.
      Parameters:
      hashMutableAttributes - the HashMutableAttributes instance to copy from
  • Method Details

    • getKeys

      public Collection<String> getKeys(String prefix, AttributeType<?> type)
      Description copied from interface: Attributes
      Gets all attribute keys with the specified prefix and type.
      Parameters:
      prefix - the prefix to filter by
      type - the attribute type to filter by
      Returns:
      a collection of keys that start with the prefix and are of the specified type
    • getType

      public Optional<AttributeType<?>> getType(String key)
      Description copied from interface: Attributes
      Gets the type of an attribute.
      Parameters:
      key - the attribute key
      Returns:
      an Optional containing the attribute type if the key exists, empty otherwise
    • getEntry

      public Optional<AttributeEntry<?>> getEntry(String key) throws AttributeException
      Description copied from interface: Attributes
      Gets the complete attribute entry for a key.
      Parameters:
      key - the attribute key
      Returns:
      an Optional containing the attribute entry if found, empty otherwise
      Throws:
      AttributeException - if there's an error accessing the attribute
    • containsKey

      public boolean containsKey(String key)
      Description copied from interface: Attributes
      Checks if an attribute with the specified key exists.
      Parameters:
      key - the attribute key to check
      Returns:
      true if the key exists, false otherwise
    • remove

      public void remove(String key)
      Description copied from interface: MutableAttributes
      Removes the attribute with the specified key.
      Parameters:
      key - the key of the attribute to remove
    • remove

      public void remove() throws AttributeException
      Description copied from interface: MutableAttributes
      Removes all attributes from this instance.
      Throws:
      AttributeException - if there's an error removing the attributes
    • toMap

      public Map<String,Object> toMap()
      Converts this HashMutableAttributes to a Map of String keys to Object values. Only entries with non-null values are included in the result.
      Returns:
      a Map containing the key-value pairs with non-null values
    • copy

      public HashMutableAttributes copy()
      Creates a copy of this HashMutableAttributes instance.
      Returns:
      a new HashMutableAttributes instance with the same attributes
    • setImpl

      protected <T> void setImpl(AttributeType<T> type, String key, T value) throws AttributeException
      Sets an attribute value with the specified type and key.
      Specified by:
      setImpl in class AbstractMutableAttributes
      Type Parameters:
      T - the type of the value
      Parameters:
      type - the attribute type
      key - the attribute key
      value - the attribute value
      Throws:
      AttributeException - if there is a type mismatch or other error
    • shouldCheckType

      protected boolean shouldCheckType()
      Determines whether type checking should be performed.
      Returns:
      true if type checking should be performed, false otherwise
    • getMap

      protected Map<String,AttributeEntry<?>> getMap()
      Gets the underlying map containing the attribute entries.
      Returns:
      the map of attribute entries
    • get

      public <T> Optional<T> get(AttributeType<T> type, String key) throws AttributeException
      Gets an attribute value with the specified type and key.
      Specified by:
      get in class AbstractAttributes
      Type Parameters:
      T - the type of the value
      Parameters:
      type - the attribute type
      key - the attribute key
      Returns:
      an Optional containing the value if found and compatible, empty otherwise
      Throws:
      AttributeException - if there is a type mismatch
    • addAll

      public void addAll(Attributes attributes) throws AttributeException
      Adds all attributes from the specified Attributes instance to this instance.
      Parameters:
      attributes - the Attributes instance to copy from
      Throws:
      AttributeException - if there is an error setting the attributes
    • addAll

      public void addAll(Map<String,Object> map) throws AttributeException
      Adds all key-value pairs from the specified Map to this instance.
      Parameters:
      map - the Map containing key-value pairs to add
      Throws:
      AttributeException - if there is an error setting the attributes
    • toImmutable

      public Attributes toImmutable()
      Description copied from interface: MutableAttributes
      Converts this MutableAttributes instance to an ImmutableAttributes instance. This is useful for passing attributes to workflow operations that require immutable data.
      Returns:
      an ImmutableAttributes instance containing all attributes from this instance
    • propertyMissing

      public void propertyMissing(String name, String value) throws AttributeException
      Handles property missing for setting a value.
      Parameters:
      name - the property name
      value - the property value as a string
      Throws:
      AttributeException - if there is an error setting the property
    • propertyMissing

      public Object propertyMissing(String name) throws AttributeException
      Handles property missing for getting a value.
      Parameters:
      name - the property name
      Returns:
      the property value as an Object
      Throws:
      AttributeException - if there is an error getting the property