public class RandomArrayIterator<E>
extends java.lang.Object
implements java.util.Iterator<E>
resetting
them to their
original position, optionally yielding a new random permutation of the array elements.
Storage requirements are linear in the size of the underlying array, all instance operations
finish in constant time.
Instances of this class are not thread-safe.Constructor and Description |
---|
RandomArrayIterator(E[] array)
Creates a new iterator for the given array.
|
RandomArrayIterator(E[] array,
java.util.Random random)
Creates a new randomized iterator for the given array.
|
Modifier and Type | Method and Description |
---|---|
boolean |
hasNext() |
E |
next() |
void |
remove() |
void |
reset(java.util.Random random)
Resets this iterator.
|
public RandomArrayIterator(E[] array, java.util.Random random)
array
- The underlying arrayrandom
- Random source for the iteration orderpublic RandomArrayIterator(E[] array)
reset(Random)
the iterator to get a new random iteration ordering.array
- The underlying arraypublic void reset(java.util.Random random)
next()
will iterate over the array in a new random order. If it is null
,
the iteration order remains unaltered.random
- Random source for the next run, or null
to repeat the previous runpublic boolean hasNext()
hasNext
in interface java.util.Iterator<E>
public void remove()
remove
in interface java.util.Iterator<E>