Class CombinationIterator

java.lang.Object
org.gorpipe.gor.gava.CombinationIterator

public class CombinationIterator
extends java.lang.Object
Iterate through all combinations (n choose k) and provide permutations representing the combinations. Designed to work in permutation tests, where instead of randomization all combinations are tested.
  • Constructor Summary

    Constructors 
    Constructor Description
    CombinationIterator​(int totalCount, int subCount)
    Instantiate the iterator.
  • Method Summary

    Modifier and Type Method Description
    static double getNumberOfCombinations​(int n, int k)
    Computes the number of combinations.
    int[] getPermutation()  
    boolean next()
    Advance to the next combination.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CombinationIterator

      public CombinationIterator​(int totalCount, int subCount)
      Instantiate the iterator.
      Parameters:
      totalCount - the total number of elements
      subCount - the number of elements to choose
  • Method Details

    • getPermutation

      public int[] getPermutation()
      Returns:
      a permutation representing the combination
    • next

      public boolean next()
      Advance to the next combination. (First call stays in the initial combination.)
      Returns:
      true if there is a next combination
    • getNumberOfCombinations

      public static double getNumberOfCombinations​(int n, int k)
      Computes the number of combinations. Returns a double because rounding to int will cause undesired results when the number is larger than max int.
      Parameters:
      n - total count
      k - sub count
      Returns:
      the number of combinations (n choose k)