Class AttributeValue<T>
- Type Parameters:
T- type of the value 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 Summary
Modifier and TypeMethodDescriptionstatic <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.final TReturns a defined value, or throws a runtime exception if the value is not defined.<D> DgetLoaderData(Class<D> valueClass) Returns the loader data if it matches the provided type.abstract TgetValue()Returns the value ornullif this value is undefined.abstract AttributeValue<T>Supplies the value to the consumer, if the value is defined.static <T> AttributeValue<T>Returns an "inaccessible" undefined value, which means the row is not accessible to the user and the real value is not available.abstract booleanisAbsent()Checks if this is a special "absent" value.abstract booleanChecks if the value is defined.abstract booleanisError()Checks if this is a special "error" value.abstract booleanChecks 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>Returns an undefined value.abstract AttributeValue<T>Creates a new instance ofAttributeValuethat has the same value, but a new loader data.
-
Method Details
-
of
Creates an instance for the given value.- Type Parameters:
T- value type- Parameters:
value- a value- Returns:
- attribute value instance
-
ofNullable
Creates an instance for the given value. If the value isnull, returns an undefined value.- Type Parameters:
T- value type- Parameters:
value- a value or null- Returns:
- attribute value instance
-
undefined
Returns an undefined value.- Type Parameters:
T- value type- Returns:
- undefined value
-
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
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
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
Creates a new instance ofAttributeValuethat has the same value, but a new loader data.- Parameters:
loaderData- loader data- Returns:
- a new attribute value
-
getValue
Returns the value ornullif this value is undefined.- Returns:
- value
-
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
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:
trueif the value is defined
-
isError
public abstract boolean isError()Checks if this is a special "error" value.- Returns:
trueif this is an error
-
isAbsent
public abstract boolean isAbsent()Checks if this is a special "absent" value.- Returns:
trueif this is an absent value
-
isInaccessible
public abstract boolean isInaccessible()Checks if this is a special "inaccessible" value.- Returns:
trueif this is an inaccessible value
-
getLoaderData
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
nullif it is missing or of other type
-
cast
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
-