org.jutil.java.collections
Class ObjectArrayIterator

java.lang.Object
  |
  +--org.jutil.java.collections.ObjectArrayIterator

public class ObjectArrayIterator
extends java.lang.Object

A class of iterators for multi-dimensional arrays of objects. The traversal of the array is depth-first. You can, but should not use this class in your code. Using the Visitor class is a better way of visiting all elements of a multi-dimensional array.

Version:
$Revision: 1.5 $
Author:
Marko van Dooren

Field Summary
static java.lang.String CVS_REVISION
           
 
Constructor Summary
ObjectArrayIterator(java.lang.Object[] array)
          // The array of an ObjectArrayIterator is not null.
public invariant getArray() != null;

// may not be null.
pre array != null;

// The array of this ObjectArrayIterator will be set to
post getArray() == array;
// The iterator will be positioned at the start of the array.
post atStart() == true;
Initialize a new ObjectArrayIterator with the given array of objects
 
Method Summary
 boolean atEnd()
          Check whether this iterator is positioned at the end of its array Result True if this iterator is positioned at the end of its array, false otherwise.
 boolean atStart()
          Check whether this iterator is positioned at the beginning of its array Result True if this iterator is positioned at the beginning of its array, false otherwise.
 java.lang.Object[] getArray()
          Return the array of this ObjectArrayIterator.
 java.lang.Object getElement()
          Return the element of the array at the current position of the iterator.
 void next()
          Go to the next element of the array Effects If the iterator wasn't at the end of the array, the iterator will be positioned at the next element.
 void previous()
          Go to the previous element of the array Effects If the iterator wasn't at the start of the array, the iterator will be positioned at the previous element.
 void setElement(java.lang.Object element)
          Set the element of the array at the current position of the iterator to the given element.
 void toEnd()
          Set this iterator to the end of the array.
 void toStart()
          Set this iterator to the beginning of the array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CVS_REVISION

public static final java.lang.String CVS_REVISION
Constructor Detail

ObjectArrayIterator

public ObjectArrayIterator(java.lang.Object[] array)
                    throws ZeroDimensionException
// The array of an ObjectArrayIterator is not null.
public invariant getArray() != null;

// may not be null.
pre array != null;

// The array of this ObjectArrayIterator will be set to
post getArray() == array;
// The iterator will be positioned at the start of the array.
post atStart() == true;
Initialize a new ObjectArrayIterator with the given array of objects
Parameters:
array - an array of objects
Method Detail

atStart

public boolean atStart()
Check whether this iterator is positioned at the beginning of its array Result True if this iterator is positioned at the beginning of its array, false otherwise.

getArray

public java.lang.Object[] getArray()
Return the array of this ObjectArrayIterator.

atEnd

public boolean atEnd()
Check whether this iterator is positioned at the end of its array Result True if this iterator is positioned at the end of its array, false otherwise.

next

public void next()
          throws java.util.NoSuchElementException
Go to the next element of the array Effects If the iterator wasn't at the end of the array, the iterator will be positioned at the next element. First the deepest dimension will be increased, the first dimension will be increased as last (depth-first). Exceptions NoSuchElementException The iterator is at the end of the iteration atEnd()

previous

public void previous()
              throws java.util.NoSuchElementException
Go to the previous element of the array Effects If the iterator wasn't at the start of the array, the iterator will be positioned at the previous element. First the deepest dimension will be decreased, the first dimension will be decreased as last. Exceptions NoSuchElementException The iterator is at the start of the iteration atStart()

toStart

public void toStart()
Set this iterator to the beginning of the array. Effects The iterator will be positioned at the beginning of the array. atStart()==true

toEnd

public void toEnd()
Set this iterator to the end of the array. Effects The iterator will be positioned at the end of the array. atEnd()==true

getElement

public java.lang.Object getElement()
Return the element of the array at the current position of the iterator. Result The element of the array at the current position of the iterator.

setElement

public void setElement(java.lang.Object element)
Set the element of the array at the current position of the iterator to the given element.
Parameters:
element - the new element that will be placed at the current position. Effects The element of the array at the current position of the iterator will be set to the given element.