Package com.helger.commons.math
Class CombinationGeneratorFlexible<DATATYPE>
- java.lang.Object
-
- com.helger.commons.math.CombinationGeneratorFlexible<DATATYPE>
-
- Type Parameters:
DATATYPE- Element type
@Immutable public final class CombinationGeneratorFlexible<DATATYPE> extends Object
Utility class for generating all possible combinations of elements for a specified number of available slots. Duplicates in the passed elements will not deliver duplicate result solutions. This implementation is flexible in terms of handling the slots. This means it will also return result sets where not all slots are filled.- Author:
- Boris Gregorcic, Philip Helger
-
-
Constructor Summary
Constructors Constructor Description CombinationGeneratorFlexible(int nSlotCount, boolean bAllowEmpty)Ctor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ICommonsSet<ICommonsList<DATATYPE>>getCombinations(ICommonsList<DATATYPE> aElements)Generate all combinations without duplicates.static <DATATYPE> ICommonsSet<ICommonsList<DATATYPE>>getCombinations(ICommonsList<DATATYPE> aElements, boolean bAllowEmpty)static <DATATYPE> voiditerateAllCombinations(ICommonsList<DATATYPE> aElements, boolean bAllowEmpty, Consumer<? super ICommonsList<DATATYPE>> aCallback)voiditerateAllCombinations(ICommonsList<DATATYPE> aElements, Consumer<? super ICommonsList<DATATYPE>> aCallback)Iterate all combination, no matter they are unique or not.
-
-
-
Constructor Detail
-
CombinationGeneratorFlexible
public CombinationGeneratorFlexible(@Nonnegative int nSlotCount, boolean bAllowEmpty)
Ctor- Parameters:
nSlotCount- the number of slots to usebAllowEmpty- whether or not to include an empty result set (no slot filled)
-
-
Method Detail
-
iterateAllCombinations
public void iterateAllCombinations(@Nonnull ICommonsList<DATATYPE> aElements, @Nonnull Consumer<? super ICommonsList<DATATYPE>> aCallback)
Iterate all combination, no matter they are unique or not.- Parameters:
aElements- List of elements.aCallback- Callback to invoke
-
getCombinations
@Nonnull @ReturnsMutableCopy public ICommonsSet<ICommonsList<DATATYPE>> getCombinations(@Nonnull ICommonsList<DATATYPE> aElements)
Generate all combinations without duplicates.- Parameters:
aElements- the elements to distribute to the specified slots (may be empty!)- Returns:
- a set of slot allocations representing all possible combinations
-
iterateAllCombinations
public static <DATATYPE> void iterateAllCombinations(@Nonnull ICommonsList<DATATYPE> aElements, boolean bAllowEmpty, @Nonnull Consumer<? super ICommonsList<DATATYPE>> aCallback)
-
getCombinations
@Nonnull @ReturnsMutableCopy public static <DATATYPE> ICommonsSet<ICommonsList<DATATYPE>> getCombinations(@Nonnull ICommonsList<DATATYPE> aElements, boolean bAllowEmpty)
-
-