Package de.hybris.platform.patches.utils
Class PermutationUtils
java.lang.Object
de.hybris.platform.patches.utils.PermutationUtils
Utility class to build permutations of given collections
-
Method Summary
Modifier and TypeMethodDescriptionstatic ImpexHeaderOption[][]permutate(ImpexHeaderOption[][] source) This method creates all permutations of elements from different collections.
Assume that as entry we get:
String[][]{{"A1","A2"},{"B1"},{"C1","C2","C3"},{"D1","D2","D3","D4"}}
In result we would like to have all possible 4 elements combinations that contains one element with A prefix, one with B, one with C and one with D.
In result there will be 2*1*3*4 elements = 24 each of length 4
Finally result for example above will be:
[A1, B1, C1, D1], [A2, B1, C1, D1],
[A1, B1, C2, D1], [A2, B1, C2, D1],
[A1, B1, C3, D1], [A2, B1, C3, D1],
[A1, B1, C1, D2], [A2, B1, C1, D2],
[A1, B1, C2, D2], [A2, B1, C2, D2],
[A1, B1, C3, D2], [A2, B1, C3, D2],
[A1, B1, C1, D3], [A2, B1, C1, D3],
[A1, B1, C2, D3], [A2, B1, C2, D3],
[A1, B1, C3, D3], [A2, B1, C3, D3],
[A1, B1, C1, D4], [A2, B1, C1, D4],
[A1, B1, C2, D4], [A2, B1, C2, D4],
[A1, B1, C3, D4], [A2, B1, C3, D4]
Idea behind the code is to iterate over all possible permutations (so in example above from 0 to 23) - loop A.
then iterate over elements that should be in this permutation (so in example above 0-3) - loop B.
then fill in in target (result) proper element.
-
Method Details
-
permutate
This method creates all permutations of elements from different collections.
Assume that as entry we get:
String[][]{{"A1","A2"},{"B1"},{"C1","C2","C3"},{"D1","D2","D3","D4"}}
In result we would like to have all possible 4 elements combinations that contains one element with A prefix, one with B, one with C and one with D.
In result there will be 2*1*3*4 elements = 24 each of length 4
Finally result for example above will be:
[A1, B1, C1, D1], [A2, B1, C1, D1],
[A1, B1, C2, D1], [A2, B1, C2, D1],
[A1, B1, C3, D1], [A2, B1, C3, D1],
[A1, B1, C1, D2], [A2, B1, C1, D2],
[A1, B1, C2, D2], [A2, B1, C2, D2],
[A1, B1, C3, D2], [A2, B1, C3, D2],
[A1, B1, C1, D3], [A2, B1, C1, D3],
[A1, B1, C2, D3], [A2, B1, C2, D3],
[A1, B1, C3, D3], [A2, B1, C3, D3],
[A1, B1, C1, D4], [A2, B1, C1, D4],
[A1, B1, C2, D4], [A2, B1, C2, D4],
[A1, B1, C3, D4], [A2, B1, C3, D4]
Idea behind the code is to iterate over all possible permutations (so in example above from 0 to 23) - loop A.
then iterate over elements that should be in this permutation (so in example above 0-3) - loop B.
then fill in in target (result) proper element.- Parameters:
source- source array- Returns:
nullif source isnull, otherwise proper permutation
-