2 * Copyright © 2016-2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.sdc.tosca.datatypes.model;
18 import java.util.Collections;
19 import java.util.HashMap;
20 import java.util.HashSet;
23 import lombok.AllArgsConstructor;
28 public enum PropertyType {
34 TIMESTAMP("timestamp"),
38 SCALAR_UNIT_SIZE("scalar-unit.size"),
39 SCALAR_UNIT_TIME("scalar-unit.time"),
40 SCALAR_UNIT_FREQUENCY("scalar-unit.frequency");
43 private static final Map<String, PropertyType> M_MAP = Collections.unmodifiableMap(initializeMapping());
44 private static final Set<String> SIMPLE_PROPERTY_TYPES = Collections.unmodifiableSet(initializeSimplePropertyTypes());
45 private String displayName;
48 * Initilize property type display name mapping.
52 public static Map<String, PropertyType> initializeMapping() {
53 final Map<String, PropertyType> typeMap = new HashMap<>();
54 for (final PropertyType propertyType : PropertyType.values()) {
55 typeMap.put(propertyType.displayName, propertyType);
61 * Get Property type by display name.
64 * @return PropertyType
66 public static PropertyType getPropertyTypeByDisplayName(final String displayName) {
67 if (M_MAP.containsKey(displayName)) {
68 return M_MAP.get(displayName);
73 private static Set<String> initializeSimplePropertyTypes() {
74 final Set<String> simplePropertyTypes = new HashSet<>();
75 simplePropertyTypes.add(STRING.getDisplayName().toLowerCase());
76 simplePropertyTypes.add(INTEGER.getDisplayName().toLowerCase());
77 simplePropertyTypes.add(FLOAT.getDisplayName().toLowerCase());
78 simplePropertyTypes.add(BOOLEAN.getDisplayName().toLowerCase());
79 simplePropertyTypes.add(SCALAR_UNIT_SIZE.getDisplayName().toLowerCase());
80 simplePropertyTypes.add(SCALAR_UNIT_TIME.getDisplayName().toLowerCase());
81 simplePropertyTypes.add(SCALAR_UNIT_FREQUENCY.getDisplayName().toLowerCase());
82 return simplePropertyTypes;
85 public static Set<String> getSimplePropertyTypes() {
86 return SIMPLE_PROPERTY_TYPES;