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 DataHolder
s, it's required to use a
DataRegistration
if the data is needed to be serialized, or dynamically
provided for through external mechanisms, through DataProvider
s.
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 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
-
Method Summary
Modifier and TypeMethodDescriptionstatic Key.Builder
<?, ?> builder()
Creates aKey.Builder
which allows creation of aKey
to later be registered for accessing values from aValueContainer
.Comparator
<?> Gets theComparator
to 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.Builder
which allows creation of aKey
to later be registered for accessing values from aValueContainer
. It is the default policy that a custom createdKey
is NOT PERSISTENT by Sponge. If custom keys forDataHolder
s is desired to be persisted, aDataRegistration
is 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 theValue
thisKey
is representing. On occasion, if the element is aCollection
type, one can useParameterizedType.getActualTypeArguments()
to access type parameters, such as the element type parameter forList
orMap
values.- Returns:
- The element generic type
-
elementComparator
Comparator<?> elementComparator()Gets theComparator
to compare values of this key.- Returns:
- The value comparator
-
elementIncludesTester
BiPredicate<?,?> elementIncludesTester()Gets the includes testerBiPredicate
. This predicate should returntrue
when 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
-