M
- The generic of the DataManipulator from the APII
- The type of the ImmutableDatAManipulator from the APIpublic abstract class AbstractData<M extends org.spongepowered.api.data.manipulator.DataManipulator<M,I>,I extends org.spongepowered.api.data.manipulator.ImmutableDataManipulator<I,M>> extends Object implements org.spongepowered.api.data.manipulator.DataManipulator<M,I>
DataProcessor
s or ValueProcessor
s to avoid relying on
implementation residing in the actual DataManipulator
s themselves.
As all vanilla related manipulators are based on data existing from
Minecraft's current implementation (i.e. not an ECS), it is required
that all processing exists in the associated processors and not within these
DataManipulator
s. Unfortunately, due to JDK 6's poor generic
inference calculator, most of the delegating methods to their processors
require extra casting to Object
and recasting to the practical
M
generics.
Note: It is ABSOLUTELY REQUIRED to registerKeyValue(Key, Supplier)
and registerFieldGetter(Key, Supplier)
and
registerFieldSetter(Key, Consumer)
for all possible
Key
s and Value
s the DataManipulator
may provide as
all of the implementation methods provided here are handled using those. This
was done to avoid having to override getKeys()
and getValues()
,
let alone using ValueProcessor
s for simple setters and getters. I believe
this to be faster than having to retrieve a processor from a map, checking if
the class is an instance of the type implementation to access the setters
and getters.
Modifier | Constructor and Description |
---|---|
protected |
AbstractData(Class<M> manipulatorClass) |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj) |
Optional<M> |
fill(org.spongepowered.api.data.DataHolder dataHolder,
org.spongepowered.api.data.merge.MergeFunction overlap) |
Optional<M> |
from(org.spongepowered.api.data.DataContainer container) |
<E> Optional<E> |
get(org.spongepowered.api.data.key.Key<? extends org.spongepowered.api.data.value.BaseValue<E>> key) |
Set<org.spongepowered.api.data.key.Key<?>> |
getKeys() |
<E,V extends org.spongepowered.api.data.value.BaseValue<E>> |
getValue(org.spongepowered.api.data.key.Key<V> key) |
Set<org.spongepowered.api.data.value.immutable.ImmutableValue<?>> |
getValues() |
int |
hashCode() |
protected void |
registerFieldGetter(org.spongepowered.api.data.key.Key<?> key,
java.util.function.Supplier<?> function)
Simple registration method for the keys to field getter methods.
|
protected <E> void |
registerFieldSetter(org.spongepowered.api.data.key.Key<? extends org.spongepowered.api.data.value.BaseValue<E>> key,
java.util.function.Consumer<E> function)
Simple registration method for the keys to field setter methods.
|
protected abstract void |
registerGettersAndSetters() |
protected void |
registerKeyValue(org.spongepowered.api.data.key.Key<?> key,
java.util.function.Supplier<org.spongepowered.api.data.value.mutable.Value<?>> function)
Simple registration method for the keys to value return methods.
|
<E> M |
set(org.spongepowered.api.data.key.Key<? extends org.spongepowered.api.data.value.BaseValue<E>> key,
E value) |
boolean |
supports(org.spongepowered.api.data.key.Key<?> key) |
<E> M |
transform(org.spongepowered.api.data.key.Key<? extends org.spongepowered.api.data.value.BaseValue<E>> key,
java.util.function.Function<E,E> function) |
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
asImmutable, copy, fill, set, set, set
compareTo
protected final void registerKeyValue(org.spongepowered.api.data.key.Key<?> key, java.util.function.Supplier<org.spongepowered.api.data.value.mutable.Value<?>> function)
Note that this is still going to be usable, but will be made simpler
when Java 8 is used, as lambda expressions can reference methods. The
update won't actually change these registration methods, but the
DataManipulator
s calling these registration methods will
become single line simplifications.
key
- The key for the value return typefunction
- The function for getting the valueprotected final void registerFieldGetter(org.spongepowered.api.data.key.Key<?> key, java.util.function.Supplier<?> function)
Note that this is still going to be usable, but will be made simpler
when Java 8 is used, as lambda expressions can reference methods. The
update won't actually change these registration methods, but the
DataManipulator
s calling these registration methods will
become single line simplifications.
key
- The key for the value return typefunction
- The function for getting the fieldprotected final <E> void registerFieldSetter(org.spongepowered.api.data.key.Key<? extends org.spongepowered.api.data.value.BaseValue<E>> key, java.util.function.Consumer<E> function)
Note that this is still going to be usable, but will be made simpler
when Java 8 is used, as lambda expressions can reference methods. The
update won't actually change these registration methods, but the
DataManipulator
s calling these registration methods will
become single line simplifications.
key
- The key for the value return typefunction
- The function for setting the fieldprotected abstract void registerGettersAndSetters()
public Optional<M> fill(org.spongepowered.api.data.DataHolder dataHolder, org.spongepowered.api.data.merge.MergeFunction overlap)
public <E> M set(org.spongepowered.api.data.key.Key<? extends org.spongepowered.api.data.value.BaseValue<E>> key, E value)
public <E> M transform(org.spongepowered.api.data.key.Key<? extends org.spongepowered.api.data.value.BaseValue<E>> key, java.util.function.Function<E,E> function)
public <E> Optional<E> get(org.spongepowered.api.data.key.Key<? extends org.spongepowered.api.data.value.BaseValue<E>> key)
public <E,V extends org.spongepowered.api.data.value.BaseValue<E>> Optional<V> getValue(org.spongepowered.api.data.key.Key<V> key)
public boolean supports(org.spongepowered.api.data.key.Key<?> key)
public Set<org.spongepowered.api.data.key.Key<?>> getKeys()
public Set<org.spongepowered.api.data.value.immutable.ImmutableValue<?>> getValues()