Class AttributeValue<T>

Object
AttributeValue<T>
Type Parameters:
T - type of the value object

@PublicApi @Immutable public abstract class AttributeValue<T> extends Object

Represents a value, or lack thereof. A defined value must be non-null. Similar to Optional<T>, but with additional values to represent special cases and an additional field to carry loader data.

AttributeValue instances are immutable.

Loader data

Loader data is a field that attribute loaders can use to store additional information, which is not a part of the resulting value, but which can be used by some other loaders or by the same loader when calculating a multi-row value.

For example, a loader that calculates the sum of all story points under the row without the row itself could store the own story points value in the loader data, because it will be needed when calculating the attribute value for the parent.

Special values

Special values are provided via the static methods and represent a few special situations. See undefined(), absent(), inaccessible() and error(). Special values may also carry loader data.

Since:
17.0
  • Method Details

    • of

      @NotNull public static <T> AttributeValue<T> of(@NotNull T value)
      Creates an instance for the given value.
      Type Parameters:
      T - value type
      Parameters:
      value - a value
      Returns:
      attribute value instance
    • ofNullable

      @NotNull public static <T> AttributeValue<T> ofNullable(@Nullable T value)
      Creates an instance for the given value. If the value is null, returns an undefined value.
      Type Parameters:
      T - value type
      Parameters:
      value - a value or null
      Returns:
      attribute value instance
    • undefined

      @NotNull public static <T> AttributeValue<T> undefined()
      Returns an undefined value.
      Type Parameters:
      T - value type
      Returns:
      undefined value
    • error

      @NotNull public static <T> AttributeValue<T> error()
      Returns an "error" undefined value. It means there was an error when calculating the value. Specific loaders may put additional information about the error as loader data.
      Type Parameters:
      T - value type
      Returns:
      error value
    • absent

      @Internal @NotNull public static <T> AttributeValue<T> absent()
      Returns an "absent" undefined value, which is used as a placeholder for a value that is being calculated. This method should not be used outside the Attributes system.
      Type Parameters:
      T - value type
      Returns:
      absent value
    • inaccessible

      @Internal @NotNull public static <T> AttributeValue<T> inaccessible()
      Returns an "inaccessible" undefined value, which means the row is not accessible to the user and the real value is not available. This method should not be used outside the Attributes system.
      Type Parameters:
      T - value type
      Returns:
      inaccessible value
    • withData

      @NotNull public abstract AttributeValue<T> withData(@Nullable Object loaderData)
      Creates a new instance of AttributeValue that has the same value, but a new loader data.
      Parameters:
      loaderData - loader data
      Returns:
      a new attribute value
    • getValue

      @Nullable public abstract T getValue()
      Returns the value or null if this value is undefined.
      Returns:
      value
    • getDefinedValue

      @NotNull public final T getDefinedValue()
      Returns a defined value, or throws a runtime exception if the value is not defined.
      Returns:
      value
      Throws:
      StructureRuntimeException - if the value is undefined
    • ifPresent

      @NotNull public abstract AttributeValue<T> ifPresent(@NotNull Consumer<? super T> consumer)
      Supplies the value to the consumer, if the value is defined.
      Parameters:
      consumer - consumer of the value, will be supplied with a non-null reference
      Returns:
      this instance
    • isDefined

      public abstract boolean isDefined()
      Checks if the value is defined.
      Returns:
      true if the value is defined
    • isError

      public abstract boolean isError()
      Checks if this is a special "error" value.
      Returns:
      true if this is an error
    • isAbsent

      public abstract boolean isAbsent()
      Checks if this is a special "absent" value.
      Returns:
      true if this is an absent value
    • isInaccessible

      public abstract boolean isInaccessible()
      Checks if this is a special "inaccessible" value.
      Returns:
      true if this is an inaccessible value
    • getLoaderData

      @Nullable public <D> D getLoaderData(Class<D> valueClass)
      Returns the loader data if it matches the provided type.
      Type Parameters:
      D - expected loader data type
      Parameters:
      valueClass - expected loader data class
      Returns:
      loader data or null if it is missing or of other type
    • cast

      @NotNull @Internal public <X> AttributeValue<X> cast(AttributeSpec<X> spec)
      Transforms the value to a different type.
      Type Parameters:
      X - the new type
      Parameters:
      spec - attribute spec to take the type from
      Returns:
      this instance