org.xshare.base.iterator
Class ArrayIterator

java.lang.Object
  |
  +--org.xshare.base.iterator.ArrayIterator
All Implemented Interfaces:
java.util.Iterator

public class ArrayIterator
extends java.lang.Object
implements java.util.Iterator

Iterator, which wraps a given array to use it in the same way as a Iterator.

Example

 ...
 Cat[] myCats = new Cat[] { ... };
 ...
 public void foobar() {
  Iterator catsItr = new ArrayIterator(myCats);
  ...
 }

Notes On The Implementation

Version:
$Revision: 1.5 $
Author:
Oliver Fischer

Constructor Summary
ArrayIterator(java.lang.Object[] pArray)
          Creates a new ArrayIterator which wraps a given array with an Iterator.
 
Method Summary
 boolean hasNext()
          Checks if there are more elements of the underlying array to return or not.
 java.lang.Object next()
          Returns the next object from the underlying array if any are left.
 void remove()
          This operation is not supported for this type of iterator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayIterator

public ArrayIterator(java.lang.Object[] pArray)
Creates a new ArrayIterator which wraps a given array with an Iterator.

Parameters:
pArray - a Object[] array representing the array which should be wrapped by this ArrayIterator.
Throws:
java.lang.NullPointerException - if the given array is null.
Method Detail

remove

public void remove()
This operation is not supported for this type of iterator.

Specified by:
remove in interface java.util.Iterator
Throws:
java.lang.UnsupportedOperationException - if this method is called since it is not supported.

next

public java.lang.Object next()
Returns the next object from the underlying array if any are left.

Specified by:
next in interface java.util.Iterator
Throws:
java.util.NoSuchElementException - if hasNext() returns false.
See Also:
hasNext()

hasNext

public boolean hasNext()
Checks if there are more elements of the underlying array to return or not.

Specified by:
hasNext in interface java.util.Iterator
Returns:
a boolean value which is true if there are elements left to return via next(). Otherwise false is returned.
See Also:
next()


jKiska Base 0.2.1 Release Esche [http://jkiska.sourceforge.net]