Interface KeyValuesCollection
- All Known Implementing Classes:
GetPrefixResponse,GetResponse,KeyValuesCollection.Empty,KeyValuesCollectionMapImpl
key values.
Use in conjunction with KeyValuesCollectionParser to deserialize into appropriate
objects.
An important use case for KeyValuesCollection is in KeyValuesCollectionListener.
To aid in efficient updating of a collection, the data structure necessarily needs to be mutable.
(Not *quite* true - we *could* eventually use something like vavr for immutable underlying data
structures that still allow for efficient updating.) As such, users of a KeyValuesCollection
need to be aware that they can't keep references of it around without calling
asImmutable().
Provides essential context and operations for a Map<KeyPath, KeyValue>-like structure.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumAn empty key values collection -
Method Summary
Modifier and TypeMethodDescriptionReturns an immutable version ofthis.asMap()Return an unmodifiable map representing this collection.default booleancontainsKey(KeyPath keyPath) Equivalent toasMap().containsKey(keyPath).Equivalent toOptional.ofNullable(asMap().get(keyPath)).default booleanisEmpty()Equivalent toasMap().isEmpty().keys()Equivalent toasMap().keySet().default Collection<KeyValue>Equivalent toasMap().values().
-
Method Details
-
asMap
Return an unmodifiable map representing this collection.Note: it is not necessarily the case that this map is immutable. If an immutable map is needed, use
asImmutable().asMap().- Returns:
- the unmodifiable map
-
asImmutable
KeyValuesCollection asImmutable()Returns an immutable version ofthis. May returnthisif it is immutable. Ensures that the caller can keep around their own immutable version.- Returns:
- an immutable version of
this
-
containsKey
Equivalent toasMap().containsKey(keyPath).- Parameters:
keyPath- the key path to test- Returns:
- true iff the key path is contained in this collection
-
get
Equivalent toOptional.ofNullable(asMap().get(keyPath)).- Parameters:
keyPath- the key path- Returns:
- the key value if present
-
keys
Equivalent toasMap().keySet(). Thus, the set is unmodifiable.Note: it is not necessarily the case that this set is immutable. If an immutable set is needed, use
asImmutable().keys().- Returns:
- the unmodifiable key paths of this collection
-
keyValues
Equivalent toasMap().values(). Thus, the collection is unmodifiable.Note: it is not necessarily the case that this collection is immutable. If an immutable collection is needed, use
asImmutable().keyValues().- Returns:
- the unmodifiable key values of this collection
-
isEmpty
default boolean isEmpty()Equivalent toasMap().isEmpty().- Returns:
- true iff the collection is empty
-