public class BufferIterator extends Object implements Iterator
This class provides a thin convenience wrapper around
ChunkStepper
, which is itself a simple class which steps
from zero to a given limit in chunks. The only additional functionality
provided by a BufferIterator
is that it will ensure a
suitable primitive buffer is available at each step, and (since the
next
method actually returns something, namely the buffer),
it implements the Iterator
interface which
ChunkStepper
does not.
A typical use of BufferIterator
is as follows:
ArrayAccess acc = ndarray.getAccess(); for ( BufferIterator bufIt = new BufferIterator( npix, Type.DOUBLE ); bufIt.hasNext(); ) { double[] buf = (double[]) bIt.next(); acc.read( buf, 0, buf.length ); doStuff( buf ); }
ChunkStepper
Constructor and Description |
---|
BufferIterator(long length)
Create a new
BufferIterator with a default chunk size. |
BufferIterator(long length,
Type type,
int chunkSize)
Create a new
BufferIterator with a given chunk size. |
Modifier and Type | Method and Description |
---|---|
long |
getBase()
The offset of the base of the chunk most recently returned by
next . |
boolean |
hasNext()
See if iteration has finished.
|
Object |
next()
Returns a primitive buffer of this object's type, with a length
matching that of this chunk.
|
void |
remove()
Remove functionality is not implemented by this class.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEachRemaining
public BufferIterator(long length, Type type, int chunkSize)
BufferIterator
with a given chunk size.length
- the total number of elements to iterate overtype
- the type of the primitive buffer which the
next
method will return
at each iterationchunkSize
- the size of buffer which will be used (except
perhaps for the last chunk)IllegalArgumentException
- if chunkSize<=0
or length<0
public BufferIterator(long length)
BufferIterator
with a default chunk size.length
- the total number of elements to iterate overpublic Object next()
next
in interface Iterator
NoSuchElementException
- if hasNext would return falsepublic boolean hasNext()
public void remove()
remove
in interface Iterator
UnsupportedOperationException
- alwayspublic long getBase()
next
. This will be zero for the first
chunk, and increasing by the size of the buffer returned by
next
with each iteration after that.IllegalStateException
- if called before the first call of
next
Copyright © 2024 Central Laboratory of the Research Councils. All Rights Reserved.