Class ReversibleKvIterator<K extends Comparable<K>,V>

java.lang.Object
com.usatiuk.objects.iterators.ReversibleKvIterator<K,V>
Type Parameters:
K - the type of the keys
V - 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

    Fields
    Modifier and Type
    Field
    Description
    protected boolean
    The current direction of the iterator.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract boolean
    Checks if there is a next element in the iterator, depending on the current direction.
    boolean
     
    boolean
    Checks if there is a previous element in the reverse direction.
    org.apache.commons.lang3.tuple.Pair<K,V>
     
    protected abstract org.apache.commons.lang3.tuple.Pair<K,V>
    Returns the next element in the iterator, depending on the current direction.
    protected abstract K
    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.
    org.apache.commons.lang3.tuple.Pair<K,V>
    Returns the key-value pair in the reverse direction, and advances the iterator.
    protected abstract void
    Reverses the current direction of the iterator.
    void
    Skips the next element in the forward direction.
    protected abstract void
    Skips the next element in the iterator, depending on the current direction.
    void
    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 _goingForward
      The 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

      protected abstract K 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

      protected abstract org.apache.commons.lang3.tuple.Pair<K,V> 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

      public K peekNextKey()
      Description copied from interface: CloseableKvIterator
      Returns the upcoming key in the forward direction without advancing the iterator.
      Specified by:
      peekNextKey in interface CloseableKvIterator<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 interface CloseableKvIterator<K extends Comparable<K>,V>
    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface Iterator<K extends Comparable<K>>
    • next

      public org.apache.commons.lang3.tuple.Pair<K,V> next()
      Specified by:
      next in interface Iterator<K extends Comparable<K>>
    • peekPrevKey

      public K peekPrevKey()
      Description copied from interface: CloseableKvIterator
      Checks if there is a next element in the forward direction.
      Specified by:
      peekPrevKey in interface CloseableKvIterator<K extends Comparable<K>,V>
      Returns:
      true if there is a next element, false otherwise
    • prev

      public org.apache.commons.lang3.tuple.Pair<K,V> prev()
      Description copied from interface: CloseableKvIterator
      Returns the key-value pair in the reverse direction, and advances the iterator.
      Specified by:
      prev in interface CloseableKvIterator<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 interface CloseableKvIterator<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 interface CloseableKvIterator<K extends Comparable<K>,V>