I
- The immutable data manipulator typeM
- The mutable manipulator typepublic abstract class AbstractImmutableData<I extends org.spongepowered.api.data.manipulator.ImmutableDataManipulator<I,M>,M extends org.spongepowered.api.data.manipulator.DataManipulator<M,I>> extends Object implements org.spongepowered.api.data.manipulator.ImmutableDataManipulator<I,M>
DataManipulator
, otherwise known as ImmutableDataManipulator
s.
The advantage of these types of DataManipulator
s is that they can not be
mutated once created. In other words, it's safe to pass around these immutable
variants across threads without worry of the underlying values being changed.
It may be possible that some commonly used ImmutableDataManipulator
s
may be cached for better performance when processing obtaining new
ImmutableDataManipulator
s with different values.
Note: It is ABSOLUTELY REQUIRED to registerKeyValue(Key, Supplier)
and registerFieldGetter(Key, Supplier)
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 |
AbstractImmutableData(Class<I> immutableClass) |
Modifier and Type | Method and Description |
---|---|
I |
copy() |
boolean |
equals(Object obj) |
<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 abstract void |
registerGetters() |
protected void |
registerKeyValue(org.spongepowered.api.data.key.Key<?> key,
java.util.function.Supplier<org.spongepowered.api.data.value.immutable.ImmutableValue<?>> function)
Simple registration method for the keys to value return methods.
|
boolean |
supports(org.spongepowered.api.data.key.Key<?> key) |
<E> Optional<I> |
with(org.spongepowered.api.data.key.Key<? extends org.spongepowered.api.data.value.BaseValue<E>> key,
E value) |
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
asMutable, with
compareTo
protected final void registerKeyValue(org.spongepowered.api.data.key.Key<?> key, java.util.function.Supplier<org.spongepowered.api.data.value.immutable.ImmutableValue<?>> 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 abstract void registerGetters()
public <E> Optional<I> with(org.spongepowered.api.data.key.Key<? extends org.spongepowered.api.data.value.BaseValue<E>> key, E value)
public final I copy()
copy
in interface org.spongepowered.api.data.manipulator.ImmutableDataManipulator<I extends org.spongepowered.api.data.manipulator.ImmutableDataManipulator<I,M>,M extends org.spongepowered.api.data.manipulator.DataManipulator<M,I>>
copy
in interface org.spongepowered.api.data.value.ValueContainer<I extends org.spongepowered.api.data.manipulator.ImmutableDataManipulator<I,M>>
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()