Class AttributeMapInstance<T>

java.lang.Object
io.superdurable.dex.AttributeMapInstance<T>
Type Parameters:
T - the Java value type stored in every instance of the AttributeMap
All Implemented Interfaces:
AttributeRead<T>

public final class AttributeMapInstance<T> extends Object implements AttributeRead<T>
Selects one typed AttributeMap instance for a Client Attribute read.

Create a selector with AttributeMap.instance(String). Pass it to Client.getAttributes(String, AttributeRead...) together with singleton Attributes. Then pass it, or an equal selector, to AttributeValues.get(AttributeRead) to obtain the typed value. Selectors are immutable and safe to share between threads. A selector holds no value. AttributeValues.get(AttributeRead) returns the same decoded value object each time it is called with an equal selector, and it does not copy that value.

Two selectors are equal when they refer to the same AttributeMap object and their instance keys are equal strings. Calling instance("n1") twice on the same AttributeMap therefore yields equal selectors. An AttributeMap object created by another AttributeMap.define(String, Class) call is a different definition, even when its name and value type are the same.

AttributeMap<Note> notes = orderFlow.notes;
AttributeValues values = client.getAttributes("order-42", notes.instance("n1"));
Optional<Note> firstNote = values.get(notes.instance("n1"));
  • Method Details

    • getAttributeMap

      public AttributeMap<T> getAttributeMap()
      Returns the AttributeMap definition that owns the selected instance.
      Returns:
      the AttributeMap object passed to AttributeMap.instance(String)
    • getInstance

      public String getInstance()
      Returns the logical instance key.
      Returns:
      the non-blank instance key, which contains no /
    • equals

      public boolean equals(Object other)
      Compares this selector with another object.
      Overrides:
      equals in class Object
      Parameters:
      other - the object to compare, which may be null
      Returns:
      true when other is an AttributeMapInstance for the same AttributeMap object and an equal instance key
    • hashCode

      public int hashCode()
      Returns a hash code consistent with equals(Object).
      Overrides:
      hashCode in class Object
      Returns:
      the hash code of the AttributeMap object identity and the instance key
    • toString

      public String toString()
      Returns the physical Attribute key of the selected instance.
      Overrides:
      toString in class Object
      Returns:
      the AttributeMap name, a /, and the URL-encoded instance key