public class PermutationGenerator<E>
extends Object
implements Iterator
Systematically generate permutations. Adapted from Java Code by Michael Gilleland (released with no restrictions) using an algorithm described here: Kenneth H. Rosen, Discrete Mathematics and Its Applications, 2nd edition (NY: McGraw-Hill, 1991), pp. 282-284
| Constructor and description |
|---|
PermutationGenerator(Collection<E> items)WARNING: Don't make n too large. |
PermutationGenerator(Iterable<E> items)Creates a generator from the supplied iterable. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public BigInteger |
getTotal()Returns the total number of permutations. |
|
public boolean |
hasNext(){@inheritDoc} |
|
public List<E> |
next()Generate next permutation (algorithm from Rosen p. 284) |
|
public void |
remove(){@inheritDoc} |
|
public void |
reset()Resets the generator to its initial state. |
WARNING: Don't make n too large. Recall that the number of permutations is n! which can be very large, even when n is as small as 20 -- 20! = 2,432,902,008,176,640,000 and 21! is too big to fit into a Java long, which is why we use BigInteger instead.
items - the items to permuteCreates a generator from the supplied iterable.
items - the items to permuteReturns the total number of permutations.
{@inheritDoc}
Generate next permutation (algorithm from Rosen p. 284)
{@inheritDoc}
Resets the generator to its initial state.
Copyright © 2003-2026 The Apache Software Foundation. All rights reserved.