Class AbstractRegistry<T extends RegistryKey<K>,K>

java.lang.Object
net.paulem.arcana.registry.AbstractRegistry<T,K>
Type Parameters:
T - the type
All Implemented Interfaces:
Registry<T,K>
Direct Known Subclasses:
FrozenRegistry, WriteableRegistry

public abstract class AbstractRegistry<T extends RegistryKey<K>,K> extends Object implements Registry<T,K>
A basic abstract implementation of Registry
Since:
1.0.0-SNAPSHOT
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final Map<K,T>
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    AbstractRegistry(Supplier<Map<K,T>> registrySupplier)
    Creates a new registry backed by the map produced by the given supplier.
  • Method Summary

    Modifier and Type
    Method
    Description
    get(K key)
    Fetches an entry from the registry
    getOrDefault(K key, @NotNull Supplier<T> defaultValue)
    Fetches the value at the given key or a provided default key
    getOrDefault(K key, T defaultValue)
    Fetches the value at the given key or a provided default key
    getOrNull(K key)
    Fetches an entry from the registry
    Fetches an entry from the registry using the specified key or throws an exception if no entry exists.
    Retrieves a set of all keys from the registry

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • AbstractRegistry

      protected AbstractRegistry(Supplier<Map<K,T>> registrySupplier)
      Creates a new registry backed by the map produced by the given supplier.
      Parameters:
      registrySupplier - supplies the backing map used to store registered objects
  • Method Details

    • get

      public Optional<T> get(@NotNull K key)
      Fetches an entry from the registry
      Specified by:
      get in interface Registry<T extends RegistryKey<K>,K>
      Parameters:
      key - the key to use to fetch the entry
      Returns:
      an optional wrapping the nullable result
    • getOrNull

      public T getOrNull(@NotNull K key)
      Fetches an entry from the registry
      Specified by:
      getOrNull in interface Registry<T extends RegistryKey<K>,K>
      Parameters:
      key - the key to use to fetch the entry
      Returns:
      the resulting object at that key, or null if it doesn't exist
    • getOrDefault

      @NotNull public T getOrDefault(@NotNull K key, @NotNull T defaultValue)
      Fetches the value at the given key or a provided default key
      Specified by:
      getOrDefault in interface Registry<T extends RegistryKey<K>,K>
      Parameters:
      key - the key
      defaultValue - the default value given the key has no value
      Returns:
      a non null value from either the key or default
    • getOrDefault

      @NotNull public T getOrDefault(@NotNull K key, @NotNull @NotNull Supplier<T> defaultValue)
      Fetches the value at the given key or a provided default key
      Specified by:
      getOrDefault in interface Registry<T extends RegistryKey<K>,K>
      Parameters:
      key - the key
      defaultValue - the default value function triggered if the key has no value
      Returns:
      a non null value from either the key or default
    • getOrThrow

      @NotNull public T getOrThrow(@NotNull K key)
      Fetches an entry from the registry using the specified key or throws an exception if no entry exists.
      Specified by:
      getOrThrow in interface Registry<T extends RegistryKey<K>,K>
      Parameters:
      key - the key to fetch the entry from the registry
      Returns:
      the entry corresponding to the specified key
    • keys

      public Set<K> keys()
      Retrieves a set of all keys from the registry
      Specified by:
      keys in interface Registry<T extends RegistryKey<K>,K>
      Returns:
      a set of string keys