Package org.apache.flink.util
Class LinkedOptionalMap<K,V>
- java.lang.Object
-
- org.apache.flink.util.LinkedOptionalMap<K,V>
-
@Internal public final class LinkedOptionalMap<K,V> extends Object
A LinkedOptionalMap is an order preserving map (likeLinkedHashMap) where keys have a unique string name, but are optionally present, and the values are optional.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceLinkedOptionalMap.ConsumerWithException<K,V,E extends Throwable>AConsumerthat throws exceptions.static classLinkedOptionalMap.KeyValue<K,V>Key-value pairs stored by the underlying map.static classLinkedOptionalMap.MergeResult<K,V>The result of merging twoLinkedOptionalMaps usingmergeRightIntoLeft(LinkedOptionalMap, LinkedOptionalMap).
-
Constructor Summary
Constructors Constructor Description LinkedOptionalMap()LinkedOptionalMap(int initialSize)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Set<String>absentKeysOrValues()Returns the key names of any keys or values that are absent.<E extends Throwable>
voidforEach(LinkedOptionalMap.ConsumerWithException<K,V,E> consumer)Set<LinkedOptionalMap.KeyValue<K,V>>getPresentEntries()booleanhasAbsentKeysOrValues()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, Function<K,String> keyNameGetter)Creates anLinkedOptionalMapfrom the provided map.voidput(String keyName, K key, V value)intsize()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.
-
-
-
Method Detail
-
optionalMapOf
public static <K,V> LinkedOptionalMap<K,V> optionalMapOf(Map<K,V> sourceMap, Function<K,String> keyNameGetter)
Creates anLinkedOptionalMapfrom the provided map.This method is the equivalent of
Optional.of(Object)but for maps. To support more than oneNULLkey, an optional map requires a unique string name to be associated with each key (provided by keyNameGetter)- Type Parameters:
K- key typeV- value type- Parameters:
sourceMap- a source map to wrap as an optional map.keyNameGetter- function that assigns a unique name to the keys of the source map.- Returns:
- an
LinkedOptionalMapwith optional named keys, and optional values.
-
mergeRightIntoLeft
public 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.
-
size
public int size()
-
absentKeysOrValues
public Set<String> absentKeysOrValues()
Returns the key names of any keys or values that are absent.
-
hasAbsentKeysOrValues
public boolean hasAbsentKeysOrValues()
Checks whether there are entries with absent keys or values.
-
forEach
public <E extends Throwable> void forEach(LinkedOptionalMap.ConsumerWithException<K,V,E> consumer) throws E extends Throwable
- Throws:
E extends Throwable
-
getPresentEntries
public Set<LinkedOptionalMap.KeyValue<K,V>> getPresentEntries()
-
unwrapOptionals
public 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. NOTE: please note that if any of the key or values are absent this method would throw anIllegalStateException.
-
-