Package org.spongepowered.api.data
Interface Key<V extends Value<?>>
-
- Type Parameters:
V
- The type ofValue
- All Superinterfaces:
Keyed
,ResourceKeyed
@CatalogedBy(Keys.class) public interface Key<V extends Value<?>> extends ResourceKeyed
Represents a key to an underlyingValue
such that the underlying value can be retrieved from aValueContainer
. For the key to be used through retrieval ofDataHolder
s, it's required to use aDataRegistration
if the data is needed to be serialized, or dynamically provided for through external mechanisms, throughDataProvider
s.If dynamic or persistent retention of the
Values
bykeys
is not desired, a registration withDataRegistration
is optional. This would mean that any submittedValue
s of aKey
without an associatedDataRegistration
will be only stored on amutable DataHolder
for 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 interface
Key.Builder<E,V extends Value<E>>
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static Key.Builder<?,?>
builder()
Creates aKey.Builder
which allows creation of aKey
to later be registered for accessing values from aValueContainer
.Comparator<?>
elementComparator()
Gets theComparator
to compare values of this key.BiPredicate<?,?>
elementIncludesTester()
Gets the includes testerBiPredicate
.Type
elementType()
static <E> Key<Value<E>>
from(ResourceKey resourceKey, Class<E> type)
static <V> Key<Value<V>>
from(org.spongepowered.plugin.PluginContainer plugin, String value, Class<V> type)
static <E> Key<ListValue<E>>
fromList(ResourceKey resourceKey, Class<E> type)
static <V> Key<ListValue<V>>
fromList(org.spongepowered.plugin.PluginContainer plugin, String value, Class<V> type)
static <K,V>
Key<MapValue<K,V>>fromMap(ResourceKey resourceKey, Class<K> keyType, Class<V> valueType)
static <K,V>
Key<MapValue<K,V>>fromMap(org.spongepowered.plugin.PluginContainer plugin, String value, Class<K> keyType, Class<V> valueType)
static <E> Key<SetValue<E>>
fromSet(ResourceKey resourceKey, Class<E> type)
static <V> Key<SetValue<V>>
fromSet(org.spongepowered.plugin.PluginContainer plugin, String value, Class<V> 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.Type
valueType()
-
Methods inherited from interface org.spongepowered.api.ResourceKeyed
key
-
-
-
-
Method Detail
-
builder
static Key.Builder<?,?> 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:
DataRegistration
-
from
static <V> Key<Value<V>> from(org.spongepowered.plugin.PluginContainer plugin, String value, Class<V> type)
-
from
static <E> Key<Value<E>> from(ResourceKey resourceKey, Class<E> type)
-
fromList
static <V> Key<ListValue<V>> fromList(org.spongepowered.plugin.PluginContainer plugin, String value, Class<V> type)
-
fromList
static <E> Key<ListValue<E>> fromList(ResourceKey resourceKey, Class<E> type)
-
fromSet
static <V> Key<SetValue<V>> fromSet(org.spongepowered.plugin.PluginContainer plugin, String value, Class<V> type)
-
fromSet
static <E> Key<SetValue<E>> fromSet(ResourceKey resourceKey, Class<E> type)
-
fromMap
static <K,V> Key<MapValue<K,V>> fromMap(org.spongepowered.plugin.PluginContainer plugin, String value, Class<K> keyType, Class<V> valueType)
-
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:
KeyValueMatcher.Operator.INCLUDES
,KeyValueMatcher.Operator.EXCLUDES
-
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
-
-