Package com.usatiuk.objects.iterators
Class ReversedKvIterator<K extends Comparable<? super K>,V>
java.lang.Object
com.usatiuk.objects.iterators.ReversedKvIterator<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>>
public class ReversedKvIterator<K extends Comparable<? super K>,V>
extends Object
implements CloseableKvIterator<K,V>
A wrapper for a key-value iterator that iterates in reverse order.
-
Constructor Summary
ConstructorsConstructorDescriptionReversedKvIterator
(CloseableKvIterator<K, V> backing) Constructs a ReversedKvIterator with the specified backing iterator. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
boolean
hasNext()
boolean
hasPrev()
Checks if there is a previous element in the reverse direction.next()
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.reversed()
Returns a reversed iterator that iterates in the reverse direction.void
skip()
Skips the next element in the forward 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 java.util.Iterator
forEachRemaining, remove
-
Constructor Details
-
ReversedKvIterator
Constructs a ReversedKvIterator with the specified backing iterator.- Parameters:
backing
- the backing iterator
-
-
Method Details
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseableKvIterator<K extends Comparable<? super K>,
V>
-
hasNext
public boolean hasNext()- Specified by:
hasNext
in interfaceIterator<K extends Comparable<? super K>>
-
next
- Specified by:
next
in interfaceIterator<K extends Comparable<? super K>>
-
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<? super 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<? super K>,
V>
-
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<? super 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<? super 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<? super 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<? super K>,
V>
-
reversed
Description copied from interface:CloseableKvIterator
Returns a reversed iterator that iterates in the reverse direction.- Specified by:
reversed
in interfaceCloseableKvIterator<K extends Comparable<? super K>,
V> - Returns:
- a new CloseableKvIterator that iterates in the reverse direction
-