AllocationUtils { public static <T> List<List<T>> getPermutations(List<List<T>> possibilities, int max) { List<List<T>> results = new ArrayList<>(); getPermutations(possibilities, results, 0, new ArrayList<>(), max); return results; }  static List<List<T>> getPermutations(List<List<T>> possibilities, int max); static List<TopologyWrapper> generateTargetLabelTopologies(TopologyWrapper topology,
                                                                      List<List<PermutationHelper>> permutations); static List<TPolicyTemplate> getPolicyTemplates(TNodeTemplate nodeTemplate); static TPolicyTemplate toPolicyTemplate(TPolicy policy); static TTopologyTemplate deepcopy(TTopologyTemplate topologyTemplate); static TTopologyTemplate deepcopy(TTopologyTemplate topologyTemplate, boolean changeNames); static TNodeTemplate clone(TNodeTemplate nodeTemplate, boolean changeNames); static TRelationshipTemplate clone(TRelationshipTemplate relationshipTemplate, boolean changeNames); static long idCounter; }
@Test public void getPermutations() { List<List<String>> possibilities = Arrays.asList(Arrays.asList("A", "B"), Arrays.asList("C", "D")); List<List<String>> results = AllocationUtils.getPermutations(possibilities, 4); assertEquals(4, results.size()); assertEquals("[[A, C], [A, D], [B, C], [B, D]]", results.toString()); results = AllocationUtils.getPermutations(possibilities, 2); assertEquals(2, results.size()); assertEquals("[[A, C], [A, D]]", results.toString()); results = AllocationUtils.getPermutations(possibilities, -10); assertEquals(0, results.size()); possibilities = Collections.singletonList(Arrays.asList("A", "B", "C")); results = AllocationUtils.getPermutations(possibilities, Integer.MAX_VALUE); assertEquals("[[A], [B], [C]]", results.toString()); }