Package org.spongepowered.api.data
Interface DataProvider<V extends Value<E>,E>
-
- All Known Subinterfaces:
DirectionRelativeDataProvider<V,E>
public interface DataProvider<V extends Value<E>,E>
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description boolean
allowsAsynchronousAccess(DataHolder dataHolder)
Gets whether this provider will allow asynchronous access for retrieving and storing value changes through the API and implementation.java.util.Optional<E>
get(DataHolder dataHolder)
Gets the elemental value from the providedDataHolder
.static <H extends DataHolder,V extends Value<E>,E>
ImmutableDataProviderBuilder<H,V,E>immutableBuilder()
Constructs a newImmutableDataProviderBuilder
.default boolean
isSupported(io.leangen.geantyref.TypeToken<? extends DataHolder> dataHolder)
boolean
isSupported(java.lang.reflect.Type dataHolder)
boolean
isSupported(DataHolder dataHolder)
Gets whether this value provider is supported by the givenValueContainer
.Key<V>
key()
Gets theKey
this provider supports.static <H extends DataHolder.Mutable,V extends Value<E>,E>
MutableDataProviderBuilder<H,V,E>mutableBuilder()
Constructs a newMutableDataProviderBuilder
.DataTransactionResult
offer(DataHolder.Mutable dataHolder, E element)
default DataTransactionResult
offerValue(DataHolder.Mutable dataHolder, V value)
DataTransactionResult
remove(DataHolder.Mutable dataHolder)
default java.util.Optional<V>
value(DataHolder dataHolder)
Gets a constructedValue
for the providedDataHolder
.<I extends DataHolder.Immutable<I>>
java.util.Optional<I>with(I immutable, E element)
<I extends DataHolder.Immutable<I>>
java.util.Optional<I>without(I immutable)
default <I extends DataHolder.Immutable<I>>
java.util.Optional<I>withValue(I immutable, V value)
-
-
-
Method Detail
-
mutableBuilder
static <H extends DataHolder.Mutable,V extends Value<E>,E> MutableDataProviderBuilder<H,V,E> mutableBuilder()
Constructs a newMutableDataProviderBuilder
.- Returns:
- The builder
-
immutableBuilder
static <H extends DataHolder,V extends Value<E>,E> ImmutableDataProviderBuilder<H,V,E> immutableBuilder()
Constructs a newImmutableDataProviderBuilder
.- Returns:
- The builder
-
allowsAsynchronousAccess
boolean allowsAsynchronousAccess(DataHolder dataHolder)
Gets whether this provider will allow asynchronous access for retrieving and storing value changes through the API and implementation. This is usually sanity checked by the implementation through a simplifiedEngine.onMainThread()
as a majority of datas are required to be synchronous if the changes can end up throwingChangeDataHolderEvent
s.A list of methods that are constrained by this check are:
Conceptually, an immutableDataHolder
will be ignorant of asynchronous access, however, some cases may exist where attempting to create new immutable variants with different values can be still limited by synchronous access.- Parameters:
dataHolder
- The data holder- Returns:
- True if this provider allows asynchronous access
-
get
java.util.Optional<E> get(DataHolder dataHolder)
Gets the elemental value from the providedDataHolder
. This is generally considered the underlying implementation access for anyValueContainer.get(Key)
where theKey
is registered with thisDataProvider
. Nominally, this means the data is provided outside traditional serialized data that is stored with theDataHolder
. It's possible that there may be changing return values for even immutable types, since the provider is providing the data.- Parameters:
dataHolder
- The data holder- Returns:
- The value, if it's supported and exists
-
value
default java.util.Optional<V> value(DataHolder dataHolder)
Gets a constructedValue
for the providedDataHolder
. Much likeget(DataHolder)
, this is generally considered the underlying implementation access for anyValueContainer.get(Key)
where theKey
is registered with thisDataProvider
. Nominally, this means the data is provided outside traditional serialized data that is stored with theDataHolder
. It's possible that there may be changing return values for even immutable types, since the provider is providing the data.- Parameters:
dataHolder
- The data holder to get the constructed value from- Returns:
- The value
-
isSupported
boolean isSupported(DataHolder dataHolder)
Gets whether this value provider is supported by the givenValueContainer
.- Parameters:
dataHolder
- The data holder- Returns:
- Whether it's supported
-
isSupported
default boolean isSupported(io.leangen.geantyref.TypeToken<? extends DataHolder> dataHolder)
-
isSupported
boolean isSupported(java.lang.reflect.Type dataHolder)
-
offer
DataTransactionResult offer(DataHolder.Mutable dataHolder, E element)
-
offerValue
default DataTransactionResult offerValue(DataHolder.Mutable dataHolder, V value)
-
remove
DataTransactionResult remove(DataHolder.Mutable dataHolder)
-
with
<I extends DataHolder.Immutable<I>> java.util.Optional<I> with(I immutable, E element)
-
withValue
default <I extends DataHolder.Immutable<I>> java.util.Optional<I> withValue(I immutable, V value)
-
without
<I extends DataHolder.Immutable<I>> java.util.Optional<I> without(I immutable)
- Type Parameters:
I
- The type of the immutable value store- Parameters:
immutable
- The immutable value store- Returns:
- The new value store, if successful
-
-