Package org.spongepowered.api.data
Interface Key<V extends Value<?>>
- Type Parameters:
V- The type ofValue
- All Superinterfaces:
Keyed,ResourceKeyed
Represents a key to an underlying
Value such that the underlying
value can be retrieved from a ValueContainer. For the key to be used
through retrieval of DataHolders, it's required to use a
DataRegistration if the data is needed to be serialized, or dynamically
provided for through external mechanisms, through DataProviders.
If dynamic or persistent retention of the Values by
keys is not desired, a registration with DataRegistration
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 Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic Key.Builder<?, ?> builder()Creates aKey.Builderwhich allows creation of aKeyto later be registered for accessing values from aValueContainer.Comparator<?> Gets theComparatorto compare values of this key.BiPredicate<?, ?> Gets the includes testerBiPredicate.from(ResourceKey resourceKey, Class<E> type) fromList(ResourceKey resourceKey, Class<E> type) fromMap(ResourceKey resourceKey, Class<K> keyType, Class<V> valueType) fromMap(org.spongepowered.plugin.PluginContainer plugin, String value, Class<K> keyType, Class<V> valueType) fromSet(ResourceKey resourceKey, Class<E> type) <E extends DataHolder>
voidregisterEvent(org.spongepowered.plugin.PluginContainer plugin, Class<E> holderFilter, EventListener<ChangeDataHolderEvent.ValueChange> listener) Register an event listener which listens to the value the key accesses changing.Methods inherited from interface org.spongepowered.api.ResourceKeyed
key
-
Method Details
-
builder
Creates aKey.Builderwhich allows creation of aKeyto later be registered for accessing values from aValueContainer. It is the default policy that a custom createdKeyis NOT PERSISTENT by Sponge. If custom keys forDataHolders is desired to be persisted, aDataRegistrationis required.- Returns:
- The key builder
- See Also:
-
from
-
from
-
fromList
-
fromList
-
fromSet
-
fromSet
-
fromMap
-
fromMap
static <K,V> Key<MapValue<K,V>> fromMap(ResourceKey resourceKey, Class<K> keyType, Class<V> valueType) -
valueType
Type valueType()- Returns:
- The value generic type
-
elementType
Type elementType()Gets the type of the element of theValuethisKeyis representing. On occasion, if the element is aCollectiontype, one can useParameterizedType.getActualTypeArguments()to access type parameters, such as the element type parameter forListorMapvalues.- Returns:
- The element generic type
-
elementComparator
Comparator<?> elementComparator()Gets theComparatorto compare values of this key.- Returns:
- The value comparator
-
elementIncludesTester
BiPredicate<?,?> elementIncludesTester()Gets the includes testerBiPredicate. This predicate should returntruewhen the second parameter (the key value) is included in the first one (the matcher value).The default tester will always return
false.- Returns:
- The includes tester bi predicate
- See Also:
-
registerEvent
<E extends DataHolder> void registerEvent(org.spongepowered.plugin.PluginContainer plugin, Class<E> holderFilter, EventListener<ChangeDataHolderEvent.ValueChange> listener) Register an event listener which listens to the value the key accesses changing.- Type Parameters:
E- The class type of the data holder- Parameters:
holderFilter- The data holder to filter withlistener- The event listener
-