Interface Registry<R extends RegistryKey,T>

Type Parameters:
R - the type of the registry key, extending RegistryKey.
T - the type of the values stored in the registry.
All Superinterfaces:
Iterable<T>
All Known Subinterfaces:
NamespacedRegistry<T>
All Known Implementing Classes:
AbstractRegistry, AbstractRegistry.Identified, AbstractRegistry.Namespaced, SocialRegistries.Channels

public interface Registry<R extends RegistryKey,T> extends Iterable<T>
The Registry interface represents a generic registry for storing and managing a collection of values, which are associated with keys that implement the RegistryKey interface.

Registries provide a way to store, retrieve, and manipulate objects based on their unique keys. The registry can store any type of object that is mapped to a particular key type R, which extends RegistryKey. Implementations of this interface will define specific behaviors for managing the registry, including registration, unregistration, and key-based lookups.

It provides methods for:

  • Registering objects to the registry
  • Unregistering objects
  • Checking if a key or value exists
  • Retrieving values associated with keys
  • Retrieving values by their type
See Also:
  • Method Details

    • identified

      static <T> Registry<IdentifiedRegistryKey,T> identified(@NotNull @NotNull Class<T> type)
      Creates and returns a registry that uses IdentifiedRegistryKey as the key type.
      Type Parameters:
      T - the type of the values.
      Parameters:
      type - the type of the values stored in the registry.
      Returns:
      a registry that uses identified keys.
    • namespaced

      static <T> NamespacedRegistry<T> namespaced(@NotNull @NotNull Class<T> type)
      Creates and returns a registry that uses NamespacedRegistryKey as the key type.
      Type Parameters:
      T - the type of the values.
      Parameters:
      type - the type of the values stored in the registry.
      Returns:
      a registry that uses namespaced keys.
    • registry

      @NotNull @NotNull Map<R,T> registry()
      Retrieves the underlying map of the registry, where the keys are the registry keys and the values are the associated objects.
      Returns:
      a Map where keys are registry keys and values are the registry values.
    • register

      void register(@NotNull R registryKey, @NotNull T value)
      Registers a value to the registry, associating it with the given registry key.
      Parameters:
      registryKey - the key to associate with the value.
      value - the value to register.
    • unregister

      @Nullable T unregister(@NotNull R registryKey)
      Unregisters a value from the registry, removing it associated with the given registry key.
      Parameters:
      registryKey - the key whose associated value should be removed.
      Returns:
      the removed value, or null if no value was associated with the key.
    • containsKey

      boolean containsKey(@NotNull R registryKey)
      Checks if a value exists in the registry for the given registry key.
      Parameters:
      registryKey - the key to check.
      Returns:
      true if the key exists in the registry, false otherwise.
    • containsValue

      boolean containsValue(@NotNull T value)
      Checks if a given value exists in the registry.
      Parameters:
      value - the value to check.
      Returns:
      true if the value exists in the registry, false otherwise.
    • value

      @NotNull @NotNull Optional<T> value(@NotNull R registryKey)
      Retrieves the value associated with the given registry key, wrapped in an Optional.
      Parameters:
      registryKey - the key whose associated value to retrieve.
      Returns:
      an Optional containing the associated value, or an empty Optional if no value is associated with the key.
    • valuesByType

      @NotNull <V extends T> @NotNull List<V> valuesByType(@NotNull @NotNull Class<V> type)
      Retrieves a list of values of a specific type associated with the registry.
      Type Parameters:
      V - the type of the values to retrieve.
      Parameters:
      type - the class type of the values to retrieve.
      Returns:
      a list of values that match the given type.
    • keys

      Retrieves a set of all the registry keys in the registry.
      Returns:
      a Set of registry keys.
    • values

      @NotNull @NotNull List<T> values()
      Retrieves a list of all the values in the registry.
      Returns:
      a List of all values in the registry.