2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.heat.datatypes;
23 import org.apache.commons.lang.math.NumberUtils;
25 import java.util.HashMap;
26 import java.util.List;
28 import java.util.Objects;
30 public enum DefinedHeatParameterTypes {
33 COMMA_DELIMITED_LIST("comma_delimited_list"),
37 private static Map<String, DefinedHeatParameterTypes> stringToDefinedType = new HashMap<>();
40 stringToDefinedType = new HashMap<>();
41 for (DefinedHeatParameterTypes definedHeatParameterType : DefinedHeatParameterTypes.values()) {
42 stringToDefinedType.put(definedHeatParameterType.type, definedHeatParameterType);
48 DefinedHeatParameterTypes(String type) {
52 public static DefinedHeatParameterTypes findByHeatResource(String type) {
53 return stringToDefinedType.get(type);
57 * Is value is from given type boolean.
59 * @param value the value
60 * @param parameterType the parameter type
63 public static boolean isValueIsFromGivenType(Object value, String parameterType) {
64 DefinedHeatParameterTypes definedType = findByHeatResource(parameterType);
66 if (Objects.nonNull(definedType)) {
67 switch (definedType) {
69 return NumberUtils.isNumber(String.valueOf(value));
72 return HeatBoolean.isValueBoolean(value);
74 case COMMA_DELIMITED_LIST:
75 String valAsString = String.valueOf(value);
76 return valAsString.split(",") instanceof String[];
79 return (value instanceof Map) || (value instanceof List);
90 public static boolean isNovaServerEnvValueIsFromRightType(Object value) {
91 return isValueIsFromGivenType(value, COMMA_DELIMITED_LIST.getType())
92 || isValueIsFromGivenType(value, STRING.getType());
95 public static boolean isEmptyValueInEnv(Object value) {
96 return Objects.isNull(value);
99 public String getType() {
103 public void setType(String type) {