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 Values 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
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceA standard builder for constructing newDataRegistrations. -
Method Summary
Modifier and TypeMethodDescriptionstatic DataRegistration.Builderbuilder()Creates a newDataRegistration.Builderto build aDataRegistration.dataStore(io.leangen.geantyref.TypeToken<? extends DataHolder> token) Gets the appropriateDataStorefor the context of theTypeTokenthat is being serialized/deserialized.dataStore(Class<? extends DataHolder> token) Gets the appropriateDataStorefor the context of theTypeTokenthat is being serialized/deserialized.keys()Gets the registeredKeysthis 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 theDataProviderfor the givenKeyto potentially get or offerValues from anyValueContainerprovided that the container is supported by theDataProvider.
-
Method Details
-
builder
Creates a newDataRegistration.Builderto build aDataRegistration. Through the use of generics, this can be duck-typed to the generics of the desiredDataManipulatortype 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 theDataProviderfor the givenKeyto potentially get or offerValues from anyValueContainerprovided that the container is supported by theDataProvider. If thekeyis not actually registered with thisDataRegistration, anUnregisteredKeyExceptionis thrown. If there is noDataProviderregistered 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 appropriateDataStorefor the context of theTypeTokenthat is being serialized/deserialized. It is always possible that there may be aDataStorethat does not support the providedTypeToken, while aDataProvidermay 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 appropriateDataStorefor the context of theTypeTokenthat is being serialized/deserialized. It is always possible that there may be aDataStorethat does not support the providedClass, while aDataProvidermay 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 registeredKeysthis controls. Note that eachKeycan 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 singleDataStoreor multipleDataProviders, based on the supportedDataHolders.- 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
-