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 booleanThe current direction of the iterator. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract booleanhasImpl()Checks if there is a next element in the iterator, depending on the current direction.booleanhasNext()booleanhasPrev()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 KpeekImpl()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 voidreverse()Reverses the current direction of the iterator.voidskip()Skips the next element in the forward direction.protected abstract voidskipImpl()Skips the next element in the iterator, depending on the current direction.voidskipPrev()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, waitMethods inherited from interface com.usatiuk.objects.iterators.CloseableKvIterator
close, reversedMethods 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:CloseableKvIteratorReturns the upcoming key in the forward direction without advancing the iterator.- Specified by:
peekNextKeyin interfaceCloseableKvIterator<K extends Comparable<K>,V> - Returns:
- the current key
-
skip
public void skip()Description copied from interface:CloseableKvIteratorSkips the next element in the forward direction.- Specified by:
skipin interfaceCloseableKvIterator<K extends Comparable<K>,V>
-
hasNext
public boolean hasNext()- Specified by:
hasNextin interfaceIterator<K extends Comparable<K>>
-
next
- Specified by:
nextin interfaceIterator<K extends Comparable<K>>
-
peekPrevKey
Description copied from interface:CloseableKvIteratorChecks if there is a next element in the forward direction.- Specified by:
peekPrevKeyin interfaceCloseableKvIterator<K extends Comparable<K>,V> - Returns:
- true if there is a next element, false otherwise
-
prev
Description copied from interface:CloseableKvIteratorReturns the key-value pair in the reverse direction, and advances the iterator.- Specified by:
previn interfaceCloseableKvIterator<K extends Comparable<K>,V> - Returns:
- the previous key-value pair
-
hasPrev
public boolean hasPrev()Description copied from interface:CloseableKvIteratorChecks if there is a previous element in the reverse direction.- Specified by:
hasPrevin interfaceCloseableKvIterator<K extends Comparable<K>,V> - Returns:
- true if there is a previous element, false otherwise
-
skipPrev
public void skipPrev()Description copied from interface:CloseableKvIteratorSkips the previous element in the reverse direction.- Specified by:
skipPrevin interfaceCloseableKvIterator<K extends Comparable<K>,V>
-