be.ac.ua.broker.utils
Class CombinationGenerator

java.lang.Object
  extended by be.ac.ua.broker.utils.CombinationGenerator

public class CombinationGenerator
extends java.lang.Object

This class is used to systematically generate the next possible combination when it is needed, this utility class is needed because it is impossible to store a very large number of combinations in memory at once.

Author:
Vermeersch Kurt (based on http://www.merriampark.com/comb.htm implementation)

Constructor Summary
CombinationGenerator(int n, int r)
          Constructor for CombinationGenerator
 
Method Summary
 int[] getCurrent()
           
 int[] getNext()
          Generate next combination (algorithm from Rosen p.
 java.math.BigInteger getNumLeft()
           
 java.math.BigInteger getTotal()
           
 boolean hasMore()
           
 void reset()
          Reset the combination generator, start iterating again from the first combination possible.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CombinationGenerator

public CombinationGenerator(int n,
                            int r)
Constructor for CombinationGenerator

Parameters:
n - number of possible integers
r - size of one combination
Method Detail

reset

public void reset()
Reset the combination generator, start iterating again from the first combination possible.


getNumLeft

public java.math.BigInteger getNumLeft()
Returns:
the number of combinations we still need to iterate over

hasMore

public boolean hasMore()
Returns:
whether there are more combinations or we iterated over all of them already

getTotal

public java.math.BigInteger getTotal()
Returns:
the total number of combinations

getNext

public int[] getNext()
Generate next combination (algorithm from Rosen p. 286)

Returns:
the next combination

getCurrent

public int[] getCurrent()
Returns:
the current combination