update link to upper-constraints.txt
[msb/apigateway.git] / apiroute / apiroute-service / src / main / java / org / onap / msb / apiroute / wrapper / util / CommonUtil.java
1 /*******************************************************************************
2  * Copyright 2016-2017 ZTE, Inc. and others.
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  * 
7  * http://www.apache.org/licenses/LICENSE-2.0
8  * 
9  * Unless required by applicable law or agreed to in writing, software distributed under the License
10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11  * or implied. See the License for the specific language governing permissions and limitations under
12  * the License.
13  ******************************************************************************/
14 package org.onap.msb.apiroute.wrapper.util;
15
16 import java.util.HashSet;
17 import java.util.Set;
18
19 import org.apache.commons.lang3.StringUtils;
20
21 public class CommonUtil {
22
23     public static final int SC_OK = 200;
24
25     public static Object[] concat(Object[] a, Object[] b) {
26         Object[] c = new Object[a.length + b.length];
27         System.arraycopy(a, 0, c, 0, a.length);
28         System.arraycopy(b, 0, c, a.length, b.length);
29         return c;
30     }
31
32     public static boolean contain(String strArray, String str) {
33         String[] array = StringUtils.split(strArray, ",");
34         return contain(array, str);
35     }
36
37     public static boolean contain(String[] array, String str) {
38         for (int i = 0; i < array.length; i++) {
39             if (array[i].trim().equals(str)) {
40                 return true;
41             }
42         }
43         return false;
44
45     }
46
47     public static boolean contain(String[] array, String value[]) {
48         for (int i = 0; i < array.length; i++) {
49             for (int n = 0; n < value.length; n++) {
50                 if (array[i].equals(value[n])) {
51                     return true;
52                 }
53             }
54         }
55         return false;
56
57     }
58
59     /**
60      * @param <T>
61      * @Title getDiffrent
62      * @Description TODO(Extract the list1 and list2 different data sets)
63      * @param list1
64      * @param list2
65      * @return TODO(a new List in list2 but not in list1)
66      * @return List<String>
67      */
68     public static <T> Set<T> getDiffrent(Set<T> list1, Set<T> list2) {
69
70         HashSet<T> set_all = new HashSet<T>();
71
72         for (T t1 : list1) {
73             set_all.add(t1);
74         }
75
76
77         Set<T> diff = new HashSet<T>();
78
79         for (T t2 : list2) {
80             if (set_all.add(t2)) { // in list2 but not in list1
81                 diff.add(t2);
82             }
83         }
84
85
86         return diff;
87     }
88
89 }