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