Class PermutationEnumeration

java.lang.Object
com.espertech.esper.common.internal.collection.PermutationEnumeration
All Implemented Interfaces:
Enumeration<int[]>

public class PermutationEnumeration extends Object implements 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 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 interface Enumeration<int[]>
    • nextElement

      public int[] nextElement()
      Specified by:
      nextElement in interface Enumeration<int[]>
    • getPermutation

      protected static int[] getPermutation(int numElements, int permutation, int[] factors)
      Returns permutation.
      Parameters:
      numElements - - number of elements in each permutation
      permutation - - 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!