Package com.usatiuk.objects.iterators
Class MappingKvIterator<K extends Comparable<K>,V,V_T>
java.lang.Object
com.usatiuk.objects.iterators.MappingKvIterator<K,V,V_T>
- Type Parameters:
K
- the type of the keysV
- the type of the values in the backing iteratorV_T
- the type of the transformed values
- All Implemented Interfaces:
CloseableKvIterator<K,
,V_T> AutoCloseable
,Iterator<org.apache.commons.lang3.tuple.Pair<K,
V_T>>
public class MappingKvIterator<K extends Comparable<K>,V,V_T>
extends Object
implements CloseableKvIterator<K,V_T>
A mapping key-value iterator that transforms the values of a backing iterator using a specified function.
-
Constructor Summary
ConstructorsConstructorDescriptionMappingKvIterator
(CloseableKvIterator<K, V> backing, Function<V, V_T> transformer) Constructs a MappingKvIterator with the specified backing iterator and transformer function. -
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.void
skip()
Skips the next element in the forward direction.void
skipPrev()
Skips the previous element in the reverse direction.toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.usatiuk.objects.iterators.CloseableKvIterator
reversed
Methods inherited from interface java.util.Iterator
forEachRemaining, remove
-
Constructor Details
-
MappingKvIterator
Constructs a MappingKvIterator with the specified backing iterator and transformer function.- Parameters:
backing
- the backing iteratortransformer
- the function to transform values
-
-
Method Details
-
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>
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseableKvIterator<K extends Comparable<K>,
V>
-
hasNext
public boolean hasNext()- Specified by:
hasNext
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>
-
next
- Specified by:
next
in interfaceIterator<K extends Comparable<K>>
-
toString
-