Package com.helger.commons.math
Class CombinationGeneratorFlexible<DATATYPE>
java.lang.Object
com.helger.commons.math.CombinationGeneratorFlexible<DATATYPE>
- Type Parameters:
DATATYPE- Element type
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 -
Method Summary
Modifier and TypeMethodDescriptiongetCombinations(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 Details
-
CombinationGeneratorFlexible
Ctor- Parameters:
nSlotCount- the number of slots to usebAllowEmpty- whether or not to include an empty result set (no slot filled)
-
-
Method Details
-
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)
-