2 * ============LICENSE_START===================================================
\r
3 * SPARKY (AAI UI service)
\r
4 * ============================================================================
\r
5 * Copyright © 2017 AT&T Intellectual Property.
\r
6 * Copyright © 2017 Amdocs
\r
7 * All rights reserved.
\r
8 * ============================================================================
\r
9 * Licensed under the Apache License, Version 2.0 (the "License");
\r
10 * you may not use this file except in compliance with the License.
\r
11 * You may obtain a copy of the License at
\r
13 * http://www.apache.org/licenses/LICENSE-2.0
\r
15 * Unless required by applicable law or agreed to in writing, software
\r
16 * distributed under the License is distributed on an "AS IS" BASIS,
\r
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
18 * See the License for the specific language governing permissions and
\r
19 * limitations under the License.
\r
20 * ============LICENSE_END=====================================================
\r
22 * ECOMP and OpenECOMP are trademarks
\r
23 * and service marks of AT&T Intellectual Property.
\r
25 package org.openecomp.sparky.util;
\r
27 import java.util.ArrayList;
\r
28 import java.util.List;
\r
30 public class SuggestionsPermutation {
\r
33 * Will return all the unique combinations of the suggestions provided.
\r
34 * The order of the permutation is not taken into account when computing
\r
36 * eg: A list of A,B,C,D will return
\r
37 * [[A], [A, B, C, D], [A, C, D], [A, D], [B], [B, C, D], [B, D], [C], [C, D], [D]]
\r
39 * @param list The list to create the unique permutations
\r
40 * @return A Arraylist which contains a array list of all possible combinations
\r
42 @SuppressWarnings("serial")
\r
43 public ArrayList<ArrayList<String>> getSuggestionsPermutation(List<String> list) {
\r
44 List<String> statusList = new ArrayList<>(list);
\r
45 List<String> dupStatusList;
\r
46 ArrayList<ArrayList<String>> uniqueList = new ArrayList<ArrayList<String>>();
\r
47 int mainLoopIndexCounter = 0;
\r
48 for (String status : statusList) {
\r
49 // Add the single entity subset
\r
50 uniqueList.add(new ArrayList<String>() {
\r
55 // Remove all the elements to left till the current index
\r
56 dupStatusList = truncateListUntill(statusList, mainLoopIndexCounter);
\r
58 while (dupStatusList.size() > 0) {
\r
59 ArrayList<String> suggListInIterate= new ArrayList<>();
\r
60 suggListInIterate.add(status);
\r
61 for (String dupStatus : dupStatusList) {
\r
62 suggListInIterate.add(dupStatus);
\r
64 uniqueList.add(suggListInIterate);
\r
65 dupStatusList.remove(0);
\r
67 mainLoopIndexCounter++;
\r
73 private List<String> truncateListUntill(List<String> lists, int index) {
\r
74 List<String> truncatedList = new ArrayList<>(lists);
\r
76 while (counter <= index) {
\r
77 truncatedList.remove(0);
\r
80 return truncatedList;
\r