T - type of data held by the keypublic class DataKey<T> extends DataKeyBase<T>
Previously you could provide:
1. [T] defaultValue 2. DataValueFactory[T] 3. DataKey[T]
Options 1. and 2. are not available separately and both have to be provided to the constructor to eliminate the need for handling null for DataHolder in the data value factory.
Now you have the following choices:
1. [T] defaultValue AND DataNotNullValueFactory 2. NotNullValueSupplier[T] 3. DataKey[T] from which default value will be taken on construction, and values will be retrieved if no value is set for this key
Additional changes include separating NullableDataKey out so that DataKey values cannot be null. If you need a key with null result value then use NullableDataKey which is identical to DataKey but allows nulls to be used for values.
| Constructor and Description |
|---|
DataKey(@NotNull String name,
@NotNull DataKey<T> defaultKey)
Creates a DataKey with a dynamic default value taken from a value of another key
|
DataKey(@NotNull String name,
@NotNull NotNullValueSupplier<T> supplier)
Creates a DataKey with non-null data value and factory
|
DataKey(@NotNull String name,
T defaultValue) |
DataKey(@NotNull String name,
T defaultValue,
@NotNull DataNotNullValueFactory<T> factory)
Creates a DataKey with non-null data value and factory
|
| Modifier and Type | Method and Description |
|---|---|
T |
get(@Nullable DataHolder holder) |
T |
getDefaultValue() |
T |
getDefaultValue(@NotNull DataHolder holder) |
@NotNull DataNotNullValueFactory<T> |
getFactory() |
@NotNull MutableDataHolder |
set(@NotNull MutableDataHolder dataHolder,
T value) |
String |
toString() |
equals, getFrom, getName, hashCodepublic DataKey(@NotNull
@NotNull String name,
@NotNull
T defaultValue,
@NotNull
@NotNull DataNotNullValueFactory<T> factory)
Use this constructor to ensure that factory is never called with null data holder value
name - See DataKeyBase.getName().defaultValue - default to use when data holder is nullfactory - data value factory for creating a new default value for the key for a non-null data holderpublic DataKey(@NotNull
@NotNull String name,
@NotNull
@NotNull NotNullValueSupplier<T> supplier)
Use this constructor to ensure that factory is never called with null data holder value
name - See DataKeyBase.getName().supplier - data value factory for creating a new default value for the key not dependent on dataHolderpublic DataKey(@NotNull
@NotNull String name,
@NotNull
@NotNull DataKey<T> defaultKey)
does not cache the returned default value but will always delegate to another key until this key gets its own value set.
name - See DataKeyBase.getName().defaultKey - The NullableDataKey to take the default value from at time of construction.@NotNull public @NotNull DataNotNullValueFactory<T> getFactory()
getFactory in class DataKeyBase<T>@NotNull public T getDefaultValue()
getDefaultValue in class DataKeyBase<T>@NotNull public T getDefaultValue(@NotNull @NotNull DataHolder holder)
getDefaultValue in class DataKeyBase<T>@NotNull public T get(@Nullable @Nullable DataHolder holder)
get in class DataKeyBase<T>@NotNull public @NotNull MutableDataHolder set(@NotNull @NotNull MutableDataHolder dataHolder, @NotNull T value)
public String toString()
toString in class DataKeyBase<T>Copyright © 2020. All rights reserved.