package hu.bme.mit.incquery.cep.performance.test.generator; import java.util.ArrayList; import java.util.List; import com.google.common.collect.Lists; public class PermutationHelper<E> { public List<List<E>> generatePerm(List<E> original) { if (original.size() == 0) { List<List<E>> result = new ArrayList<List<E>>(); result.add(new ArrayList<E>()); return result; } E firstElement = original.remove(0); List<List<E>> returnValue = new ArrayList<List<E>>(); List<List<E>> permutations = generatePerm(original); for (List<E> smallerPermutated : permutations) { for (int index = 0; index <= smallerPermutated.size(); index++) { List<E> temp = new ArrayList<E>(smallerPermutated); temp.add(index, firstElement); returnValue.add(temp); } } return returnValue; } public List<List<E>> generatePerm2(List<E> original, int length) { if (original.size() == 0) { List<List<E>> result = new ArrayList<List<E>>(); result.add(new ArrayList<E>()); return result; } E firstElement = original.remove(0); List<List<E>> returnValue = new ArrayList<List<E>>(); List<List<E>> permutations = generatePerm(original); int i = 0; for (List<E> smallerPermutated : permutations) { for (int index = 0; index <= smallerPermutated.size(); index++) { System.out.println(i); if(i==length){ return returnValue; } List<E> temp = new ArrayList<E>(smallerPermutated); temp.add(index, firstElement); returnValue.add(temp); i++; } } return returnValue; } }