Package io.permazen.kv.util
Class KVNavigableMap
java.lang.Object
java.util.AbstractMap<K,V>
io.permazen.util.AbstractNavigableMap<K,V>
io.permazen.kv.util.AbstractKVNavigableMap<byte[],byte[]>
io.permazen.kv.util.KVNavigableMap
- All Implemented Interfaces:
Map<byte[],
,byte[]> NavigableMap<byte[],
,byte[]> SortedMap<byte[],
byte[]>
A
NavigableMap
view of the keys and values in a KVStore
.
Instances are mutable, with these exceptions:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,
V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Field Summary
Fields inherited from class io.permazen.kv.util.AbstractKVNavigableMap
keyFilter, keyRange, kv, prefixMode, reversed
Fields inherited from class io.permazen.util.AbstractNavigableMap
bounds
-
Constructor Summary
ModifierConstructorDescriptionConstructor for when there are no range restrictions.protected
KVNavigableMap
(KVStore kv, boolean reversed, KeyRange keyRange, KeyFilter keyFilter) Primary constructor.KVNavigableMap
(KVStore kv, byte[] prefix) Constructor for when the range of visibleKVStore
keys is all keys sharing a givenbyte[]
prefix. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Comparator<byte[]>
boolean
containsKey
(Object obj) protected NavigableMap<byte[],
byte[]> createSubMap
(boolean newReversed, KeyRange newKeyRange, KeyFilter newKeyFilter, Bounds<byte[]> newBounds) Create a (possibly reversed) view of this instance with (possibly) tighter lower and/or upper bounds and the givenKeyFilter
, if any.protected byte[]
decodeKey
(ByteReader reader) Decode a key object from an encodedbyte[]
key.protected byte[]
decodeValue
(KVPair pair) Decode a value object from an encodedbyte[]
key/value pair.protected void
encodeKey
(ByteWriter writer, Object obj) Encode the given key object into abyte[]
key.byte[]
put
(byte[] key, byte[] value) byte[]
Removes the mapping for a key from this map if it is present.Methods inherited from class io.permazen.kv.util.AbstractKVNavigableMap
createSubMap, encodeVisibleKey, entrySet, filterKeys, get, isVisible, isWithinLowerBound, isWithinUpperBound, navigableKeySet
Methods inherited from class io.permazen.util.AbstractNavigableMap
ceilingEntry, ceilingKey, descendingKeySet, descendingMap, firstEntry, firstKey, floorEntry, floorKey, getBounds, getComparator, headMap, headMap, higherEntry, higherKey, isEmpty, keySet, lastEntry, lastKey, lowerEntry, lowerKey, pollFirstEntry, pollLastEntry, searchAbove, searchBelow, subMap, subMap, tailMap, tailMap
Methods inherited from class java.util.AbstractMap
clone, containsValue, equals, hashCode, putAll, size, toString, values
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, containsValue, equals, forEach, getOrDefault, hashCode, merge, putAll, putIfAbsent, remove, replace, replace, replaceAll, size
-
Constructor Details
-
KVNavigableMap
Constructor for when there are no range restrictions.- Parameters:
kv
- underlyingKVStore
-
KVNavigableMap
Constructor for when the range of visibleKVStore
keys is all keys sharing a givenbyte[]
prefix.- Parameters:
kv
- underlyingKVStore
prefix
- prefix defining minimum and maximum keys- Throws:
NullPointerException
- ifprefix
is null
-
KVNavigableMap
Primary constructor.- Parameters:
kv
- underlyingKVStore
reversed
- whether ordering is reversedkeyRange
- key range restriction, or null for nonekeyFilter
- key filter, or null for none- Throws:
IllegalArgumentException
- ifkv
is null
-
-
Method Details
-
comparator
-
put
public byte[] put(byte[] key, byte[] value) - Specified by:
put
in interfaceMap<byte[],
byte[]> - Overrides:
put
in classAbstractMap<byte[],
byte[]>
-
remove
Description copied from class:AbstractNavigableMap
Removes the mapping for a key from this map if it is present.The implementation in
AbstractNavigableMap
always throwsUnsupportedOperationException
.- Specified by:
remove
in interfaceMap<byte[],
byte[]> - Overrides:
remove
in classAbstractNavigableMap<byte[],
byte[]>
-
clear
public void clear()- Specified by:
clear
in interfaceMap<byte[],
byte[]> - Overrides:
clear
in classAbstractMap<byte[],
byte[]>
-
containsKey
- Specified by:
containsKey
in interfaceMap<byte[],
byte[]> - Overrides:
containsKey
in classAbstractNavigableMap<byte[],
byte[]>
-
encodeKey
Description copied from class:AbstractKVNavigableMap
Encode the given key object into abyte[]
key. Note that this method must throwIllegalArgumentException
, notClassCastException
orNullPointerException
, ifobj
does not have the correct type or is an illegal null value.- Specified by:
encodeKey
in classAbstractKVNavigableMap<byte[],
byte[]> - Parameters:
writer
- output for encodedbyte[]
key corresponding toobj
obj
- map key object
-
decodeKey
Description copied from class:AbstractKVNavigableMap
Decode a key object from an encodedbyte[]
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 classAbstractKVNavigableMap<byte[],
byte[]> - Parameters:
reader
- input for encoded bytes- Returns:
- decoded map key
-
decodeValue
Description copied from class:AbstractKVNavigableMap
Decode a value object from an encodedbyte[]
key/value pair.- Specified by:
decodeValue
in classAbstractKVNavigableMap<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 givenKeyFilter
, if any. The bounds are consistent with the reversed ordering (i.e., reversed ifreverse
is true) and have already been range-checked against this instance's bounds.- Specified by:
createSubMap
in classAbstractKVNavigableMap<byte[],
byte[]> - Parameters:
newReversed
- whether the new map's ordering should be reversed (impliesnewBounds
are also inverted, but notkeyRange
); note: means "absolutely" reversed, not relative to this instancenewKeyRange
- new key range, or null for none; will be consistent withbounds
, if anynewKeyFilter
- new key filter, or null for nonenewBounds
- new bounds- Returns:
- restricted and/or filtered view of this instance
-