Class LinkedOptionalMap<K,​V>


  • @Internal
    public final class LinkedOptionalMap<K,​V>
    extends Object
    A LinkedOptionalMap is an order preserving map (like LinkedHashMap) where keys have a unique string name, but are optionally present, and the values are optional.
    • Constructor Detail

      • LinkedOptionalMap

        public LinkedOptionalMap()
      • LinkedOptionalMap

        public LinkedOptionalMap​(int initialSize)
    • Method Detail

      • optionalMapOf

        public static <K,​V> LinkedOptionalMap<K,​V> optionalMapOf​(Map<K,​V> sourceMap,
                                                                             Function<K,​String> keyNameGetter)
        Creates an 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)

        Type Parameters:
        K - key type
        V - 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 LinkedOptionalMap with optional named keys, and optional values.
      • size

        public int size()
      • put

        public void put​(String keyName,
                        @Nullable
                        K key,
                        @Nullable
                        V value)
      • 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.
      • 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 an IllegalStateException.
      • keyNames

        public Set<String> keyNames()
        Returns the key names added to this map.