com.holub.tools
Class ArrayIterator

java.lang.Object
  extended by com.holub.tools.ArrayIterator
All Implemented Interfaces:
Iterator

public final class ArrayIterator
extends Object
implements Iterator

A simple implementation of java.util.Iterator that enumerates over arrays. You can use this class to pass arrays to methods that normally accept Iterator arguments. (It's an example of the Adapter design pattern in that it makes an array appear to implement the Iterator interface.)

©2004 Allen I. Holub. All rights reserved.

This code may be used freely by yourself with the following restrictions:

  1. Your splash screen, about box, or equivalent, must include Allen Holub's name, copyright, and URL. For example:

    This program contains Allen Holub's SQL package.
    (c) 2005 Allen I. Holub. All Rights Reserved.
    http://www.holub.com


    If your program does not run interactively, then the foregoing notice must appear in your documentation.
  2. You may not redistribute (or mirror) the source code.
  3. You must report any bugs that you find to me. Use the form at http://www.holub.com/company/contact.html or send email.
  4. The software is supplied as is. Neither Allen Holub nor Holub Associates are responsible for any bugs (or any problems caused by bugs, including lost productivity or data) in any of this code.

Constructor Summary
ArrayIterator(Object[] items)
          Create and ArrayIterator.
 
Method Summary
 boolean hasNext()
           
 Object next()
           
 void remove()
           
 Object[] toArray()
          Not part of the Iterator interface, returns the data set in array form.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayIterator

public ArrayIterator(Object[] items)
Create and ArrayIterator.

Parameters:
items - the array whose elements will be returned, in turn, by each next() call.
Method Detail

hasNext

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

next

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

remove

public void remove()
Specified by:
remove in interface Iterator

toArray

public Object[] toArray()
Not part of the Iterator interface, returns the data set in array form. A clone of the wrapped array is actually returned, so modifying the returned array will not affect the iteration at all.