I
- The immutable data manipulator typeM
- The mutable manipulator typepublic abstract class AbstractImmutableData<I extends ImmutableDataManipulator<I,M>,M extends DataManipulator<M,I>> extends Object implements ImmutableDataManipulator<I,M>
ImmutableDataManipulator
such that
all fields are declared final
and remain "immutable".Modifier | Constructor and Description |
---|---|
protected |
AbstractImmutableData() |
Modifier and Type | Method and Description |
---|---|
I |
copy()
Creates a clone copy of this
ValueContainer as a new
ValueContainer such that all the BaseValue s are
safely duplicated to the new instance. |
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)
|
Set<Key<?>> |
getKeys()
Gets all applicable
Key s for this ValueContainer . |
<E,V extends BaseValue<E>> |
getValue(Key<V> key)
|
Set<ImmutableValue<?>> |
getValues()
Gets all applicable
BaseValue s associated with this
ValueContainer . |
int |
hashCode() |
protected void |
registerFieldGetter(Key<?> key,
Supplier<?> function)
Simple registration method for the keys to field getter methods.
|
protected abstract void |
registerGetters() |
protected void |
registerKeyValue(Key<?> key,
Supplier<ImmutableValue<?>> function)
Simple registration method for the keys to value return methods.
|
boolean |
supports(Key<?> key)
Checks if the given
Key is supported by this
ValueContainer . |
DataContainer |
toContainer()
Serializes this object into a comprehensible
DataContainer . |
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
asMutable, with, with
getContentVersion
getOrElse, getOrNull, require, supports
protected final void registerKeyValue(Key<?> key, Supplier<ImmutableValue<?>> function)
Note that this is still usable with Java 8 method references.
Referencing this::getfoo()
is recommended.
key
- The key for the value return typefunction
- The function for getting the valueprotected final void registerFieldGetter(Key<?> key, Supplier<?> function)
Note that this is still usable with Java 8 method references.
Referencing this::getfoo()
is recommended.
key
- The key for the value return typefunction
- The function for getting the fieldprotected abstract void registerGetters()
public final I copy()
ValueContainer
ValueContainer
as a new
ValueContainer
such that all the BaseValue
s are
safely duplicated to the new instance.copy
in interface ImmutableDataManipulator<I extends ImmutableDataManipulator<I,M>,M extends DataManipulator<M,I>>
copy
in interface ValueContainer<I extends ImmutableDataManipulator<I,M>>
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<I extends ImmutableDataManipulator<I,M>>
E
- The type of valuekey
- The key linking thepublic <E,V extends BaseValue<E>> Optional<V> getValue(Key<V> key)
ValueContainer
getValue
in interface ValueContainer<I extends ImmutableDataManipulator<I,M>>
E
- The type of the return typeV
- The type of valuekey
- The key linked to the BaseValue
public boolean supports(Key<?> key)
ValueContainer
Key
is supported by this
ValueContainer
.supports
in interface ValueContainer<I extends ImmutableDataManipulator<I,M>>
key
- The key to checkpublic Set<Key<?>> getKeys()
ValueContainer
Key
s for this ValueContainer
.
Changes can not be made to the set to alter the ValueContainer
,
nor can the BaseValue
s be changed with the provided
ImmutableSet
.getKeys
in interface ValueContainer<I extends ImmutableDataManipulator<I,M>>
Key
spublic Set<ImmutableValue<?>> getValues()
ValueContainer
BaseValue
s associated with this
ValueContainer
. As the data backed by the values are copied,
any modifications to the BaseValue
s will not be reflected onto
this ValueContainer
.getValues
in interface ValueContainer<I extends ImmutableDataManipulator<I,M>>
public DataContainer toContainer()
DataSerializable
DataContainer
.toContainer
in interface DataSerializable
protected DataContainer fillContainer(DataContainer dataContainer)
dataContainer
- The data container