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.openecomp.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.
\r
32 * The order of the permutation is not taken into account when computing
\r
34 * eg: A list of A,B,C,D will return
\r
35 * [[A], [A, B, C, D], [A, C, D], [A, D], [B], [B, C, D], [B, D], [C], [C, D], [D]]
\r
37 * @param list The list to create the unique permutations
\r
38 * @return A Arraylist which contains a array list of all possible combinations
\r
40 @SuppressWarnings("serial")
\r
41 public ArrayList<ArrayList<String>> getSuggestionsPermutation(List<String> list) {
\r
42 List<String> statusList = new ArrayList<>(list);
\r
43 List<String> dupStatusList;
\r
44 ArrayList<ArrayList<String>> uniqueList = new ArrayList<ArrayList<String>>();
\r
45 int mainLoopIndexCounter = 0;
\r
46 for (String status : statusList) {
\r
47 // Add the single entity subset
\r
48 uniqueList.add(new ArrayList<String>() {
\r
53 // Remove all the elements to left till the current index
\r
54 dupStatusList = truncateListUntill(statusList, mainLoopIndexCounter);
\r
56 while (dupStatusList.size() > 0) {
\r
57 ArrayList<String> suggListInIterate= new ArrayList<>();
\r
58 suggListInIterate.add(status);
\r
59 for (String dupStatus : dupStatusList) {
\r
60 suggListInIterate.add(dupStatus);
\r
62 uniqueList.add(suggListInIterate);
\r
63 dupStatusList.remove(0);
\r
65 mainLoopIndexCounter++;
\r
71 private List<String> truncateListUntill(List<String> lists, int index) {
\r
72 List<String> truncatedList = new ArrayList<>(lists);
\r
74 while (counter <= index) {
\r
75 truncatedList.remove(0);
\r
78 return truncatedList;
\r