Package one.microstream.util.iterables
Class RandomArrayIterator<E>
- java.lang.Object
-
- one.microstream.util.iterables.RandomArrayIterator<E>
-
- All Implemented Interfaces:
Iterator<E>
public final class RandomArrayIterator<E> extends Object implements Iterator<E>
Iterator
implementation of a random array element retrieval generator.Usage example:
prints (for example):for(final Integer i : random(10, array(1,3,5,7,9))) { System.out.println(i); }
7
3
1
3
3
3
9
7
1
7
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RandomArrayIterator.Factory<E>
-
Constructor Summary
Constructors Constructor Description RandomArrayIterator(E[] array, int count)
-
Method Summary
Modifier and Type Method Description int
abort()
Aborts the random iteration and returns the iteration count thisRandomArrayIterator
has produced until now.RandomArrayIterator<E>
decrementCount(int amount)
int
getCount()
int
getIterationCount()
Returns the iteration count thisRandomArrayIterator
has produced until now.boolean
hasNext()
RandomArrayIterator<E>
incrementCount(int amount)
E
next()
static <E> RandomArrayIterator.Factory<E>
random(int count, E[] array)
void
remove()
RandomArrayIterator<E>
setCount(int count)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Iterator
forEachRemaining
-
-
-
-
Constructor Detail
-
RandomArrayIterator
public RandomArrayIterator(E[] array, int count)
-
-
Method Detail
-
random
public static <E> RandomArrayIterator.Factory<E> random(int count, E[] array)
-
getCount
public int getCount()
-
setCount
public RandomArrayIterator<E> setCount(int count)
- Parameters:
count
- the count to set
-
incrementCount
public RandomArrayIterator<E> incrementCount(int amount)
- Parameters:
amount
-
-
decrementCount
public RandomArrayIterator<E> decrementCount(int amount)
- Parameters:
amount
-
-
abort
public int abort()
Aborts the random iteration and returns the iteration count thisRandomArrayIterator
has produced until now.- Returns:
- the current iteration count.
- See Also:
getIterationCount()
-
getIterationCount
public int getIterationCount()
Returns the iteration count thisRandomArrayIterator
has produced until now.- Returns:
- the current iteration count.
- See Also:
abort()
-
hasNext
public boolean hasNext()
- Specified by:
hasNext
in interfaceIterator<E>
- See Also:
Iterator.hasNext()
-
next
public E next()
- Specified by:
next
in interfaceIterator<E>
- See Also:
Iterator.next()
-
remove
public void remove() throws UnsupportedOperationException
- Specified by:
remove
in interfaceIterator<E>
- Throws:
UnsupportedOperationException
- See Also:
Iterator.remove()
-
-