Java List Merge mergeHierarchicalAndFlatDimensions( Collection> hierachicalDimensions, Collection> flatDimensions)

Here you can find the source of mergeHierarchicalAndFlatDimensions( Collection> hierachicalDimensions, Collection> flatDimensions)

Description

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}

License

Open Source License

Parameter

Parameter Description
hierachicalDimensions a parameter
flatDimensions a parameter

Declaration

public static Collection<List<Boolean>> mergeHierarchicalAndFlatDimensions(
        Collection<List<Boolean>> hierachicalDimensions, Collection<List<Boolean>> flatDimensions) 

Method Source Code


//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;
    }
}

Related

  1. mergedView(final List left, final List right)
  2. mergeErrorMsgList(List errorMsgs)
  3. mergeException(List t)
  4. mergeExcludedFieldLists(String[] superClassExcludes, String[] localClassExcludes)
  5. mergeFilterLists(List childFilters, List parentFilters)
  6. mergeIdAndStrings(Long accountId, Long workspaceId, List strs)
  7. mergeIntegerResult(List result)
  8. mergeList(List sourceList, List resultList, Set filterSet)
  9. mergeList(List list1, List list2, List... rest)