/** * Returns a collection containing all possible combinations of the input values. * @param <E> the element type * @param values a List of collections of values * @return a collection of Lists, all the same size as the input List, containing all possible * combinations of the values in the collections, in their respective indexes in the List. */ public static <E> Collection<List<E>> fanOutCombinations(List<Collection<E>> values) { Collection<List<E>> retval = new ArrayList<List<E>>(); List<E> soFar = Collections.emptyList(); fanOutCombinations(values, retval, soFar, 0); return retval; }
/** * Returns a collection containing all possible combinations of the input values. * @param <E> the element type * @param values a List of collections of values * @return a collection of Lists, all the same size as the input List, containing all possible * combinations of the values in the collections, in their respective indexes in the List. */ public static <E> Collection<List<E>> fanOutCombinations(List<Collection<E>> values) { Collection<List<E>> retval = new ArrayList<List<E>>(); List<E> soFar = Collections.emptyList(); fanOutCombinations(values, retval, soFar, 0); return retval; }
private static <E> void fanOutCombinations(List<Collection<E>> values, Collection<List<E>> retval, List<E> soFar, int index) { if (index == values.size() - 1) { for (E value : values.get(index)) { List<E> solution = new ArrayList<E>(soFar); solution.add(value); retval.add(solution); } } else { for (E value : values.get(index)) { List<E> solution = new ArrayList<E>(soFar); solution.add(value); fanOutCombinations(values, retval, solution, index + 1); } } }
private static <E> void fanOutCombinations(List<Collection<E>> values, Collection<List<E>> retval, List<E> soFar, int index) { if (index == values.size() - 1) { for (E value : values.get(index)) { List<E> solution = new ArrayList<E>(soFar); solution.add(value); retval.add(solution); } } else { for (E value : values.get(index)) { List<E> solution = new ArrayList<E>(soFar); solution.add(value); fanOutCombinations(values, retval, solution, index + 1); } } }
.fanOutCombinations(values)) { if (keysToSourceObjects.containsKey(valueSet)) { throw new ObjectStoreException("Duplicate objects found for pk "
.fanOutCombinations(values)) { if (keysToSourceObjects.containsKey(valueSet)) { throw new ObjectStoreException("Duplicate objects found for pk "