net.opentsdb.core
Interface SeekableView

All Superinterfaces:
Iterator<DataPoint>

public interface SeekableView
extends Iterator<DataPoint>

Provides a zero-copy view to iterate through data points.

The iterator returned by classes that implement this interface must return each DataPoint in O(1) and does not support remove().

Because no data is copied during iteration and no new object gets created, the DataPoint returned must not be stored and gets invalidated as soon as next() is called on the iterator (actually it doesn't get invalidated but rather its contents changes). If you want to store individual data points, you need to copy the timestamp and value out of each DataPoint into your own data structures.

In the vast majority of cases, the iterator will be used to go once through all the data points, which is why it's not a problem if the iterator acts just as a transient "view". Iterating will be very cheap since no memory allocation is required (except to instantiate the actual iterator at the beginning).


Method Summary
 boolean hasNext()
          Returns true if this view has more elements.
 DataPoint next()
          Returns a view on the next data point.
 void remove()
          Unsupported operation.
 void seek(long timestamp)
          Advances the iterator to the given point in time.
 

Method Detail

hasNext

boolean hasNext()
Returns true if this view has more elements.

Specified by:
hasNext in interface Iterator<DataPoint>

next

DataPoint next()
Returns a view on the next data point. No new object gets created, the referenced returned is always the same and must not be stored since its internal data structure will change the next time next() is called.

Specified by:
next in interface Iterator<DataPoint>
Throws:
NoSuchElementException - if there were no more elements to iterate on (in which case hasNext() would have returned false.

remove

void remove()
Unsupported operation.

Specified by:
remove in interface Iterator<DataPoint>
Throws:
UnsupportedOperationException - always.

seek

void seek(long timestamp)
Advances the iterator to the given point in time.

This allows the iterator to skip all the data points that are strictly before the given timestamp.

Parameters:
timestamp - A strictly positive 32 bit UNIX timestamp (in seconds).
Throws:
IllegalArgumentException - if the timestamp is zero, or negative, or doesn't fit on 32 bits (think "unsigned int" -- yay Java!).