Class KeyValueProvider<K,V>

Type Parameters:
K - The type of keys.
V - The type of values.

public final class KeyValueProvider<K,V> extends Object
A simpler, safer, read-only wrapper around Map that exposes only a few methods to retrieve a value from a given key.

Methods either makes it clear there might be no value (through the method name or Optional return type) or are guaranteed to throw an exception when no value can be found, with a meaningful message (including a list of all available keys).

This class only makes sense where there is a relatively low number of keys, as exception messages will include a list of all available keys.

  • Constructor Details

  • Method Details

    • getOrFail

      public V getOrFail(K key)
    • getOptional

      public Optional<V> getOptional(K key)
    • getOrNull

      public V getOrNull(K key)
    • values

      public Collection<? extends V> values()