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 booleanallowsAsynchronousAccess(DataHolder dataHolder)Gets whether this provider will allow asynchronous access for retrieving and storing value changes through the API and implementation.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 booleanisSupported(io.leangen.geantyref.TypeToken<? extends DataHolder> dataHolder)booleanisSupported(Type dataHolder)booleanisSupported(DataHolder dataHolder)Gets whether this value provider is supported by the givenValueContainer.Key<V>key()Gets theKeythis provider supports.static <H extends DataHolder.Mutable,V extends Value<E>,E>
MutableDataProviderBuilder<H,V,E>mutableBuilder()Constructs a newMutableDataProviderBuilder.DataTransactionResultoffer(DataHolder.Mutable dataHolder, E element)default DataTransactionResultofferValue(DataHolder.Mutable dataHolder, V value)DataTransactionResultremove(DataHolder.Mutable dataHolder)default Optional<V>value(DataHolder dataHolder)Gets a constructedValuefor the providedDataHolder.<I extends DataHolder.Immutable<I>>
Optional<I>with(I immutable, E element)<I extends DataHolder.Immutable<I>>
Optional<I>without(I immutable)default <I extends DataHolder.Immutable<I>>
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 throwingChangeDataHolderEvents.A list of methods that are constrained by this check are:
Conceptually, an immutableDataHolderwill 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
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 theKeyis 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 Optional<V> value(DataHolder dataHolder)
Gets a constructedValuefor the providedDataHolder. Much likeget(DataHolder), this is generally considered the underlying implementation access for anyValueContainer.get(Key)where theKeyis 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(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>> Optional<I> with(I immutable, E element)
-
withValue
default <I extends DataHolder.Immutable<I>> Optional<I> withValue(I immutable, V value)
-
without
<I extends DataHolder.Immutable<I>> 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
-
-