Class HashMutableAttributes
java.lang.Object
com.yworkflow.definition.model.attribute.AbstractAttributes
com.yworkflow.definition.model.attribute.AbstractMutableAttributes
com.yworkflow.definition.model.attribute.HashMutableAttributes
- All Implemented Interfaces:
Attributes,MutableAttributes
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 Summary
ConstructorsConstructorDescriptionCreates a new empty HashMutableAttributes instance.HashMutableAttributes(HashMutableAttributes hashMutableAttributes) Creates a new HashMutableAttributes instance by copying from another instance.HashMutableAttributes(Map<String, String> argValues) Creates a new HashMutableAttributes instance with the specified string values. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAll(Attributes attributes) Adds all attributes from the specified Attributes instance to this instance.voidAdds all key-value pairs from the specified Map to this instance.booleancontainsKey(String key) Checks if an attribute with the specified key exists.copy()Creates a copy of this HashMutableAttributes instance.<T> Optional<T>get(AttributeType<T> type, String key) Gets an attribute value with the specified type and key.Gets the complete attribute entry for a key.getKeys(String prefix, AttributeType<?> type) Gets all attribute keys with the specified prefix and type.protected Map<String,AttributeEntry<?>> getMap()Gets the underlying map containing the attribute entries.Gets the type of an attribute.propertyMissing(String name) Handles property missing for getting a value.voidpropertyMissing(String name, String value) Handles property missing for setting a value.voidremove()Removes all attributes from this instance.voidRemoves the attribute with the specified key.protected <T> voidsetImpl(AttributeType<T> type, String key, T value) Sets an attribute value with the specified type and key.protected booleanDetermines whether type checking should be performed.Converts this MutableAttributes instance to an ImmutableAttributes instance.toMap()Converts this HashMutableAttributes to a Map of String keys to Object values.Methods inherited from class com.yworkflow.definition.model.attribute.AbstractMutableAttributes
setAttributes, setBoolean, setData, setDouble, setInstant, setInt, setLong, setObject, setRaw, setRaw, setString, toString, withAttributes, withBoolean, withData, withDouble, withInstant, withInt, withLong, withObject, withStringMethods inherited from class com.yworkflow.definition.model.attribute.AbstractAttributes
get, getBoolean, getData, getDouble, getInstant, getInt, getKeys, getKeys, getKeys, getLong, getObject, getStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.yworkflow.definition.model.attribute.Attributes
get, getBoolean, getData, getDouble, getInstant, getInt, getKeys, getKeys, getKeys, getLong, getObject, getString
-
Constructor Details
-
HashMutableAttributes
public HashMutableAttributes()Creates a new empty HashMutableAttributes instance. -
HashMutableAttributes
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
Creates a new HashMutableAttributes instance by copying from another instance.- Parameters:
hashMutableAttributes- the HashMutableAttributes instance to copy from
-
-
Method Details
-
getKeys
Description copied from interface:AttributesGets all attribute keys with the specified prefix and type.- Parameters:
prefix- the prefix to filter bytype- the attribute type to filter by- Returns:
- a collection of keys that start with the prefix and are of the specified type
-
getType
Description copied from interface:AttributesGets the type of an attribute.- Parameters:
key- the attribute key- Returns:
- an Optional containing the attribute type if the key exists, empty otherwise
-
getEntry
Description copied from interface:AttributesGets 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
Description copied from interface:AttributesChecks if an attribute with the specified key exists.- Parameters:
key- the attribute key to check- Returns:
- true if the key exists, false otherwise
-
remove
Description copied from interface:MutableAttributesRemoves the attribute with the specified key.- Parameters:
key- the key of the attribute to remove
-
remove
Description copied from interface:MutableAttributesRemoves all attributes from this instance.- Throws:
AttributeException- if there's an error removing the attributes
-
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
Creates a copy of this HashMutableAttributes instance.- Returns:
- a new HashMutableAttributes instance with the same attributes
-
setImpl
Sets an attribute value with the specified type and key.- Specified by:
setImplin classAbstractMutableAttributes- Type Parameters:
T- the type of the value- Parameters:
type- the attribute typekey- the attribute keyvalue- 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
Gets the underlying map containing the attribute entries.- Returns:
- the map of attribute entries
-
get
Gets an attribute value with the specified type and key.- Specified by:
getin classAbstractAttributes- Type Parameters:
T- the type of the value- Parameters:
type- the attribute typekey- the attribute key- Returns:
- an Optional containing the value if found and compatible, empty otherwise
- Throws:
AttributeException- if there is a type mismatch
-
addAll
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
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
Description copied from interface:MutableAttributesConverts 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
Handles property missing for setting a value.- Parameters:
name- the property namevalue- the property value as a string- Throws:
AttributeException- if there is an error setting the property
-
propertyMissing
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
-