@Internal public final class LinkedOptionalMap<K,V> extends Object
LinkedHashMap
) where keys have a
unique string name, but are optionally present, and the values are optional.Modifier and Type | Class and Description |
---|---|
static interface |
LinkedOptionalMap.ConsumerWithException<K,V,E extends Throwable>
A
Consumer that throws exceptions. |
static class |
LinkedOptionalMap.KeyValue<K,V>
Key-value pairs stored by the underlying map.
|
static class |
LinkedOptionalMap.MergeResult<K,V>
The result of merging two
LinkedOptionalMap s using mergeRightIntoLeft(LinkedOptionalMap, LinkedOptionalMap) . |
Constructor and Description |
---|
LinkedOptionalMap() |
LinkedOptionalMap(int initialSize) |
Modifier and Type | Method and Description |
---|---|
Set<String> |
absentKeysOrValues()
Returns the key names of any keys or values that are absent.
|
<E extends Throwable> |
forEach(LinkedOptionalMap.ConsumerWithException<K,V,E> consumer) |
Set<LinkedOptionalMap.KeyValue<K,V>> |
getPresentEntries() |
boolean |
hasAbsentKeysOrValues()
Checks whether there are entries with absent keys or values.
|
Set<String> |
keyNames()
Returns the key names added to this map.
|
static <K,V> LinkedOptionalMap.MergeResult<K,V> |
mergeRightIntoLeft(LinkedOptionalMap<K,V> left,
LinkedOptionalMap<K,V> right)
Tries to merges the keys and the values of @right into @left.
|
static <K,V> LinkedOptionalMap<K,V> |
optionalMapOf(Map<K,V> sourceMap,
java.util.function.Function<K,String> keyNameGetter)
Creates an
LinkedOptionalMap from the provided map. |
void |
put(String keyName,
K key,
V value) |
int |
size() |
LinkedHashMap<K,V> |
unwrapOptionals()
Assuming all the entries of this map are present (keys and values) this method would return a
map with these key and values, stripped from their Optional wrappers.
|
public LinkedOptionalMap()
public LinkedOptionalMap(int initialSize)
public static <K,V> LinkedOptionalMap<K,V> optionalMapOf(Map<K,V> sourceMap, java.util.function.Function<K,String> keyNameGetter)
LinkedOptionalMap
from the provided map.
This method is the equivalent of Optional.of(Object)
but for maps. To support more
than one NULL
key, an optional map requires a unique string name to be associated
with each key (provided by keyNameGetter)
K
- key typeV
- value typesourceMap
- a source map to wrap as an optional map.keyNameGetter
- function that assigns a unique name to the keys of the source map.LinkedOptionalMap
with optional named keys, and optional values.public static <K,V> LinkedOptionalMap.MergeResult<K,V> mergeRightIntoLeft(LinkedOptionalMap<K,V> left, LinkedOptionalMap<K,V> right)
public int size()
public Set<String> absentKeysOrValues()
public boolean hasAbsentKeysOrValues()
public <E extends Throwable> void forEach(LinkedOptionalMap.ConsumerWithException<K,V,E> consumer) throws E extends Throwable
E extends Throwable
public Set<LinkedOptionalMap.KeyValue<K,V>> getPresentEntries()
public LinkedHashMap<K,V> unwrapOptionals()
IllegalStateException
.Copyright © 2014–2021 The Apache Software Foundation. All rights reserved.