T
- type of the value expected for this attribute@PublicApi @Immutable public final class AttributeSpec<T> extends Object
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:
String
identifier. Attributes that have the same identifier are considered to be semantically
same or similar.ValueFormat
, which defines the type and possible operations on the resulting value.Use AttributeSpecBuilder
to build an instance of AttributeSpec
in the code.
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.
StructureAttributeService
,
AttributeSpecBuilder
Constructor and Description |
---|
AttributeSpec(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.
|
Modifier and Type | Method and Description |
---|---|
<V> AttributeSpec<V> |
as(ValueFormat<V> format)
Returns an attribute spec with the same ID and parameters, but with the given
ValueFormat . |
boolean |
equals(Object o) |
ValueFormat<T> |
getFormat()
Returns the attribute's format.
|
String |
getId()
Returns the attribute's ID.
|
SpecParams |
getParams()
Returns the same as
getParamsMap() , but wrapped into accessor object. |
Map<String,Object> |
getParamsMap()
Returns the attribute's parameters as a read-only map.
|
int |
hashCode() |
boolean |
is(String id)
Checks if this attribute specification is for the given attribute ID.
|
boolean |
is(String id,
ValueFormat<?> format)
Checks if this attribute specification is for the given ID and format.
|
boolean |
is(ValueFormat<?> format)
Checks if this attribute specification contains the given format.
|
AttributeSpec<T> |
noParams()
Returns a new attribute spec with all parameters removed.
|
AttributeSpec<T> |
replaceParams(Map<String,Object> newParams)
Returns a new attribute spec with parameters replaced with a new map.
|
String |
toString() |
AttributeSpec<T> |
withParam(String name,
Object value)
Returns a new attribute spec with added parameter.
|
public AttributeSpec(String id, ValueFormat<T> format)
id
- attribute IDformat
- value formatpublic AttributeSpec(@NotNull String id, @NotNull ValueFormat<T> format, @Nullable Map<String,Object> params)
id
- attribute IDformat
- value formatparams
- parameters map@NotNull public String getId()
@NotNull public ValueFormat<T> getFormat()
@NotNull public Map<String,Object> getParamsMap()
@NotNull public SpecParams getParams()
getParamsMap()
, but wrapped into accessor object.public boolean is(String id)
id
- attribute's IDpublic boolean is(ValueFormat<?> format)
format
- value formatpublic boolean is(String id, ValueFormat<?> format)
id
- attribute's IDformat
- value formatpublic <V> AttributeSpec<V> as(ValueFormat<V> format)
ValueFormat
.format
- the format for a new AttributeSpec
public AttributeSpec<T> withParam(String name, Object value)
name
- parameter namevalue
- parameter valuepublic AttributeSpec<T> replaceParams(Map<String,Object> newParams)
newParams
- replacement parameterspublic AttributeSpec<T> noParams()
Copyright © 2024 Tempo Software. All Rights Reserved.