Package org.spongepowered.api.data
Interface DataRegistration
public interface DataRegistration
An optional registration of
keys
to associate a semi-persistent
state of their associated values
that can be stored, retrieved,
persisted, and/or associated with DataHolders
. A
registration identifies the given Keys
are provided by an
implementation for specific DataHolders
that may support
and not support those keys
. All API provided keys
exposed through the Keys
class will have an associated registration
by the implementation of the API, whether they are usable through
DataProviders
or DataStores
.
If dynamic or persistent retention of the Values
by
keys
is not desired, a registration is optional. This would mean
that any submitted Value
s of a Key
without an associated
DataRegistration
will be only stored on a
mutable DataHolder
for
the duration that that holder exists. The value would not persist between
reloads, restarts, etc.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
A standard builder for constructing newDataRegistration
s. -
Method Summary
Modifier and TypeMethodDescriptionstatic DataRegistration.Builder
builder()
Creates a newDataRegistration.Builder
to build aDataRegistration
.dataStore
(io.leangen.geantyref.TypeToken<? extends DataHolder> token) Gets the appropriateDataStore
for the context of theTypeToken
that is being serialized/deserialized.dataStore
(Class<? extends DataHolder> token) Gets the appropriateDataStore
for the context of theTypeToken
that is being serialized/deserialized.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 Details
-
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
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
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
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
-