Class AttributeValues

java.lang.Object
io.superdurable.dex.AttributeValues

public final class AttributeValues extends Object
Holds the decoded values of one Client.getAttributes(String, AttributeRead...) call.

getAttributes returns an AttributeValues only after every set value has decoded. Look up each value with get(AttributeRead), passing the read that was part of the call or an equal one. An Attribute matches only the same definition object. An AttributeMapInstance matches any selector for the same AttributeMap object and the same instance key, so a freshly created notes.instance("n1") works.

An unset Attribute or AttributeMap instance reads as Optional.empty(). Falsy values such as an empty string, 0, and false are set values. A stored value that decodes to null also reads as Optional.empty(), because Optional cannot hold null. Writing null from a Step or RPC deletes the Attribute, so this case is rare.

An AttributeValues cannot change after the call returns, and threads may share it. Each get(AttributeRead) call returns the same decoded value object for a read; the value is not copied. Treat a mutable value as shared, or copy it before changing it.

AttributeValues values = client.getAttributes(
        "order-42",
        orderFlow.orderStatus,
        orderFlow.notes.instance("n1"));
String status = values.get(orderFlow.orderStatus).orElse("new");
Optional<Note> note = values.get(orderFlow.notes.instance("n1"));
  • Method Details

    • get

      public <T> Optional<T> get(AttributeRead<T> read)
      Returns the decoded value of one read from the call that produced these values.

      The read must have been part of the getAttributes call. A read that was not part of the call raises IllegalArgumentException rather than returning Optional.empty(), so a typo or a wrong definition object is not mistaken for an unset value. This includes another Attribute object with the same name, and an AttributeMapInstance of another AttributeMap object or another instance key.

      Repeated calls for the same read return the same decoded value object. The value is not copied, so changes to a mutable value are visible to every caller that shares these values.

      AttributeValues values = client.getAttributes("order-42", orderFlow.orderStatus);
      if (!values.get(orderFlow.orderStatus).isPresent()) {
          log.info("order-42 has no status yet");
      }
      
      Type Parameters:
      T - the Java value type of the read
      Parameters:
      read - the Attribute or AttributeMapInstance passed to getAttributes, or an equal AttributeMapInstance
      Returns:
      the decoded value, or Optional.empty() when the Attribute or AttributeMap instance is not set or its stored value decodes to null
      Throws:
      NullPointerException - if read is null
      IllegalArgumentException - if read was not part of the call, or is not an Attribute or AttributeMapInstance; the message names the physical key and the Flow ID of the call