T
- The type of single value this will holdM
- The type of DataManipulator
I
- The type of ImmutableDataManipulator
public abstract class AbstractSingleData<T,M extends DataManipulator<M,I>,I extends ImmutableDataManipulator<I,M>> extends AbstractData<M,I>
DataManipulator
s that handle a single
value, adding the provided getValue()
and setValue(Object)
methods for easy manipulation. This as well simplifies handling various
other common implementations, such as hashCode()
and
equals(Object)
.Modifier and Type | Field and Description |
---|---|
protected T |
defaultValue |
protected Key<? extends BaseValue<T>> |
usedKey |
protected T |
value |
Modifier | Constructor and Description |
---|---|
protected |
AbstractSingleData(Key<? extends Value<T>> usedKey,
T value) |
protected |
AbstractSingleData(Key<? extends Value<T>> usedKey,
T value,
T defaultValue) |
protected |
AbstractSingleData(T value,
Key<? extends BaseValue<T>> usedKey)
Deprecated.
Use
AbstractSingleData(Key, Object) instead. |
Modifier and Type | Method and Description |
---|---|
abstract I |
asImmutable()
Gets an
ImmutableDataManipulator copy of this
DataManipulator such that all backed Value s are copied
into ImmutableValue counterparts. |
boolean |
equals(Object obj) |
protected DataContainer |
fillContainer(DataContainer dataContainer)
Implement this method to add the data to be persisted.
|
<E> Optional<E> |
get(Key<? extends BaseValue<E>> key)
|
protected T |
getValue()
A simple getter for usage with a
Supplier for
the AbstractData.registerFieldGetter(Key, Supplier) method. |
protected abstract Value<?> |
getValueGetter()
Gets the
Value as a method since this manipulator only focuses
on a single value. |
int |
hashCode() |
protected void |
registerGettersAndSetters()
A required registration method for registering the various fields and
value getters.
|
protected M |
setValue(T value)
A simple setter for usage with a
Consumer for
the AbstractData.registerFieldSetter(Key, Consumer) method. |
boolean |
supports(Key<?> key)
Checks if the given
Key is supported by this
ValueContainer . |
getKeys, getValue, getValues, registerFieldGetter, registerFieldSetter, registerKeyValue, set, toContainer, transform
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
copy, fill, fill, from, set, set, set
getContentVersion
getOrElse, getOrNull, require, supports
@Deprecated protected AbstractSingleData(T value, Key<? extends BaseValue<T>> usedKey)
AbstractSingleData(Key, Object)
instead.protected final void registerGettersAndSetters()
AbstractData
Value
such that there is an
associated Key
to "get" that field value.registerGettersAndSetters
in class AbstractData<M extends DataManipulator<M,I>,I extends ImmutableDataManipulator<I,M>>
protected abstract Value<?> getValueGetter()
Value
as a method since this manipulator only focuses
on a single value.public <E> Optional<E> get(Key<? extends BaseValue<E>> key)
ValueContainer
BaseValue
linked to the provided Key
. If the Key
is not
supported, Optional.empty()
is returned. It is important
to check for support of a Key
by either calling
ValueContainer.supports(BaseValue)
or ValueContainer.supports(Key)
.get
in interface ValueContainer<M extends DataManipulator<M,I>>
get
in class AbstractData<M extends DataManipulator<M,I>,I extends ImmutableDataManipulator<I,M>>
E
- The type of valuekey
- The key linking thepublic boolean supports(Key<?> key)
ValueContainer
Key
is supported by this
ValueContainer
.supports
in interface ValueContainer<M extends DataManipulator<M,I>>
supports
in class AbstractData<M extends DataManipulator<M,I>,I extends ImmutableDataManipulator<I,M>>
key
- The key to checkpublic abstract I asImmutable()
DataManipulator
ImmutableDataManipulator
copy of this
DataManipulator
such that all backed Value
s are copied
into ImmutableValue
counterparts. Any changes to this
DataManipulator
will NOT be reflected on the returned
ImmutableDataManipulator
and vice versa.DataManipulator
's data copied into a
ImmutableDataManipulator
protected T getValue()
Supplier
for
the AbstractData.registerFieldGetter(Key, Supplier)
method.protected M setValue(T value)
Consumer
for
the AbstractData.registerFieldSetter(Key, Consumer)
method.value
- The valueprotected DataContainer fillContainer(DataContainer dataContainer)
AbstractData
fillContainer
in class AbstractData<M extends DataManipulator<M,I>,I extends ImmutableDataManipulator<I,M>>
dataContainer
- The data containerpublic int hashCode()
hashCode
in class AbstractData<M extends DataManipulator<M,I>,I extends ImmutableDataManipulator<I,M>>
public boolean equals(Object obj)
equals
in class AbstractData<M extends DataManipulator<M,I>,I extends ImmutableDataManipulator<I,M>>