Class AttributeSpec<T>

Object
AttributeSpec<T>
Type Parameters:
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:

  1. A unique String identifier. Attributes that have the same identifier are considered to be semantically same or similar.
  2. 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.
  3. 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.

See Also:
  • Constructor Details

    • AttributeSpec

      public AttributeSpec(String id, ValueFormat<T> format)
      Constructs an attribute spec with the given ID and format, without parameters.
      Parameters:
      id - attribute ID
      format - 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 ID
      format - value format
      params - parameters map
  • Method Details

    • getId

      @NotNull public String getId()
      Returns the attribute's ID.
    • getFormat

      @NotNull public ValueFormat<T> getFormat()
      Returns the attribute's format.
    • getParamsMap

      @NotNull public Map<String,Object> getParamsMap()
      Returns the attribute's parameters as a read-only map. If there are no parameters, empty map is returned.
    • getParams

      @NotNull public SpecParams getParams()
      Returns the same as getParamsMap(), but wrapped into accessor object.
    • is

      public boolean is(String id)
      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

      public boolean is(ValueFormat<?> format)
      Checks if this attribute specification contains the given format.
      Parameters:
      format - value format
      Returns:
      true if this attribute has this format
    • is

      public boolean is(String id, ValueFormat<?> format)
      Checks if this attribute specification is for the given ID and format.
      Parameters:
      id - attribute's ID
      format - value format
      Returns:
      true if this attribute has this ID and format
    • as

      public <V> AttributeSpec<V> as(ValueFormat<V> format)
      Returns an attribute spec with the same ID and parameters, but with the given ValueFormat.
      Parameters:
      format - the format for a new AttributeSpec
    • withParam

      public AttributeSpec<T> withParam(String name, Object value)
      Returns a new attribute spec with added parameter.
      Parameters:
      name - parameter name
      value - parameter value
      Returns:
      a new, adjusted attribute specification
    • replaceParams

      public AttributeSpec<T> replaceParams(Map<String,Object> newParams)
      Returns a new attribute spec with parameters replaced with a new map.
      Parameters:
      newParams - replacement parameters
    • noParams

      public AttributeSpec<T> noParams()
      Returns a new attribute spec with all parameters removed.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object