Package io.permazen.kv.util
Class KVNavigableSet
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<E>
io.permazen.util.AbstractIterationSet<E>
io.permazen.util.AbstractNavigableSet<E>
io.permazen.kv.util.AbstractKVNavigableSet<byte[]>
io.permazen.kv.util.KVNavigableSet
- All Implemented Interfaces:
Iterable<byte[]>
,Collection<byte[]>
,NavigableSet<byte[]>
,Set<byte[]>
,SortedSet<byte[]>
-
Field Summary
Fields inherited from class io.permazen.kv.util.AbstractKVNavigableSet
keyFilter, keyRange, kv, prefixMode, reversed
Fields inherited from class io.permazen.util.AbstractNavigableSet
bounds
-
Constructor Summary
ModifierConstructorDescriptionConstructor for when there are no range restrictions.protected
KVNavigableSet
(KVStore kv, boolean reversed, KeyRange keyRange, KeyFilter keyFilter) Primary constructor.KVNavigableSet
(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[]>
protected NavigableSet<byte[]>
createSubSet
(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[]
decode
(ByteReader reader) Decode an element from abyte[]
key.protected void
encode
(ByteWriter writer, Object obj) Encode the given object into abyte[]
key.boolean
Removes the given element from this set if it is present.Methods inherited from class io.permazen.kv.util.AbstractKVNavigableSet
contains, createSubSet, encodeVisible, filterKeys, first, isEmpty, isVisible, isWithinLowerBound, isWithinUpperBound, iterator, last, pollFirst, pollLast
Methods inherited from class io.permazen.util.AbstractNavigableSet
buildSpliterator, ceiling, descendingIterator, descendingSet, floor, getBounds, getComparator, headSet, headSet, higher, lower, searchAbove, searchBelow, subSet, subSet, tailSet, tailSet
Methods inherited from class io.permazen.util.AbstractIterationSet
equals, hashCode, size, spliterator, stream, toArray, toArray
Methods inherited from class java.util.AbstractSet
removeAll
Methods inherited from class java.util.AbstractCollection
add, addAll, containsAll, retainAll, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.Set
add, addAll, containsAll, equals, hashCode, removeAll, retainAll, size, toArray, toArray
Methods inherited from interface java.util.SortedSet
spliterator
-
Constructor Details
-
KVNavigableSet
Constructor for when there are no range restrictions.- Parameters:
kv
- underlyingKVStore
-
KVNavigableSet
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
-
KVNavigableSet
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
-
remove
Description copied from class:AbstractNavigableSet
Removes the given element from this set if it is present.The implementation in
AbstractNavigableSet
always throwsUnsupportedOperationException
.- Specified by:
remove
in interfaceCollection<byte[]>
- Specified by:
remove
in interfaceSet<byte[]>
- Overrides:
remove
in classAbstractNavigableSet<byte[]>
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<byte[]>
- Specified by:
clear
in interfaceSet<byte[]>
- Overrides:
clear
in classAbstractCollection<byte[]>
-
encode
Description copied from class:AbstractKVNavigableSet
Encode the given 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:
encode
in classAbstractKVNavigableSet<byte[]>
- Parameters:
writer
- output for encodedbyte[]
key corresponding toobj
obj
- set element
-
decode
Description copied from class:AbstractKVNavigableSet
Decode an element from abyte[]
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:
decode
in classAbstractKVNavigableSet<byte[]>
- Parameters:
reader
- input for encoded bytes- Returns:
- decoded set element
-
createSubSet
protected NavigableSet<byte[]> createSubSet(boolean newReversed, KeyRange newKeyRange, KeyFilter newKeyFilter, Bounds<byte[]> newBounds) Description copied from class:AbstractKVNavigableSet
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:
createSubSet
in classAbstractKVNavigableSet<byte[]>
- Parameters:
newReversed
- whether the new set'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
-