Class KeyValueProvider<K,V>
java.lang.Object
org.hibernate.search.util.common.data.spi.KeyValueProvider<K,V>
- Type Parameters:
K
- The type of keys.V
- The type of values.
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 Summary
ConstructorsConstructorDescriptionKeyValueProvider
(Map<K, ? extends V> content, BiFunction<? super K, ? super Set<K>, SearchException> singleMissingValueExceptionFactory) -
Method Summary
Modifier and TypeMethodDescriptionstatic <K,
V> KeyValueProvider<K, V> create
(Map<K, ? extends V> content, BiFunction<? super K, ? super Set<K>, SearchException> missingValueExceptionFactory) static <K,
V> KeyValueProvider<K, V> create
(Map<K, ? extends V> content, BiFunction<? super K, ? super Set<K>, SearchException> singleMissingValueExceptionFactory, BiFunction<? super Set<K>, ? super Set<K>, SearchException> multiMissingValueExceptionFactory) static <K,
V> KeyValueProvider<K, V> createWithMultiKeyException
(Map<K, ? extends V> content, BiFunction<? super Set<K>, ? super Set<K>, SearchException> missingValueExceptionFactory) getAllOrFail
(Collection<? extends K> keys) <V2> List<V2>
getAllOrFail
(Collection<? extends K> keys, BiFunction<K, V, V2> transform) getOptional
(K key) keys()
Collection<? extends V>
values()
-
Constructor Details
-
KeyValueProvider
public KeyValueProvider(Map<K, ? extends V> content, BiFunction<? super K, ? super Set<K>, SearchException> singleMissingValueExceptionFactory)
-
-
Method Details
-
create
public static <K,V> KeyValueProvider<K,V> create(Map<K, ? extends V> content, BiFunction<? super K, ? super Set<K>, SearchException> missingValueExceptionFactory) -
create
public static <K,V> KeyValueProvider<K,V> create(Map<K, ? extends V> content, BiFunction<? super K, ? super Set<K>, SearchException> singleMissingValueExceptionFactory, BiFunction<? super Set<K>, ? super Set<K>, SearchException> multiMissingValueExceptionFactory) -
createWithMultiKeyException
public static <K,V> KeyValueProvider<K,V> createWithMultiKeyException(Map<K, ? extends V> content, BiFunction<? super Set<K>, ? super Set<K>, SearchException> missingValueExceptionFactory) -
getOrFail
-
getAllOrFail
-
getAllOrFail
-
getOptional
-
getOrNull
-
keys
-
values
-