Package org.spongepowered.api.registry
Interface Registry<T>
-
- Type Parameters:
T
- The type
@DoNotStore public interface Registry<T>
A store ofregistry entries
with a well defined type.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default <V extends T>
java.util.Optional<RegistryEntry<V>>findEntry(RegistryKey<T> key)
findEntry(ResourceKey)
, provided for convenience when usingRegistryKey
.<V extends T>
java.util.Optional<RegistryEntry<V>>findEntry(ResourceKey key)
default <V extends T>
java.util.Optional<V>findValue(RegistryKey<T> key)
findValue(ResourceKey)
, provided for convenience when usingRegistryKey
.<V extends T>
java.util.Optional<V>findValue(ResourceKey key)
java.util.Optional<ResourceKey>
findValueKey(T value)
Gets thekey
for a particular value, if found.boolean
isDynamic()
Returns if this registry supports adding additional values.<V extends T>
java.util.Optional<RegistryEntry<V>>register(ResourceKey key, V value)
Registers a new value to this registry.java.util.stream.Stream<T>
stream()
Gets aStream
of all registry values within.java.util.stream.Stream<RegistryEntry<T>>
streamEntries()
Gets aStream
of allentries
within.RegistryType<T>
type()
Gets thekey
identifying this registry.default <V extends T>
Vvalue(RegistryKey<T> key)
value(ResourceKey)
, provided for convenience when usingRegistryKey
.<V extends T>
Vvalue(ResourceKey key)
ResourceKey
valueKey(T value)
Gets thekey
for a particular value.
-
-
-
Method Detail
-
type
RegistryType<T> type()
Gets thekey
identifying this registry.- Returns:
- The key
-
valueKey
ResourceKey valueKey(T value)
Gets thekey
for a particular value.Great care needs to be made in calling this method with any uncertainty as to if the key will exist. Should the value lack a key, a
IllegalStateException
will be thrown. Therefore, it is advised to callfindValueKey(Object)
instead.- Parameters:
value
- The value- Returns:
- The key
-
findValueKey
java.util.Optional<ResourceKey> findValueKey(T value)
Gets thekey
for a particular value, if found.The value must be registered within to be retrieved by key.
- Parameters:
value
- The value- Returns:
- The key or
Optional.empty()
-
findEntry
<V extends T> java.util.Optional<RegistryEntry<V>> findEntry(ResourceKey key)
Gets theentry
for a particularkey
, if found.The value must be registered within to be retrieved by key.
- Parameters:
key
- The key- Returns:
- The entry or
Optional.empty()
-
findEntry
default <V extends T> java.util.Optional<RegistryEntry<V>> findEntry(RegistryKey<T> key)
findEntry(ResourceKey)
, provided for convenience when usingRegistryKey
.- Parameters:
key
- The key- Returns:
- The entry or
Optional.empty()
-
findValue
<V extends T> java.util.Optional<V> findValue(ResourceKey key)
- Parameters:
key
- The key- Returns:
- The value or
Optional.empty()
-
findValue
default <V extends T> java.util.Optional<V> findValue(RegistryKey<T> key)
findValue(ResourceKey)
, provided for convenience when usingRegistryKey
.- Parameters:
key
- The key- Returns:
- The value or
Optional.empty()
-
value
<V extends T> V value(ResourceKey key)
Gets thevalue
for a particularkey
.Great care needs to be made in calling this method with any uncertainty as to if the key will exist. Should this key lack a value, a
ValueNotFoundException
will be thrown. Therefore, it is advised to callfindValue(ResourceKey)
orfindValue(RegistryKey)
instead.- Parameters:
key
- The key- Returns:
- The value
-
value
default <V extends T> V value(RegistryKey<T> key)
value(ResourceKey)
, provided for convenience when usingRegistryKey
.- Parameters:
key
- The key- Returns:
- The value
-
streamEntries
java.util.stream.Stream<RegistryEntry<T>> streamEntries()
Gets aStream
of allentries
within.- Returns:
- The stream
-
stream
java.util.stream.Stream<T> stream()
Gets aStream
of all registry values within.- Returns:
- The stream
-
isDynamic
boolean isDynamic()
Returns if this registry supports adding additional values.- Returns:
- True if the registry can add additional values
-
register
<V extends T> java.util.Optional<RegistryEntry<V>> register(ResourceKey key, V value)
Registers a new value to this registry.If this registry is not
dynamic
or the provided key is already registered,Optional.empty()
is returned instead.- Parameters:
key
- The keyvalue
- The value- Returns:
- The newly added entry,
Optional.empty()
otherwise
-
-