Package com.usatiuk.objects.iterators
Class ReversibleKvIterator<K extends Comparable<K>,V>
java.lang.Object
com.usatiuk.objects.iterators.ReversibleKvIterator<K,V>
- Type Parameters:
K
- the type of the keysV
- the type of the values
- All Implemented Interfaces:
CloseableKvIterator<K,
,V> AutoCloseable
,Iterator<org.apache.commons.lang3.tuple.Pair<K,
V>>
- Direct Known Subclasses:
KeyPredicateKvIterator
,MergingKvIterator
,NavigableMapKvIterator
,TombstoneSkippingIterator
public abstract class ReversibleKvIterator<K extends Comparable<K>,V>
extends Object
implements CloseableKvIterator<K,V>
Base class for a reversible key-value iterator.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
The current direction of the iterator. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract boolean
hasImpl()
Checks if there is a next element in the iterator, depending on the current direction.boolean
hasNext()
boolean
hasPrev()
Checks if there is a previous element in the reverse direction.next()
nextImpl()
Returns the next element in the iterator, depending on the current direction.protected abstract K
peekImpl()
Fills the next element in the iterator, depending on the current direction.Returns the upcoming key in the forward direction without advancing the iterator.Checks if there is a next element in the forward direction.prev()
Returns the key-value pair in the reverse direction, and advances the iterator.protected abstract void
reverse()
Reverses the current direction of the iterator.void
skip()
Skips the next element in the forward direction.protected abstract void
skipImpl()
Skips the next element in the iterator, depending on the current direction.void
skipPrev()
Skips the previous element in the reverse direction.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.usatiuk.objects.iterators.CloseableKvIterator
close, reversed
Methods inherited from interface java.util.Iterator
forEachRemaining, remove
-
Field Details
-
_goingForward
protected boolean _goingForwardThe current direction of the iterator.
-
-
Constructor Details
-
ReversibleKvIterator
public ReversibleKvIterator()
-
-
Method Details
-
reverse
protected abstract void reverse()Reverses the current direction of the iterator. -
peekImpl
Fills the next element in the iterator, depending on the current direction.- Throws:
IllegalStateException
- if there is no next element
-
skipImpl
protected abstract void skipImpl()Skips the next element in the iterator, depending on the current direction.- Throws:
IllegalStateException
- if there is no next element
-
hasImpl
protected abstract boolean hasImpl()Checks if there is a next element in the iterator, depending on the current direction.- Returns:
- true if there is a next element, false otherwise
-
nextImpl
Returns the next element in the iterator, depending on the current direction.- Returns:
- the next element
- Throws:
IllegalStateException
- if there is no next element
-
peekNextKey
Description copied from interface:CloseableKvIterator
Returns the upcoming key in the forward direction without advancing the iterator.- Specified by:
peekNextKey
in interfaceCloseableKvIterator<K extends Comparable<K>,
V> - Returns:
- the current key
-
skip
public void skip()Description copied from interface:CloseableKvIterator
Skips the next element in the forward direction.- Specified by:
skip
in interfaceCloseableKvIterator<K extends Comparable<K>,
V>
-
hasNext
public boolean hasNext()- Specified by:
hasNext
in interfaceIterator<K extends Comparable<K>>
-
next
- Specified by:
next
in interfaceIterator<K extends Comparable<K>>
-
peekPrevKey
Description copied from interface:CloseableKvIterator
Checks if there is a next element in the forward direction.- Specified by:
peekPrevKey
in interfaceCloseableKvIterator<K extends Comparable<K>,
V> - Returns:
- true if there is a next element, false otherwise
-
prev
Description copied from interface:CloseableKvIterator
Returns the key-value pair in the reverse direction, and advances the iterator.- Specified by:
prev
in interfaceCloseableKvIterator<K extends Comparable<K>,
V> - Returns:
- the previous key-value pair
-
hasPrev
public boolean hasPrev()Description copied from interface:CloseableKvIterator
Checks if there is a previous element in the reverse direction.- Specified by:
hasPrev
in interfaceCloseableKvIterator<K extends Comparable<K>,
V> - Returns:
- true if there is a previous element, false otherwise
-
skipPrev
public void skipPrev()Description copied from interface:CloseableKvIterator
Skips the previous element in the reverse direction.- Specified by:
skipPrev
in interfaceCloseableKvIterator<K extends Comparable<K>,
V>
-