Here you can find the source of mergeHierarchicalAndFlatDimensions( Collection> hierachicalDimensions, Collection
> flatDimensions)
Parameter | Description |
---|---|
hierachicalDimensions | a parameter |
flatDimensions | a parameter |
public static Collection<List<Boolean>> mergeHierarchicalAndFlatDimensions( Collection<List<Boolean>> hierachicalDimensions, Collection<List<Boolean>> flatDimensions)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Collection; import java.util.List; public class Main { /**/* ww w. j a v a 2s .c om*/ * Hierarchical: * {1, 0, 0} * {1, 1, 0} * {1, 1, 1} * * Flat: * {1, 0} * {1, 1} * {0, 0} * {0, 1} * * Result: * {1, 0, 0, 1, 0} * {1, 0, 0, 1, 1} * {1, 0, 0, 0, 0} * {1, 0, 0, 0, 1} * * {1, 1, 0, 1, 0} * {1, 1, 0, 1, 1} * {1, 1, 0, 0, 0} * {1, 1, 0, 0, 1} * * {1, 1, 1, 1, 0} * {1, 1, 1, 1, 1} * {1, 1, 1, 0, 0} * {1, 1, 1, 0, 1} * * @param hierachicalDimensions * @param flatDimensions * @return */ public static Collection<List<Boolean>> mergeHierarchicalAndFlatDimensions( Collection<List<Boolean>> hierachicalDimensions, Collection<List<Boolean>> flatDimensions) { if (hierachicalDimensions.size() == 0) { return flatDimensions; } if (flatDimensions.size() == 0) { return hierachicalDimensions; } Collection<List<Boolean>> result = new ArrayList<>(hierachicalDimensions.size() * flatDimensions.size()); hierachicalDimensions.forEach(hierarchicalCombination -> { flatDimensions.forEach(flatCombination -> { List<Boolean> mergedCombination = new ArrayList<>( hierarchicalCombination.size() + flatCombination.size()); mergedCombination.addAll(hierarchicalCombination); mergedCombination.addAll(flatCombination); result.add(mergedCombination); }); }); return result; } }