T -
public class PermutationIterator<T> extends Objectimplements Iterator <List <T>>
| Modifier and Type | Field and Description |
|---|---|
protected List |
allElements
|
protected long |
ctr
|
protected long |
max
|
| Constructor and Description |
|---|
PermutationIterator(Collection
Create a PermutationIterator.
|
| Modifier and Type | Method and Description |
|---|---|
static long |
getFactorial(int k)
Return the factorial of the argument.
|
boolean |
hasNext()
|
List |
next()
|
void |
remove()
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEachRemainingpublic PermutationIterator(Collection<T> allElements)
allElements - all the elements this iterator will provide permutations of. Note the number of permutations this iterator creates is the factorial of the size of this list, which means it gets very large very fast. The
getFactorial(int) method will throw an ArithmeticException if there are over 20 elements. (This logic could be safely rewritten using BigIntegers to avoid that limitation, but that raises the question: should we?)
public static long getFactorial(int k)
throws ArithmeticException
k - the input value for the factorial function.
ArithmeticException - if the factorial is too large to be computed using longs. Unit tests suggest this occurs around k=21.
public boolean hasNext()
public void remove()