Class DataKey<T>
- java.lang.Object
-
- com.vladsch.flexmark.util.data.DataKeyBase<T>
-
- com.vladsch.flexmark.util.data.DataKey<T>
-
- Type Parameters:
T
- type of data held by the key
- All Implemented Interfaces:
MutableDataValueSetter<T>
- Direct Known Subclasses:
CollectionDataKey
public class DataKey<T> extends DataKeyBase<T>
NOTE: Constructors have changed in a breaking way from 0.50.x and prior implementationsPreviously 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 Summary
Constructors Constructor Description DataKey(java.lang.String name, DataKey<T> defaultKey)
Creates a DataKey with a dynamic default value taken from a value of another keyDataKey(java.lang.String name, NotNullValueSupplier<T> supplier)
Creates a DataKey with non-null data value and factoryDataKey(java.lang.String name, T defaultValue)
DataKey(java.lang.String name, T defaultValue, DataNotNullValueFactory<T> factory)
Creates a DataKey with non-null data value and factory
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T
get(DataHolder holder)
T
getDefaultValue()
T
getDefaultValue(DataHolder holder)
DataNotNullValueFactory<T>
getFactory()
MutableDataHolder
set(MutableDataHolder dataHolder, T value)
java.lang.String
toString()
-
Methods inherited from class com.vladsch.flexmark.util.data.DataKeyBase
equals, getFrom, getName, hashCode
-
-
-
-
Constructor Detail
-
DataKey
public DataKey(@NotNull java.lang.String name, @NotNull T defaultValue, @NotNull DataNotNullValueFactory<T> factory)
Creates a DataKey with non-null data value and factoryUse this constructor to ensure that factory is never called with null data holder value
- Parameters:
name
- SeeDataKeyBase.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 holder
-
DataKey
public DataKey(@NotNull java.lang.String name, @NotNull NotNullValueSupplier<T> supplier)
Creates a DataKey with non-null data value and factoryUse this constructor to ensure that factory is never called with null data holder value
- Parameters:
name
- SeeDataKeyBase.getName()
.supplier
- data value factory for creating a new default value for the key not dependent on dataHolder
-
DataKey
public DataKey(@NotNull java.lang.String name, @NotNull DataKey<T> defaultKey)
Creates a DataKey with a dynamic default value taken from a value of another keydoes not cache the returned default value but will always delegate to another key until this key gets its own value set.
- Parameters:
name
- SeeDataKeyBase.getName()
.defaultKey
- The NullableDataKey to take the default value from at time of construction.
-
DataKey
public DataKey(@NotNull java.lang.String name, @NotNull T defaultValue)
-
-
Method Detail
-
getFactory
@NotNull public DataNotNullValueFactory<T> getFactory()
- Overrides:
getFactory
in classDataKeyBase<T>
-
getDefaultValue
@NotNull public T getDefaultValue()
- Overrides:
getDefaultValue
in classDataKeyBase<T>
-
getDefaultValue
@NotNull public T getDefaultValue(@NotNull DataHolder holder)
- Overrides:
getDefaultValue
in classDataKeyBase<T>
-
get
@NotNull public T get(@Nullable DataHolder holder)
- Overrides:
get
in classDataKeyBase<T>
-
set
@NotNull public MutableDataHolder set(@NotNull MutableDataHolder dataHolder, @NotNull T value)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classDataKeyBase<T>
-
-