Class PermutationEnumeration
java.lang.Object
com.espertech.esper.common.internal.collection.PermutationEnumeration
- All Implemented Interfaces:
Enumeration<int[]>
Provides a N! (n-faculty) number of permutations for N elements.
Example: for 3 elements provides 6 permutations exactly as follows:
{0, 1, 2}
{0, 2, 1}
{1, 0, 2}
{1, 2, 0}
{2, 0, 1}
{2, 1, 0}
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected static int
faculty
(int num) Computes faculty of N.protected static int[]
getFactors
(int numElements) Returns factors for computing the permutation.protected static int[]
getPermutation
(int numElements, int permutation, int[] factors) Returns permutation.boolean
int[]
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Enumeration
asIterator
-
Constructor Details
-
PermutationEnumeration
public PermutationEnumeration(int numElements) Ctor.- Parameters:
numElements
- - number of elements in each permutation.
-
-
Method Details
-
hasMoreElements
public boolean hasMoreElements()- Specified by:
hasMoreElements
in interfaceEnumeration<int[]>
-
nextElement
public int[] nextElement()- Specified by:
nextElement
in interfaceEnumeration<int[]>
-
getPermutation
protected static int[] getPermutation(int numElements, int permutation, int[] factors) Returns permutation.- Parameters:
numElements
- - number of elements in each permutationpermutation
- - number of permutation to compute, between 0 and numElements!factors
- - factors for each index- Returns:
- permutation
-
getFactors
protected static int[] getFactors(int numElements) Returns factors for computing the permutation.- Parameters:
numElements
- - number of factors to compute- Returns:
- factors list
-
faculty
protected static int faculty(int num) Computes faculty of N.- Parameters:
num
- to compute faculty for- Returns:
- N!
-