Class AttributeSpec<T>
- Type Parameters:
T- type of the value expected for this attribute
AttributeSpec is the "attribute specification", a composite identifier of an attribute. See
package documentation for the definition of an attribute.
Attribute specification contains the following parts:
- A unique
Stringidentifier. Attributes that have the same identifier are considered to be semantically same or similar. - An unbounded parameters map, which should be serializable to JSON (contain only simple types, maps and arrays). Two specifications with the same ID and parameters are considered to be semantically same.
ValueFormat, which defines the type and possible operations on the resulting value.
Use AttributeSpecBuilder to build an instance of AttributeSpec in the code.
Parameter normalization
Attribute spec parameters are normalized. This means that if the value of a parameter is the default for that
parameter, it is not stored in the map. For example, int parameters have default equal to 0. If you try
to build an attribute spec and set an int parameter to 0, the resulting attribute spec will not have that
value.
This is done to avoid unequal instances of AttributeSpec to represent the same attribute. If not normalized,
multiple versions of the same attribute spec could lead to bugs.
See AttributeSpecNormalization for more details.
-
Constructor Summary
ConstructorsConstructorDescriptionAttributeSpec(String id, ValueFormat<T> format) Constructs an attribute spec with the given ID and format, without parameters.AttributeSpec(String id, ValueFormat<T> format, Map<String, Object> params) Constructs an attribute spec with the given ID, format and parameters. -
Method Summary
Modifier and TypeMethodDescription<V> AttributeSpec<V>as(ValueFormat<V> format) Returns an attribute spec with the same ID and parameters, but with the givenValueFormat.booleanReturns the attribute's format.getId()Returns the attribute's ID.Returns the same asgetParamsMap(), but wrapped into accessor object.Returns the attribute's parameters as a read-only map.inthashCode()booleanis(ValueFormat<?> format) Checks if this attribute specification contains the given format.booleanChecks if this attribute specification is for the given attribute ID.booleanis(String id, ValueFormat<?> format) Checks if this attribute specification is for the given ID and format.noParams()Returns a new attribute spec with all parameters removed.replaceParams(Map<String, Object> newParams) Returns a new attribute spec with parameters replaced with a new map.toString()Returns a new attribute spec with added parameter.
-
Constructor Details
-
AttributeSpec
Constructs an attribute spec with the given ID and format, without parameters.- Parameters:
id- attribute IDformat- value format
-
AttributeSpec
public AttributeSpec(@NotNull String id, @NotNull ValueFormat<T> format, @Nullable Map<String, Object> params) Constructs an attribute spec with the given ID, format and parameters. The latter should contain only simple types and collections, the things serializable into JSON.- Parameters:
id- attribute IDformat- value formatparams- parameters map
-
-
Method Details
-
getId
Returns the attribute's ID. -
getFormat
Returns the attribute's format. -
getParamsMap
Returns the attribute's parameters as a read-only map. If there are no parameters, empty map is returned. -
getParams
Returns the same asgetParamsMap(), but wrapped into accessor object. -
is
Checks if this attribute specification is for the given attribute ID.- Parameters:
id- attribute's ID- Returns:
- true if this attribute has the same ID
-
is
Checks if this attribute specification contains the given format.- Parameters:
format- value format- Returns:
- true if this attribute has this format
-
is
Checks if this attribute specification is for the given ID and format.- Parameters:
id- attribute's IDformat- value format- Returns:
- true if this attribute has this ID and format
-
as
Returns an attribute spec with the same ID and parameters, but with the givenValueFormat.- Parameters:
format- the format for a newAttributeSpec
-
withParam
Returns a new attribute spec with added parameter.- Parameters:
name- parameter namevalue- parameter value- Returns:
- a new, adjusted attribute specification
-
replaceParams
Returns a new attribute spec with parameters replaced with a new map.- Parameters:
newParams- replacement parameters
-
noParams
Returns a new attribute spec with all parameters removed. -
equals
-
hashCode
public int hashCode() -
toString
-