Divide the MSB source codes into two repos
[msb/apigateway.git] / apiroute / apiroute-service / src / main / java / org / onap / msb / apiroute / wrapper / util / CommonUtil.java
1 package org.onap.msb.apiroute.wrapper.util;
2
3 import java.util.HashSet;
4 import java.util.Set;
5
6 import org.apache.commons.lang3.StringUtils;
7
8 public class CommonUtil {
9
10   public static final int SC_OK = 200;
11   
12   public static Object[] concat(Object[] a, Object[] b) {
13     Object[] c = new Object[a.length + b.length];
14     System.arraycopy(a, 0, c, 0, a.length);
15     System.arraycopy(b, 0, c, a.length, b.length);
16     return c;
17   }
18
19   public static boolean contain(String strArray, String str) {
20     String[] array = StringUtils.split(strArray, ",");
21     return contain(array, str);
22   }
23
24   public static boolean contain(String[] array, String str) {
25     for (int i = 0; i < array.length; i++) {
26       if (array[i].trim().equals(str)) {
27         return true;
28       }
29     }
30     return false;
31
32   }
33
34   public static boolean contain(String[] array, String value[]) {
35     for (int i = 0; i < array.length; i++) {
36       for (int n = 0; n < value.length; n++) {
37         if (array[i].equals(value[n])) {
38           return true;
39         }
40       }
41     }
42     return false;
43
44   }
45
46   /**
47    * @param <T>
48    * @Title getDiffrent
49    * @Description TODO(Extract the list1 and list2 different data sets)
50    * @param list1
51    * @param list2
52    * @return TODO(a new List in list2 but not in list1)
53    * @return List<String>
54    */
55   public static <T> Set<T> getDiffrent(Set<T> list1, Set<T> list2) {
56
57     HashSet<T> set_all = new HashSet<T>();
58
59     for (T t1 : list1) {
60       set_all.add(t1);
61     }
62
63
64     Set<T> diff = new HashSet<T>();
65
66     for (T t2 : list2) {
67       if (set_all.add(t2)) { // in list2 but not in list1
68         diff.add(t2);
69       }
70     }
71
72
73     return diff;
74   }
75
76 }