com.bigdata.btree.filter
Class Reverserator<E>

java.lang.Object
  extended by com.bigdata.btree.filter.Reverserator<E>
All Implemented Interfaces:
ITupleCursor<E>, ITupleIterator<E>, Iterator<ITuple<E>>

public class Reverserator<E>
extends Object
implements ITupleCursor<E>

Return an iterator that traverses the tuples in the reverse of the natural index order. The iterator is backed by the ITupleCursor and operations on the iterator effect the state of the cursor and visa versa.

Note: This implements the full ITupleCursor API so that we can stack filters over this class as readily as over an ITupleCursor. However, the semantics of hasNext() and next() and of hasPrior() and prior() are of course reversed (the move counter to the natural index order).


Constructor Summary
Reverserator(ITupleCursor<E> src)
           
 
Method Summary
 IIndex getIndex()
          The backing index being traversed by the ITupleCursor.
 boolean hasNext()
          Return true if there is another tuple that orders after the current cursor position in the natural order of the index and that lies within the optional constraints key-range on the cursor or on the index partition.
 boolean hasPrior()
          Return true if there is another tuple that orders before the current cursor position in the natural order of the index and that lies within the optional key-range constraints on the cursor or on the index partition.
 ITuple<E> next()
          Position the cursor on the next tuple in the natural key order of the index.
 ITuple<E> prior()
          Position the cursor on the first visitable tuple ordered less than the current cursor position in the natural key order of the index and return that tuple.
 void remove()
          Removes the tuple (if any) from the index corresponding to the current cursor position.
 ITuple<E> seek(byte[] key)
          Positions the cursor on the specified key.
 ITuple<E> seek(Object key)
          Variant that first encodes the key using the object returned by IndexMetadata.getTupleSerializer() for the backing index.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Reverserator

public Reverserator(ITupleCursor<E> src)
Method Detail

next

public ITuple<E> next()
Description copied from interface: ITupleCursor
Position the cursor on the next tuple in the natural key order of the index.

Note: in order to maintain standard iterator semantics, this method will visit the #first() visitable tuple if the current cursor position is undefined.

Specified by:
next in interface ITupleCursor<E>
Specified by:
next in interface ITupleIterator<E>
Specified by:
next in interface Iterator<ITuple<E>>
Returns:
The ITuple containing the data and metadata for the current index entry.

hasNext

public boolean hasNext()
Description copied from interface: ITupleCursor
Return true if there is another tuple that orders after the current cursor position in the natural order of the index and that lies within the optional constraints key-range on the cursor or on the index partition.

Note: in order to maintain standard iterator semantics, this method will return true if the current cursor position is undefined and #first() would report the existence of a visitable tuple.

Specified by:
hasNext in interface ITupleCursor<E>
Specified by:
hasNext in interface Iterator<ITuple<E>>

remove

public void remove()
Description copied from interface: ITupleCursor
Removes the tuple (if any) from the index corresponding to the current cursor position. The cursor position is NOT changed by this method. After removing the current tuple, ITupleCursor2.tuple() will return null to indicate that there is no tuple in the index corresponding to the deleted tuple. (When delete markers are enabled and deleted tuples are being visited, then ITupleCursor2.tuple() will return the new state of the tuple with its delete marker set.)

Specified by:
remove in interface ITupleCursor<E>
Specified by:
remove in interface Iterator<ITuple<E>>

getIndex

public IIndex getIndex()
Description copied from interface: ITupleCursor
The backing index being traversed by the ITupleCursor.

Specified by:
getIndex in interface ITupleCursor<E>

hasPrior

public boolean hasPrior()
Description copied from interface: ITupleCursor
Return true if there is another tuple that orders before the current cursor position in the natural order of the index and that lies within the optional key-range constraints on the cursor or on the index partition.

Note: in order to maintain semantics parallel to standard iterator semantics, this method will return true if the current cursor position is undefined and #last() would report the existence of a visitable tuple.

Specified by:
hasPrior in interface ITupleCursor<E>

prior

public ITuple<E> prior()
Description copied from interface: ITupleCursor
Position the cursor on the first visitable tuple ordered less than the current cursor position in the natural key order of the index and return that tuple.

Note: in order to maintain semantics parallel to standard iterator semantics, this method will visit the #last() visitable tuple if the current cursor position is undefined.

Specified by:
prior in interface ITupleCursor<E>

seek

public ITuple<E> seek(byte[] key)
Description copied from interface: ITupleCursor
Positions the cursor on the specified key.

If there is a corresponding visitable tuple in the index then it is returned.

If there is no visitable tuple in the index for that key then null is returned. You can use ITupleCursor.prior() or ITupleCursor.next() to locate the first visitable tuple to either side of the cursor position.

The cursor position is updated to the specified key regardless of whether there is a visitable tuple in the index for that key.

Specified by:
seek in interface ITupleCursor<E>
Parameters:
key - The key (required).
Returns:
The tuple corresponding to key if it exists and is visitable in the index and null otherwise.

seek

public ITuple<E> seek(Object key)
Description copied from interface: ITupleCursor
Variant that first encodes the key using the object returned by IndexMetadata.getTupleSerializer() for the backing index.

Specified by:
seek in interface ITupleCursor<E>
Parameters:
key - The key (required).
Returns:
The tuple corresponding to the encoded key if it exists and is visitable in the index and null otherwise.


Copyright © 2006-2009 SYSTAP, LLC. All Rights Reserved.