Package com.mayam.wf.attributes.shared
Class AttributeMap
java.lang.Object
com.mayam.wf.attributes.shared.AttributeMap
- All Implemented Interfaces:
AttributeManager
,AttributeMutator
,Copyable
,Navigable
Map from
Attribute
to value. When properly injected,
the map will validate input to make sure it conforms to
Attribute
annotations.
Setting an attribute will mark it as dirty.- Author:
- Markus MÃ¥rtensson
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
Fluid export with optional filtering and merging instructions.static interface
Describes a class containing anAttributeMap
.Nested classes/interfaces inherited from interface com.mayam.wf.attributes.shared.Copyable
Copyable.Utilities
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
attachCache
(@NonNull AttributeMap cache) Attaches a cache for use in scenarios where the AttributeMap describes a subject with operation parameters.void
clear()
Removes all values from the map.@NonNull AttributeMap
Clears the dirty flags on all attribute values within the map.boolean
containsAttribute
(@NonNull Attribute attribute) @Nullable AttributeMap
Detaches the current cache, returning it.boolean
@NonNull AttributeMap.Exporter
export()
Begins a fluid export.<T> @Nullable T
getAttribute
(@NonNull Attribute attribute) Attribute accessor.<T> @Nullable T
getAttribute
(@NonNull Attribute attribute, @NonNull Class<T> cls) Attribute accessor.@Nullable String
getAttributeAsString
(@NonNull Attribute attribute) Gets an attribute value, converted to a string.<T> @Nullable T
getAttributeByFieldId
(@NonNull String fieldId) Attribute accessor based on field identifier.<T> @Nullable T
getAttributeByFieldId
(@NonNull String fieldId, @NonNull Class<T> cls) Attribute accessor based on field identifier.@Nullable String
getAttributeByFieldIdAsString
(@NonNull String fieldId) Gets an attribute value based on field identifier, converted to a string.Compile a set of attributes with values inside this attribute map.Compile a set of attributes with dirty values inside this attribute map.boolean
hasCache()
int
hashCode()
boolean
Checks for the existence ofAttributeValidator
andAttributeDescription.Producer
helper instances.void
injectHelpers
(AttributeValidator validator, AttributeDescription.Producer describer, AttributeFieldMapper attributeFieldMapper) Injects helper objects.boolean
managesAttribute
(Attribute attribute) Determines if the given attribute is part of the subset managed by the class.static @Nullable AttributeMap
merge
(@Nullable AttributeMap original, @Nullable AttributeMap overrides) Merges two AttributeMap objects with priority given to the one referred to as "overrides".Given a key relative to this object, returns the associated object if any.void
putAll
(@NonNull AttributeMap source) Copy values from another attribute map into this, regardless of dirty status.void
putClean
(@NonNull AttributeMap source) Copy values from another attribute map into this, unless they already exist in dirty state.void
putDirty
(@NonNull AttributeMap source) Copy dirty values from another attribute map into this.void
removeAttribute
(@NonNull Attribute attribute) Removes a value from the map.void
removeAttributeByFieldId
(@NonNull String fieldId) Remove attribute based on field identifier.<T> @NonNull T
requireAttribute
(@NonNull Attribute attribute) Attribute accessor with included null-check.<T> @NonNull T
requireAttribute
(@NonNull Attribute attribute, @NonNull Class<T> cls) Attribute accessor with included null-check.<T> @NonNull T
requireAttributeByFieldId
(String fieldId) Attribute accessor, based on field identifier, with included non-check.@NonNull AttributeMap
setAttribute
(@NonNull Attribute attribute, @Nullable Object value) Attribute mutator.@NonNull AttributeMap
setAttribute
(@NonNull Attribute attribute, @Nullable Object value, boolean markAsDirty) Attribute mutator with the option of disabling dirty flagging.@NonNull AttributeMap
setAttributeByFieldId
(@NonNull String fieldId, @Nullable Object value) Attribute mutator based on field identifier.@NonNull AttributeMap
setAttributeByFieldIdFromString
(@NonNull String fieldId, @Nullable String valueStr) Attribute mutator based on field identifier.@NonNull AttributeMap
setAttributeFromString
(@NonNull Attribute attribute, @Nullable String valueStr) Sets attribute value based on on a string, converting it to the class defined byDeclare.valueClass()
.@NonNull String
@NonNull String
toLongString
(@Nullable String separator) @NonNull String
toLongString
(@Nullable String separator, boolean ignoreNulls) @NonNull String
toLongString
(@Nullable String separator, boolean ignoreNulls, boolean print_dirty) @NonNull String
@NonNull String
toLongStringIgnoreNulls
(@Nullable String separator) @NonNull String
toString()
-
Constructor Details
-
AttributeMap
public AttributeMap()
-
-
Method Details
-
hasInjectedHelpers
public boolean hasInjectedHelpers()Checks for the existence ofAttributeValidator
andAttributeDescription.Producer
helper instances.- Returns:
- true if both helpers are injected.
-
clear
public void clear()Removes all values from the map. -
getAttributeByFieldId
Attribute accessor based on field identifier. Requires aAttributeFieldMapper
implementation, which is typically only bound on the server side.- Type Parameters:
T
- the requested type for casting.- Parameters:
fieldId
- the field identifier.- Returns:
- the current value of the attribute, cast as requested.
-
getAttributeByFieldId
Attribute accessor based on field identifier. Requires aAttributeFieldMapper
implementation, which is typically only bound on the server side.- Parameters:
fieldId
- the field identifier.cls
- the requested type for casting.- Returns:
- the current value of the attribute, cast as requested.
-
getAttributeByFieldIdAsString
Gets an attribute value based on field identifier, converted to a string. Requires aAttributeFieldMapper
implementation, which is typically only bound on the server side.- Parameters:
fieldId
- the field id- Returns:
- attribute value converted to a string.
-
setAttributeByFieldId
Attribute mutator based on field identifier. Requires aAttributeFieldMapper
implementation, which is typically only bound on the server side.- Parameters:
fieldId
- the field identifier.value
- the new value of the attribute.- Returns:
- the manager, to allow method chaining.
-
setAttributeByFieldIdFromString
public @NonNull AttributeMap setAttributeByFieldIdFromString(@NonNull String fieldId, @Nullable String valueStr) Attribute mutator based on field identifier. Requires aAttributeFieldMapper
implementation, which is typically only bound on the server side.- Parameters:
fieldId
- the field identifier.valueStr
- the string representation of the value to set.- Returns:
- the manager, to allow method chaining.
-
removeAttributeByFieldId
Remove attribute based on field identifier. Requires aAttributeFieldMapper
implementation, which is typically only bound on the server side.- Parameters:
fieldId
- the field identifier.
-
requireAttributeByFieldId
Attribute accessor, based on field identifier, with included non-check. Should the value value prove to be null, a exception is thrown.- Type Parameters:
T
- the requested type for casting.- Parameters:
fieldId
- the field identifier.- Returns:
- the current non-null value of the attribute, cast as requested.
- Throws:
IllegalArgumentException
- if the value is null.
-
getAttributeSet
Compile a set of attributes with values inside this attribute map.- Returns:
- attribute set.
-
getDirtySet
Compile a set of attributes with dirty values inside this attribute map.- Returns:
- dirty attribute set.
-
clearDirty
Clears the dirty flags on all attribute values within the map.- Returns:
- the map to allow method chaining.
-
detachCache
Detaches the current cache, returning it. -
hasCache
public boolean hasCache() -
hashCode
public int hashCode() -
equals
-
toLongString
-
toLongStringIgnoreNulls
-
toLongStringIgnoreNulls
-
toLongString
-
toLongString
-
toLongString
-
toString
-
export
Begins a fluid export.- See Also: