|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectuk.ac.starlink.array.BufferIterator
public class BufferIterator
Provides buffers for convenient stepping through an array. At each step a primitive buffer of a given type of just the right size to match the current chunk is returned. This class is provided as a convenience for applications code which wishes to iterate through an array in sections, using a buffer of the size matching the section at each step.
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 Summary | |
---|---|
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. |
Method Summary | |
---|---|
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public BufferIterator(long length, Type type, int chunkSize)
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<0public BufferIterator(long length)
length
- the total number of elements to iterate overMethod Detail |
---|
public Object next()
next
in interface Iterator
NoSuchElementException
- if hasNext would return falsepublic boolean hasNext()
hasNext
in interface Iterator
public void remove()
remove
in interface Iterator
UnsupportedOperationException
- alwayspublic long getBase()
IllegalStateException
- if called before the first call of
next
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |