dsto.dfc.collections
Class ArrayIterator

java.lang.Object
  extended by dsto.dfc.collections.ArrayIterator
All Implemented Interfaces:
Cursor, Iterator

public class ArrayIterator
extends Object
implements Iterator, Cursor

Iterates through items in an array. Implements both java.util.Iterator and the DFC Cursoriterator interface.

Author:
Matthew Phillips

Constructor Summary
ArrayIterator(Object[] items)
          Create a new instance.
ArrayIterator(Object[] items, int index)
          Create a new instance.
 
Method Summary
 Object current()
           
 boolean hasNext()
           
 boolean inside()
           
 int move(int units)
          Move the cursor left (negative units) or right (positive units).
 Object next()
           
 void remove()
          Not supported.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayIterator

public ArrayIterator(Object[] items)
Create a new instance.

Parameters:
items - The items to iterate.

ArrayIterator

public ArrayIterator(Object[] items,
                     int index)
Create a new instance.

Parameters:
items - The items to iterate.
index - The start index. May be "outside" the sequence (null iteration).
Method Detail

inside

public boolean inside()
Specified by:
inside in interface Cursor
Returns:
True if the cursor is valid is within the collection).

current

public Object current()
               throws NoSuchElementException
Specified by:
current in interface Cursor
Returns:
The current element the cursor is pointing to.
Throws:
NoSuchElementException - If the cursor is not inside the collection.

move

public int move(int units)
Description copied from interface: Cursor
Move the cursor left (negative units) or right (positive units). This may cause the cursor to move outside the collection: if so, it stops just one unit to the left or right of the sequence and returns the actual number of items it moved past. A subsequent move of one unit in the other direction would put the cursor back to the first/last entry.

Specified by:
move in interface Cursor
Parameters:
units - The number of units to move.
Returns:
The number of elements actually moved past, which may be less than the requested units if the cursor has moved outside the collection. For example, if the cursor was at the last element of the collection and a move of 1 unit was requested, this returns zero.

hasNext

public boolean hasNext()
Specified by:
hasNext in interface Iterator

next

public Object next()
Specified by:
next in interface Iterator

remove

public void remove()
Not supported.

Specified by:
remove in interface Iterator


Copyright © 2008 Commonwealth of Australia