Class RegistryComponent<R extends Registry<T>,T extends Identifiable,K,V>

java.lang.Object
net.orbyfied.j8.registry.RegistryComponent<R,T,K,V>
Type Parameters:
R - The type of registry.
T - The type of base item.
K - The keys it stores (for mapping).
V - The values it stores (mapping and linear).

public abstract class RegistryComponent<R extends Registry<T>,T extends Identifiable,K,V> extends Object
An extension to a registry. Allows for more complex storage of items.
  • Field Details

  • Constructor Details

    • RegistryComponent

      public RegistryComponent(R registry)
      Constructor.
  • Method Details

    • getRegistry

      public R getRegistry()
      Gets the registry this component has been assigned to.
      Returns:
      The registry reference.
    • getKeyType

      public abstract Class<K> getKeyType()
      Gets the runtime key type of the storage.
      Returns:
      The key type.
    • getValueType

      public abstract Class<V> getValueType()
      Gets the runtime value type of the storage.
      Returns:
      The value type.
    • isLinear

      public abstract boolean isLinear()
      Gets if the storage is linear, so if it is stored in an ordered list.
      Returns:
      If it is.
    • isMapped

      public abstract boolean isMapped()
      Gets if the storage is mapped, so if it is stored in a quick lookup map.
      Returns:
      If it is.
    • getKeyFactory

      public Function<T,K> getKeyFactory()
      Returns the item to key factory.
      Returns:
      The function.
    • getValueFactory

      public Function<T,V> getValueFactory()
      Returns the item to value factory.
      Returns:
      The function.
    • getKeyFromValueFactory

      public Function<V,K> getKeyFromValueFactory()
      Returns the value to key factory.
      Returns:
      The function.
    • getKeyFromValue

      public K getKeyFromValue(V val)
      Utilizes the value to key factory to get the key from the provided value.
      Parameters:
      val - The value.
      Returns:
      The key.
    • getValueOf

      public V getValueOf(T t)
      Utilizes the item to value factory to get the value of the provided item.
      Parameters:
      t - The item.
      Returns:
      The value.
    • getKeyOf

      public K getKeyOf(T t)
      Utilizes the item to key factory to get the key of the provided item.
      Parameters:
      t - The item.
      Returns:
      The key.
    • getLinear

      public abstract V getLinear(int index)
      Gets the value at the given index.
      Parameters:
      index - The index to use.
      Returns:
      The value.
      Throws:
      UnsupportedOperationException - Might be thrown by an implementation if linear storage is not supported. Check isLinear()
    • getMapped

      public abstract V getMapped(K key)
      Gets the value mapped to the given key.
      Parameters:
      key - The key to look up.
      Returns:
      The value or null.
      Throws:
      UnsupportedOperationException - Might be thrown by an implementation if mapped storage is not supported. Check isMapped()
    • getMapped

      public V getMapped(T key)
      Gets the value corresponding with the given item.
      Parameters:
      key - The item.
      Returns:
      The value.
      See Also:
    • register

      public abstract RegistryComponent<R,T,K,V> register(V value)
      Registers a value to the storage. Should utilize the key factory to get the key for mapping.
      Parameters:
      value - The value to register.
      Returns:
      This.
    • register

      public RegistryComponent<R,T,K,V> register(T item)
      Utilizes the value factory in the default implementation.
      See Also:
    • unregister

      public abstract RegistryComponent<R,T,K,V> unregister(K key)
      Unregisters a key from the storage. Should utilize the key factory to get the key for mapping.
      Parameters:
      key - The key to unregister.
      Returns:
      This.
    • unregister

      public RegistryComponent<R,T,K,V> unregister(T item)
      Utilizes the key factory in the default implementation.
      See Also: