Package org.spongepowered.api.data
Interface DataRegistration
-
public interface DataRegistrationAn optional registration ofkeysto associate a semi-persistent state of their associatedvaluesthat can be stored, retrieved, persisted, and/or associated withDataHolders. A registration identifies the givenKeysare provided by an implementation for specificDataHoldersthat may support and not support thosekeys. All API providedkeysexposed through theKeysclass will have an associated registration by the implementation of the API, whether they are usable throughDataProvidersorDataStores.If dynamic or persistent retention of the
Valuesbykeysis not desired, a registration is optional. This would mean that any submittedValues of aKeywithout an associatedDataRegistrationwill be only stored on amutable DataHolderfor 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 interfaceDataRegistration.BuilderA standard builder for constructing newDataRegistrations.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static DataRegistration.Builderbuilder()Creates a newDataRegistration.Builderto build aDataRegistration.Optional<DataStore>dataStore(io.leangen.geantyref.TypeToken<? extends DataHolder> token)Gets the appropriateDataStorefor the context of theTypeTokenthat is being serialized/deserialized.Optional<DataStore>dataStore(Class<? extends DataHolder> token)Gets the appropriateDataStorefor the context of theTypeTokenthat is being serialized/deserialized.Iterable<Key<?>>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 Detail
-
builder
static DataRegistration.Builder 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
Optional<DataStore> dataStore(io.leangen.geantyref.TypeToken<? extends DataHolder> token)
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
Optional<DataStore> dataStore(Class<? extends DataHolder> token)
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
Iterable<Key<?>> 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
-
-