Interface KeyValuesCollection

All Known Implementing Classes:
GetPrefixResponse, GetResponse, KeyValuesCollection.Empty, KeyValuesCollectionMapImpl

public interface KeyValuesCollection
Represents a collection of 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.

  • Method Details

    • asMap

      Map<KeyPath,KeyValue> 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 of this. May return this if it is immutable. Ensures that the caller can keep around their own immutable version.
      Returns:
      an immutable version of this
    • containsKey

      default boolean containsKey(KeyPath keyPath)
      Equivalent to asMap().containsKey(keyPath).
      Parameters:
      keyPath - the key path to test
      Returns:
      true iff the key path is contained in this collection
    • get

      default Optional<KeyValue> get(KeyPath keyPath)
      Equivalent to Optional.ofNullable(asMap().get(keyPath)).
      Parameters:
      keyPath - the key path
      Returns:
      the key value if present
    • keys

      default Set<KeyPath> keys()
      Equivalent to asMap().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

      default Collection<KeyValue> keyValues()
      Equivalent to asMap().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 to asMap().isEmpty().
      Returns:
      true iff the collection is empty