com.bigdata.striterator
Class ChunkedArrayIterator<E>

java.lang.Object
  extended by com.bigdata.striterator.ChunkedArrayIterator<E>
All Implemented Interfaces:
IChunkedIterator<E>, IChunkedOrderedIterator<E>, ICloseableIterator<E>, Iterator<E>
Direct Known Subclasses:
SingleValueChunkedIterator

public class ChunkedArrayIterator<E>
extends Object
implements IChunkedOrderedIterator<E>

Fully buffered iterator.

Version:
$Id: ChunkedArrayIterator.java 4481 2011-05-11 03:20:08Z mrpersonick $
Author:
Bryan Thompson

Field Summary
 
Fields inherited from interface com.bigdata.striterator.IChunkedIterator
DEFAULT_CHUNK_SIZE
 
Constructor Summary
ChunkedArrayIterator(E[] a)
          An iterator that visits the elements in the given array.
ChunkedArrayIterator(int n, E[] a, IKeyOrder<E> keyOrder)
          An iterator that visits the elements in the given array.
 
Method Summary
 E[] array()
          Return the backing array.
 void close()
          Closes the iterator, releasing any associated resources.
 int getBufferCount()
          The #of elements that this iterator buffered.
 IKeyOrder<E> getKeyOrder()
          The natural order in which elements are being visited.
 boolean hasNext()
           
 E next()
          The next element available from the iterator.
 E[] nextChunk()
          Returns the remaining statements.
 E[] nextChunk(IKeyOrder<E> keyOrder)
          Return the next "chunk" of elements.
 void remove()
          Removes the last element visited by IChunkedIterator.next() (optional operation).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChunkedArrayIterator

public ChunkedArrayIterator(E[] a)
An iterator that visits the elements in the given array.

Parameters:
a - The array of elements.

ChunkedArrayIterator

public ChunkedArrayIterator(int n,
                            E[] a,
                            IKeyOrder<E> keyOrder)
An iterator that visits the elements in the given array.

Parameters:
a - The array of elements.
n - The #of entries in a that are valid.
keyOrder - The order of the elements in the buffer or null iff not known.
Method Detail

getBufferCount

public int getBufferCount()
The #of elements that this iterator buffered.


hasNext

public boolean hasNext()
Specified by:
hasNext in interface Iterator<E>

next

public E next()
Description copied from interface: IChunkedIterator
The next element available from the iterator.

Specified by:
next in interface IChunkedIterator<E>
Specified by:
next in interface Iterator<E>

remove

public void remove()
Description copied from interface: IChunkedIterator
Removes the last element visited by IChunkedIterator.next() (optional operation).

Note: This method is not readily suited for use with IChunkedIterator.nextChunk() since the latter has already visited everything in the chunk and IChunkedIterator.remove() would only remove the last item in the chunk. Normally you will want to accumulate items to be removed in a buffer and then submit the buffer to some batch api operation when it overflows. Alternatively, the IRangeQuery.REMOVEALL flag may be used with the source iterator to remove elements from the index as they are visited.

Specified by:
remove in interface IChunkedIterator<E>
Specified by:
remove in interface Iterator<E>
Throws:
UnsupportedOperationException

array

public E[] array()
Return the backing array.

See Also:
getBufferCount()

nextChunk

public E[] nextChunk()
Returns the remaining statements.

Specified by:
nextChunk in interface IChunkedIterator<E>
Returns:
The next chunk.
Throws:
NoSuchElementException - if hasNext() returns false.

getKeyOrder

public IKeyOrder<E> getKeyOrder()
Description copied from interface: IChunkedOrderedIterator
The natural order in which elements are being visited.

Specified by:
getKeyOrder in interface IChunkedOrderedIterator<E>
Returns:
The natural order in which the elements are being visited -or- null if not known.

nextChunk

public E[] nextChunk(IKeyOrder<E> keyOrder)
Description copied from interface: IChunkedOrderedIterator
Return the next "chunk" of elements. The elements will be in the specified order. If IChunkedOrderedIterator.getKeyOrder() would return non-null and the request order corresponds to the value that would be returned by IChunkedOrderedIterator.getKeyOrder() then the elements in the next chunk are NOT sorted. Otherwise the elements in the next chunk are sorted before they are returned. The size of the chunk is up to the implementation.

Specified by:
nextChunk in interface IChunkedOrderedIterator<E>
Parameters:
keyOrder - The natural order for the elements in the chunk.
Returns:
The next chunk of elements in the specified order.

close

public void close()
Description copied from interface: ICloseableIterator
Closes the iterator, releasing any associated resources. This method MAY be invoked safely if the iterator is already closed. Implementations of this interface MUST invoke ICloseableIterator.close() if Iterator.hasNext() method returns false to ensure that the iterator is closed (and its resources release) as soon as it is exhausted.

Note: Implementations that support Iterator.remove() MUST NOT eagerly close the iterator when it is exhausted since that would make it impossible to remove the last visited statement. Instead they MUST wait for an explicit ICloseableIterator.close() by the application.

Specified by:
close in interface ICloseableIterator<E>


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