Java List Combine recursiveCombine(List>> toCombinate, int index)

Here you can find the source of recursiveCombine(List>> toCombinate, int index)

Description

recursive Combine

License

Apache License

Declaration

private static <T> List<List<T>> recursiveCombine(List<List<List<T>>> toCombinate, int index) 

Method Source Code


//package com.java2s;
/* Copyright (C) 2011 SpringSource
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License./*  ww w . j  ava 2  s  . c om*/
 */

import java.util.ArrayList;

import java.util.List;

public class Main {
    private static <T> List<List<T>> recursiveCombine(List<List<List<T>>> toCombinate, int index) {
        if (index == toCombinate.size() - 1) {
            //this is leaf, just return what we got at this position
            return new ArrayList<List<T>>(toCombinate.get(index));
        } else {
            List<List<T>> next = recursiveCombine(toCombinate, index + 1);
            //now combinate with each element in my list
            List<List<T>> result = new ArrayList<List<T>>();
            List<List<T>> currentContainer = toCombinate.get(index); //[ [a],[b] ]
            for (List<T> current : currentContainer) {
                for (List<T> n : next) {
                    List<T> temp = new ArrayList<T>(n);
                    temp.addAll(current);
                    result.add(temp);
                }
            }
            return result;
        }
    }
}

Related

  1. combineString(List lstInput, String strToken)
  2. combineStringList(List sList)
  3. combineSubtractArrays(List a1, List a2)
  4. getCombinedColumnName(final List columnNames, final boolean sortByName)
  5. putCombinedList(Map map, Object key, Object value)