org.clapper.util.misc
Class ArrayIterator<T>
- java.lang.Object
-
- org.clapper.util.misc.ArrayIterator<T>
-
- All Implemented Interfaces:
- java.util.Iterator<T>
public class ArrayIterator<T> extends java.lang.Object implements java.util.Iterator<T>The ArrayIterator class provides a bridge between an array of objects and an Iterator. It's useful in cases where you have an array, but you need an Iterator; using an instance of ArrayIterator saves copying the array's contents into a Collection, just to get an Iterator.- See Also:
Iterator
-
-
Constructor Summary
Constructors Constructor and Description ArrayIterator(T[] array)Allocate a new ArrayIterator object that will iterate over the specified array of objects.ArrayIterator(T[] array, int index)Allocate a new ArrayIterator object that will iterate over the specified array of objects, starting at a particular index.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description intgetNextIndex()Get the index of the next element to be retrieved.booleanhasNext()Determine whether the underlying Iterator has more elements.Tnext()Get the next element from the underlying array.Tprevious()Get the previous element from the underlying array.voidremove()Required by the Iterator interface, but not supported by this class.
-
-
-
Constructor Detail
-
ArrayIterator
public ArrayIterator(T[] array)
Allocate a new ArrayIterator object that will iterate over the specified array of objects.- Parameters:
array- The array over which to iterate
-
ArrayIterator
public ArrayIterator(T[] array, int index)
Allocate a new ArrayIterator object that will iterate over the specified array of objects, starting at a particular index. The index isn't checked for validity until next() is called.- Parameters:
array- The array over which to iterateindex- The index at which to start
-
-
Method Detail
-
getNextIndex
public int getNextIndex()
Get the index of the next element to be retrieved. This index value might be past the end of the array.- Returns:
- the index
-
hasNext
public boolean hasNext()
Determine whether the underlying Iterator has more elements.
-
next
public T next() throws java.util.NoSuchElementException
Get the next element from the underlying array.- Specified by:
nextin interfacejava.util.Iterator<T>- Returns:
- the next element from the underlying array
- Throws:
java.util.NoSuchElementException- No more elements exist- See Also:
previous(),Iterator.next()
-
previous
public T previous() throws java.util.NoSuchElementException
Get the previous element from the underlying array. This method decrements the iterator's internal index by one, and returns the corresponding element.- Returns:
- the previous element from the underlying array
- Throws:
java.util.NoSuchElementException- Attempt to move internal index before the first array element- See Also:
next()
-
remove
public void remove()
Required by the Iterator interface, but not supported by this class.- Specified by:
removein interfacejava.util.Iterator<T>- Throws:
java.lang.UnsupportedOperationException- unconditionally
-
-
DMelt 3.0 © DataMelt by jWork.ORG