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 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 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.
Modifier and Type | Method and Description |
---|---|
static <T> AttributeValue<T> |
absent()
Returns an "absent" undefined value, which is used as a placeholder for a value that is being calculated.
|
<X> AttributeValue<X> |
cast(AttributeSpec<X> spec)
Transforms the value to a different type.
|
static <T> AttributeValue<T> |
error()
Returns an "error" undefined value.
|
T |
getDefinedValue()
Returns a defined value, or throws a runtime exception if the value is not defined.
|
<D> D |
getLoaderData(Class<D> valueClass)
Returns the loader data if it matches the provided type.
|
abstract T |
getValue()
Returns the value or
null if this value is undefined. |
abstract AttributeValue<T> |
ifPresent(Consumer<? super T> consumer)
Supplies the value to the consumer, if the value is defined.
|
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.
|
abstract boolean |
isAbsent()
Checks if this is a special "absent" value.
|
abstract boolean |
isDefined()
Checks if the value is defined.
|
abstract boolean |
isError()
Checks if this is a special "error" value.
|
abstract boolean |
isInaccessible()
Checks if this is a special "inaccessible" value.
|
static <T> AttributeValue<T> |
of(T value)
Creates an instance for the given value.
|
static <T> AttributeValue<T> |
ofNullable(T value)
Creates an instance for the given value.
|
static <T> AttributeValue<T> |
undefined()
Returns an undefined value.
|
abstract AttributeValue<T> |
withData(Object loaderData)
Creates a new instance of
AttributeValue that has the same value, but a new loader data. |
@NotNull public static <T> AttributeValue<T> of(@NotNull T value)
T
- value typevalue
- a value@NotNull public static <T> AttributeValue<T> ofNullable(@Nullable T value)
null
, returns an undefined value.T
- value typevalue
- a value or null@NotNull public static <T> AttributeValue<T> undefined()
T
- value type@NotNull public static <T> AttributeValue<T> error()
T
- value type@Internal @NotNull public static <T> AttributeValue<T> absent()
T
- value type@Internal @NotNull public static <T> AttributeValue<T> inaccessible()
T
- value type@NotNull public abstract AttributeValue<T> withData(@Nullable Object loaderData)
AttributeValue
that has the same value, but a new loader data.loaderData
- loader data@Nullable public abstract T getValue()
null
if this value is undefined.@NotNull public final T getDefinedValue()
StructureRuntimeException
- if the value is undefined@NotNull public abstract AttributeValue<T> ifPresent(@NotNull Consumer<? super T> consumer)
consumer
- consumer of the value, will be supplied with a non-null referencepublic abstract boolean isDefined()
true
if the value is definedpublic abstract boolean isError()
true
if this is an errorpublic abstract boolean isAbsent()
true
if this is an absent valuepublic abstract boolean isInaccessible()
true
if this is an inaccessible value@Nullable public <D> D getLoaderData(Class<D> valueClass)
D
- expected loader data typevalueClass
- expected loader data classnull
if it is missing or of other type@NotNull @Internal public <X> AttributeValue<X> cast(AttributeSpec<X> spec)
X
- the new typespec
- attribute spec to take the type fromCopyright © 2024 Tempo Software. All Rights Reserved.