|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.ccg.util.ArrayIterator
public final class ArrayIterator
Convert any array of objects into an Iterator.
Java probably has this functionality somewhere (I just couldn't
seem to find it). This simple class puts the wrapper around an
array of objects to make the array behave like a standard Java
Iterator.
Some notes:
| Constructor Summary | |
|---|---|
ArrayIterator(Object[] array,
boolean allowNullRemove)
Contruct the array iterator. |
|
| Method Summary | |
|---|---|
boolean |
hasNext()
Determine if there are more elements. |
Object |
next()
Get next element in Iterator. |
void |
remove()
Attempt to remove object from the iterator. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ArrayIterator(Object[] array,
boolean allowNullRemove)
array - Array of objects to appear when one enumerates. You may pass
null.allowNullRemove - If you pass true, we will support the "remove()" operation by
setting the corresponding entry in the array to null. If you
pass false, the "remove()" operation will not be supported and
a exception will be thrown if you attempt to use it.| Method Detail |
|---|
public boolean hasNext()
hasNext in interface IteratorIteratorpublic Object next()
hasNext() returns true.
next in interface IteratorIterator
public void remove()
throws UnsupportedOperationException,
IllegalStateException
When you construct this object you have the option of allowing the "remove()" method to function. If you didn't enable the "remove()" method at the time of construction, any invocation will throw the UnsupportedOperationException.
The "next()" method must be used PRIOR to the invocation of the "remove()" method (as we remove the item returned by the last invocation of "next").
The successful removal of a item results in its corresponding entry in the original array being set to null.
remove in interface IteratorUnsupportedOperationException - The "remove" operation is not supported by this iterator.
IllegalStateException - If an attempt to use the "remove" operation was made PRIOR to
use of the "next" method.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||