Interface KeyContainer

All Known Subinterfaces:
DynamicKeyContainer, MutableKeyContainer

public interface KeyContainer
A generic container for key-value pairs. Like a Map<String, Object>, but with type safety.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    contains(Key<?> key)
    Returns whether the registry contains a value associated with the given key.
    Returns an empty container.
    from(KeyContainer container)
    Returns an immutable view of the given container.
    default <V> @Nullable V
    get(Key<V> key)
    Returns the value associated with the given key, or null if it does not exist.
    Set<Key<?>>
    Returns an immutable view of the keys in the registry.
    <V> Optional<V>
    getOptional(Key<V> key)
    Returns the value associated with the given key.
    default <V> V
    getRequired(Key<V> key)
    Returns the value associated with the given key or throws a NPE if it's missing.
  • Method Details

    • empty

      static KeyContainer empty()
      Returns an empty container.
      Returns:
      the empty container
    • from

      static KeyContainer from(KeyContainer container)
      Returns an immutable view of the given container.
      Parameters:
      container - the container
      Returns:
      the new container
    • getOptional

      <V> Optional<V> getOptional(Key<V> key)
      Returns the value associated with the given key.
      Type Parameters:
      V - the type of the value
      Parameters:
      key - the key
      Returns:
      the value
    • getRequired

      default <V> V getRequired(Key<V> key)
      Returns the value associated with the given key or throws a NPE if it's missing.
      Type Parameters:
      V - the type of the value
      Parameters:
      key - the key
      Returns:
      the value
      Throws:
      NullPointerException - if the value is missing
    • get

      default <V> @Nullable V get(Key<V> key)
      Returns the value associated with the given key, or null if it does not exist.
      Type Parameters:
      V - the type of the value
      Parameters:
      key - the key
      Returns:
      the value, or null if it does not exist
    • contains

      boolean contains(Key<?> key)
      Returns whether the registry contains a value associated with the given key.
      Parameters:
      key - the key
      Returns:
      true if the value exists, or false if it does not
    • getKeys

      Set<Key<?>> getKeys()
      Returns an immutable view of the keys in the registry.