Class SimpleRegistry<T>

java.lang.Object
fr.fidorial.registry.SimpleRegistry<T>
All Implemented Interfaces:
Registry<T>

public final class SimpleRegistry<T> extends Object implements Registry<T>
An immutable Registry built once from a list of keys. It does not support key(Object).
Since:
0.1.0
  • Method Details

    • of

      public static <T> SimpleRegistry<T> of(RegistryKey<T> registryKey, Collection<TypedKey<T>> keys, Function<Key,T> resolver)
      Builds a registry by resolving every key.
      Type Parameters:
      T - the value type
      Parameters:
      registryKey - the key identifying the registry
      keys - the keys to register, in order
      resolver - resolves the value of each key
      Returns:
      the registry
      Since:
      0.1.0
    • registryKey

      public RegistryKey<T> registryKey()
      Description copied from interface: Registry
      Returns the key identifying this registry.
      Specified by:
      registryKey in interface Registry<T>
      Returns:
      the key identifying this registry
    • get

      public T get(TypedKey<T> key)
      Description copied from interface: Registry
      Gets the value registered under a key.
      Specified by:
      get in interface Registry<T>
      Parameters:
      key - the key
      Returns:
      the value
    • find

      public Optional<T> find(TypedKey<T> key)
      Description copied from interface: Registry
      Returns the value registered under a key, or empty if there is none.
      Specified by:
      find in interface Registry<T>
      Parameters:
      key - the key
      Returns:
      the value registered under a key, or empty if there is none
    • key

      public TypedKey<T> key(T value)
      Description copied from interface: Registry
      Gets the key a value is registered under.
      Specified by:
      key in interface Registry<T>
      Parameters:
      value - the value
      Returns:
      its key
    • values

      public Collection<T> values()
      Description copied from interface: Registry
      Returns every registered value, in registration order.
      Specified by:
      values in interface Registry<T>
      Returns:
      every registered value, in registration order
    • stream

      public Stream<T> stream()
      Description copied from interface: Registry
      Returns a stream over every registered value, in registration order.
      Specified by:
      stream in interface Registry<T>
      Returns:
      a stream over every registered value, in registration order