1 /* Copyright (c) 2019 AT&T Intellectual Property. #
\r
3 # Licensed under the Apache License, Version 2.0 (the "License"); #
\r
4 # you may not use this file except in compliance with the License. #
\r
5 # You may obtain a copy of the License at #
\r
7 # http://www.apache.org/licenses/LICENSE-2.0 #
\r
9 # Unless required by applicable law or agreed to in writing, software #
\r
10 # distributed under the License is distributed on an "AS IS" BASIS, #
\r
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
\r
12 # See the License for the specific language governing permissions and #
\r
13 # limitations under the License. #
\r
14 ##############################################################################*/
\r
17 package org.oran.otf.common.utility;
\r
19 import com.fasterxml.jackson.databind.ObjectMapper;
\r
20 import com.google.common.base.Strings;
\r
21 import java.util.ArrayList;
\r
22 import java.util.Arrays;
\r
23 import java.util.Collection;
\r
24 import java.util.HashMap;
\r
25 import java.util.List;
\r
26 import java.util.Map;
\r
27 import java.util.UUID;
\r
29 public class Utility {
\r
31 public static String getLoggerPrefix() {
\r
32 return "[" + Thread.currentThread().getStackTrace()[2].getMethodName() + "]: ";
\r
35 public static Map<?, ?> toMap(Object obj) throws Exception {
\r
36 ObjectMapper mapper = new ObjectMapper();
\r
37 return mapper.convertValue(obj, HashMap.class);
\r
40 public static boolean isCollection(Object obj) {
\r
41 return obj.getClass().isArray() || obj instanceof Collection;
\r
44 public static List<?> toList(Object obj) {
\r
46 throw new NullPointerException("Argument cannot be null.");
\r
49 List<?> list = new ArrayList<>();
\r
50 if (obj.getClass().isArray()) {
\r
51 list = Arrays.asList((Object[]) obj);
\r
52 } else if (obj instanceof Collection) {
\r
53 list = new ArrayList<>((Collection<?>) obj);
\r
59 public static boolean isValidUuid(String str) {
\r
60 if (Strings.isNullOrEmpty(str)) {
\r
64 UUID uuid = UUID.fromString(str);
\r
65 return uuid.toString().equalsIgnoreCase(str);
\r
66 } catch (IllegalArgumentException iae) {
\r