2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * Copyright © 2017 Amdocs
\r
7 * ================================================================================
\r
8 * Licensed under the Apache License, Version 2.0 (the "License");
\r
9 * you may not use this file except in compliance with the License.
\r
10 * You may obtain a copy of the License at
\r
12 * http://www.apache.org/licenses/LICENSE-2.0
\r
14 * Unless required by applicable law or agreed to in writing, software
\r
15 * distributed under the License is distributed on an "AS IS" BASIS,
\r
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 * See the License for the specific language governing permissions and
\r
18 * limitations under the License.
\r
19 * ============LICENSE_END=========================================================
\r
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
23 package org.onap.aai.sparky.util;
\r
25 import java.util.ArrayList;
\r
26 import java.util.List;
\r
28 public class SuggestionsPermutation {
\r
31 * Will return all the unique combinations of the suggestions provided. The order of the
\r
32 * permutation is not taken into account when computing the uniqueness. eg: A list of A,B,C,D will
\r
33 * return [[A], [A, B, C, D], [A, C, D], [A, D], [B], [B, C, D], [B, D], [C], [C, D], [D]]
\r
35 * @param list The list to create the unique permutations
\r
37 * @return A Arraylist which contains a array list of all possible combinations
\r
39 public static ArrayList<ArrayList<String>> getUniqueListForSuggestions(
\r
40 List<String> originalList) {
\r
41 ArrayList<ArrayList<String>> lists = new ArrayList<ArrayList<String>>();
\r
42 if (originalList.isEmpty()) {
\r
43 lists.add(new ArrayList<String>());
\r
46 List<String> list = new ArrayList<String>(originalList);
\r
47 String head = list.get(0);
\r
48 ArrayList<String> rest = new ArrayList<String>(list.subList(1, list.size()));
\r
50 for (ArrayList<String> activeList : getUniqueListForSuggestions(rest)) {
\r
51 ArrayList<String> newList = new ArrayList<String>();
\r
53 newList.addAll(activeList);
\r
55 lists.add(activeList);
\r
60 public static ArrayList<ArrayList<String>> getNonEmptyUniqueLists(List<String> list) {
\r
61 ArrayList<ArrayList<String>> lists = getUniqueListForSuggestions(list);
\r
62 // remove empty list from the power set
\r
63 for (ArrayList<String> emptyList : lists) {
\r
64 if (emptyList.isEmpty()) {
\r
65 lists.remove(emptyList);
\r
72 public static List<List<String>> getListPermutations(List<String> list) {
\r
73 List<String> inputList = new ArrayList<String>();
\r
74 inputList.addAll(list);
\r
75 if (inputList.size() == 0) {
\r
76 List<List<String>> result = new ArrayList<List<String>>();
\r
77 result.add(new ArrayList<String>());
\r
81 List<List<String>> listOfLists = new ArrayList<List<String>>();
\r
83 String firstElement = inputList.remove(0);
\r
85 List<List<String>> recursiveReturn = getListPermutations(inputList);
\r
86 for (List<String> li : recursiveReturn) {
\r
88 for (int index = 0; index <= li.size(); index++) {
\r
89 List<String> temp = new ArrayList<String>(li);
\r
90 temp.add(index, firstElement);
\r
91 listOfLists.add(temp);
\r