Class KVNavigableMap

All Implemented Interfaces:
Map<byte[],byte[]>, NavigableMap<byte[],byte[]>, SortedMap<byte[],byte[]>

public class KVNavigableMap extends AbstractKVNavigableMap<byte[],byte[]>
A NavigableMap view of the keys and values in a KVStore.

Instances are mutable, with these exceptions:

  • Constructor Details

    • KVNavigableMap

      public KVNavigableMap(KVStore kv)
      Constructor for when there are no range restrictions.
      Parameters:
      kv - underlying KVStore
    • KVNavigableMap

      public KVNavigableMap(KVStore kv, byte[] prefix)
      Constructor for when the range of visible KVStore keys is all keys sharing a given byte[] prefix.
      Parameters:
      kv - underlying KVStore
      prefix - prefix defining minimum and maximum keys
      Throws:
      NullPointerException - if prefix is null
    • KVNavigableMap

      protected KVNavigableMap(KVStore kv, boolean reversed, KeyRange keyRange, KeyFilter keyFilter)
      Primary constructor.
      Parameters:
      kv - underlying KVStore
      reversed - whether ordering is reversed
      keyRange - key range restriction, or null for none
      keyFilter - key filter, or null for none
      Throws:
      IllegalArgumentException - if kv is null
  • Method Details

    • comparator

      public Comparator<byte[]> comparator()
    • put

      public byte[] put(byte[] key, byte[] value)
      Specified by:
      put in interface Map<byte[],byte[]>
      Overrides:
      put in class AbstractMap<byte[],byte[]>
    • remove

      public byte[] remove(Object obj)
      Description copied from class: AbstractNavigableMap
      Removes the mapping for a key from this map if it is present.

      The implementation in AbstractNavigableMap always throws UnsupportedOperationException.

      Specified by:
      remove in interface Map<byte[],byte[]>
      Overrides:
      remove in class AbstractNavigableMap<byte[],byte[]>
    • clear

      public void clear()
      Specified by:
      clear in interface Map<byte[],byte[]>
      Overrides:
      clear in class AbstractMap<byte[],byte[]>
    • containsKey

      public boolean containsKey(Object obj)
      Specified by:
      containsKey in interface Map<byte[],byte[]>
      Overrides:
      containsKey in class AbstractNavigableMap<byte[],byte[]>
    • encodeKey

      protected void encodeKey(ByteWriter writer, Object obj)
      Description copied from class: AbstractKVNavigableMap
      Encode the given key object into a byte[] key. Note that this method must throw IllegalArgumentException, not ClassCastException or NullPointerException, if obj does not have the correct type or is an illegal null value.
      Specified by:
      encodeKey in class AbstractKVNavigableMap<byte[],byte[]>
      Parameters:
      writer - output for encoded byte[] key corresponding to obj
      obj - map key object
    • decodeKey

      protected byte[] decodeKey(ByteReader reader)
      Description copied from class: AbstractKVNavigableMap
      Decode a key object from an encoded byte[] key.

      If not in prefix mode, all of reader must be consumed; otherwise, the consumed portion is the prefix and any following keys with the same prefix are ignored.

      Specified by:
      decodeKey in class AbstractKVNavigableMap<byte[],byte[]>
      Parameters:
      reader - input for encoded bytes
      Returns:
      decoded map key
    • decodeValue

      protected byte[] decodeValue(KVPair pair)
      Description copied from class: AbstractKVNavigableMap
      Decode a value object from an encoded byte[] key/value pair.
      Specified by:
      decodeValue in class AbstractKVNavigableMap<byte[],byte[]>
      Parameters:
      pair - key/value pair
      Returns:
      decoded map value
    • createSubMap

      protected NavigableMap<byte[],byte[]> createSubMap(boolean newReversed, KeyRange newKeyRange, KeyFilter newKeyFilter, Bounds<byte[]> newBounds)
      Description copied from class: AbstractKVNavigableMap
      Create a (possibly reversed) view of this instance with (possibly) tighter lower and/or upper bounds and the given KeyFilter, if any. The bounds are consistent with the reversed ordering (i.e., reversed if reverse is true) and have already been range-checked against this instance's bounds.
      Specified by:
      createSubMap in class AbstractKVNavigableMap<byte[],byte[]>
      Parameters:
      newReversed - whether the new map's ordering should be reversed (implies newBounds are also inverted, but not keyRange); note: means "absolutely" reversed, not relative to this instance
      newKeyRange - new key range, or null for none; will be consistent with bounds, if any
      newKeyFilter - new key filter, or null for none
      newBounds - new bounds
      Returns:
      restricted and/or filtered view of this instance