java.lang.Object
com.github.darksoulq.abyssallib.server.registry.Registry<T>
Type Parameters:
T - The type of object being registered.
Direct Known Subclasses:
TypedRegistry

public class Registry<T> extends Object
A generic registry system for managing library objects and their associated unique identifiers.

The registry uses a BiMap to ensure that every object has exactly one ID and every ID points to exactly one object. This is essential for consistent serialization and lookup across the library.

  • Constructor Details

    • Registry

      public Registry()
  • Method Details

    • register

      public void register(String id, T object)
      Registers a new object with a unique identifier.

      If the ID is already present in the registry, the registration is rejected and a severe error is logged to the console to prevent accidental overwrites.

      Parameters:
      id - The unique string identifier for the object.
      object - The object instance to register.
    • get

      public T get(String id)
      Retrieves an object from the registry by its identifier.
      Parameters:
      id - The unique ID of the object.
      Returns:
      The registered object, or null if no object is mapped to the ID.
    • getId

      public String getId(T value)
      Retrieves the unique identifier associated with a registered object instance.
      Parameters:
      value - The object instance to look up.
      Returns:
      The string ID associated with the object, or null if the object is not registered.
    • contains

      public boolean contains(String id)
      Checks if a specific ID is currently present in the registry.
      Parameters:
      id - The identifier to check.
      Returns:
      true if an entry exists for the given ID.
    • getAll

      public Map<String,T> getAll()
      Returns an unmodifiable view of all entries currently in the registry.
      Returns:
      A Map containing all ID-to-Object mappings.
    • removeAll

      public Set<T> removeAll(String namespace)
    • remove

      @Internal public T remove(String id)
      Removes an entry from the registry by its ID.

      Warning: This method is intended for internal use only. Removing entries from a registry at runtime can cause significant issues with existing data references and serialization.

      Parameters:
      id - The ID of the entry to remove.
      Returns:
      The object that was removed, or null if the ID was not found.
    • clear

      @Internal public void clear()