Here you can find the source of combineAux(List
private static <E> void combineAux(List<Collection<E>> collections, List<E> objectAccumulator, List<Collection<E>> resultList)
//package com.java2s; /*/*from ww w . jav a 2 s.co m*/ Copyright 2009 Semantic Discovery, Inc. (www.semanticdiscovery.com) This file is part of the Semantic Discovery Toolkit. The Semantic Discovery Toolkit is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. The Semantic Discovery Toolkit is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with The Semantic Discovery Toolkit. If not, see <http://www.gnu.org/licenses/>. */ import java.util.List; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; public class Main { /** Recursive auxiliary for combine(collections). */ private static <E> void combineAux(List<Collection<E>> collections, List<E> objectAccumulator, List<Collection<E>> resultList) { int numCollections = collections.size(); if (numCollections == 0) { return; } Collection<E> firstCollection = collections.iterator().next(); boolean isEmpty = firstCollection == null || firstCollection.size() == 0; if (numCollections == 1) { if (!isEmpty) { for (Iterator<E> it = firstCollection.iterator(); it.hasNext();) { E curObject = it.next(); List<E> nextAccumulator = new ArrayList<E>(objectAccumulator); nextAccumulator.add(curObject); resultList.add(nextAccumulator); } } else { List<E> nextAccumulator = new ArrayList<E>(objectAccumulator); nextAccumulator.add(null); resultList.add(nextAccumulator); } return; } List<Collection<E>> remainder = collections.subList(1, numCollections); if (!isEmpty) { for (Iterator<E> it = firstCollection.iterator(); it.hasNext();) { E curObject = it.next(); List<E> nextAccumulator = new ArrayList<E>(objectAccumulator); nextAccumulator.add(curObject); combineAux(remainder, nextAccumulator, resultList); } } else { List<E> nextAccumulator = new ArrayList<E>(objectAccumulator); nextAccumulator.add(null); combineAux(remainder, nextAccumulator, resultList); } } }