Package org.spongepowered.api.data
Interface DataRegistration
-
public interface DataRegistration
An optional registration ofkeys
to associate a semi-persistent state of their associatedvalues
that can be stored, retrieved, persisted, and/or associated withDataHolders
. A registration identifies the givenKeys
are provided by an implementation for specificDataHolders
that may support and not support thosekeys
. All API providedkeys
exposed through theKeys
class will have an associated registration by the implementation of the API, whether they are usable throughDataProviders
orDataStores
.If dynamic or persistent retention of the
Values
bykeys
is not desired, a registration is optional. This would mean that any submittedValue
s of aKey
without an associatedDataRegistration
will be only stored on amutable DataHolder
for the duration that that holder exists. The value would not persist between reloads, restarts, etc.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
DataRegistration.Builder
A standard builder for constructing newDataRegistration
s.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static DataRegistration.Builder
builder()
Creates a newDataRegistration.Builder
to build aDataRegistration
.Optional<DataStore>
dataStore(io.leangen.geantyref.TypeToken<? extends DataHolder> token)
Gets the appropriateDataStore
for the context of theTypeToken
that is being serialized/deserialized.Optional<DataStore>
dataStore(Class<? extends DataHolder> token)
Gets the appropriateDataStore
for the context of theTypeToken
that is being serialized/deserialized.Iterable<Key<?>>
keys()
Gets the registeredKeys
this controls.static <T,V extends Value<T>>
DataRegistrationof(Key<V> key, Class<? extends DataHolder> dataHolder, Class<? extends DataHolder>... dataHolders)
Creates a DataRegistration for a single key with a DataStore for given data-holders.<V extends Value<E>,E>
Collection<DataProvider<V,E>>providersFor(Key<V> key)
Gets theDataProvider
for the givenKey
to potentially get or offerValue
s from anyValueContainer
provided that the container is supported by theDataProvider
.
-
-
-
Method Detail
-
builder
static DataRegistration.Builder builder()
Creates a newDataRegistration.Builder
to build aDataRegistration
. Through the use of generics, this can be duck-typed to the generics of the desiredDataManipulator
type to be registered.- Returns:
- The new builder instance
-
providersFor
<V extends Value<E>,E> Collection<DataProvider<V,E>> providersFor(Key<V> key) throws UnregisteredKeyException
Gets theDataProvider
for the givenKey
to potentially get or offerValue
s from anyValueContainer
provided that the container is supported by theDataProvider
. If thekey
is not actually registered with thisDataRegistration
, anUnregisteredKeyException
is thrown. If there is noDataProvider
registered for the particularKey
,Optional.empty()
is returned.- Type Parameters:
V
- The value typeE
- The element type- Parameters:
key
- The requested key- Returns:
- The provider, if there is one for the key
- Throws:
UnregisteredKeyException
- If the key is not registered in this registration
-
dataStore
Optional<DataStore> dataStore(io.leangen.geantyref.TypeToken<? extends DataHolder> token)
Gets the appropriateDataStore
for the context of theTypeToken
that is being serialized/deserialized. It is always possible that there may be aDataStore
that does not support the providedTypeToken
, while aDataProvider
may be provided for a particularKey
.- Parameters:
token
- The type token of the desired ValueContainer- Returns:
- The relevant DataStore for the desired type token of the target type.
-
dataStore
Optional<DataStore> dataStore(Class<? extends DataHolder> token)
Gets the appropriateDataStore
for the context of theTypeToken
that is being serialized/deserialized. It is always possible that there may be aDataStore
that does not support the providedClass
, while aDataProvider
may be provided for a particularKey
.- Parameters:
token
- The class of the desired ValueContainer. Cannot be a raw type- Returns:
- The relevant DataStore for the desired type token of the target type.
-
keys
Iterable<Key<?>> keys()
Gets the registeredKeys
this controls. Note that eachKey
can only be registered/owned by a singlePluginContainer
. It is possible for there to be only a single key registered, or multiple, depending on the basis of what potentially grouped values are controlled by a singleDataStore
or multipleDataProvider
s, based on the supportedDataHolder
s.- Returns:
- The keys registered
-
of
@SafeVarargs static <T,V extends Value<T>> DataRegistration of(Key<V> key, Class<? extends DataHolder> dataHolder, Class<? extends DataHolder>... dataHolders)
Creates a DataRegistration for a single key with a DataStore for given data-holders.- Type Parameters:
T
- the value's typeV
- the value type- Parameters:
key
- the data keydataHolders
- the data-holders- Returns:
- The built data registration
-
-