public final class IntPermutations extends Object implements CombinatorialIterator<int[]>
Example
The result will be
IntPermutations its = new IntPermutations(3);
while (its.hasNext())
System.out.println(Arrays.toString(its.next()))
It is also possible to iterate in the opposite direction via
[0, 1, 2]
[0, 2, 1]
[1, 0, 2]
[1, 2, 0]
[2, 0, 1]
[2, 1, 0]
previous() method.
The iterator is implemented such that each next combination will be calculated only on the invocation of method
next().
Note: method next() returns the same reference on each invocation.
| Constructor and Description |
|---|
IntPermutations(int dimension)
Construct iterator over all permutations with specified dimension starting with identity.
|
IntPermutations(int[] permutation)
Construct iterator over permutations with specified permutation at the start.
|
| Modifier and Type | Method and Description |
|---|---|
int[] |
current()
Returns the reference on the current iteration element.
|
int |
getDimension()
Returns dimension specified in the constructor
|
boolean |
hasNext() |
boolean |
hasPrevious()
Returns
true if the iteration has more elements, iterating in back order. |
int[] |
next()
Returns the next element in the iteration.
|
int[] |
previous()
Returns the previous element in the iteration.
|
void |
remove() |
void |
reset()
Resets the iteration
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waititerator, stream, toListforEachRemainingforEach, spliteratorpublic IntPermutations(int dimension)
dimension - dimension of permutationspublic IntPermutations(int[] permutation)
Note: parameter permutation is not copied in constructor and the same instance will be used
during iteration.
permutation - starting permutationIllegalArgumentException - if permutation is inconsistent with one-line notationpublic boolean hasPrevious()
true if the iteration has more elements, iterating in back order. (In other words, returns true if previous() would return an element rather than throwing an exception.)true if the iteration has more elementspublic int[] next()
public int[] previous()
public void reset()
CombinatorialIteratorreset in interface CombinatorialIterator<int[]>public void remove()
remove in interface Iterator<int[]>UnsupportedOperationException - alwayspublic int getDimension()
public int[] current()
CombinatorialIteratorcurrent in interface CombinatorialIterator<int[]>Copyright © 2017. All rights reserved.