3cec134b867d174750df4278e2d4817e36b29802
[sdc.git] / common / onap-tosca-datatype / src / main / java / org / onap / sdc / tosca / datatypes / model / PropertyType.java
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.onap.sdc.tosca.datatypes.model;
17
18 import java.util.Collections;
19 import java.util.HashMap;
20 import java.util.HashSet;
21 import java.util.Map;
22 import java.util.Set;
23 import lombok.AllArgsConstructor;
24 import lombok.Getter;
25
26 @AllArgsConstructor
27 @Getter
28 public enum PropertyType {
29     // @formatter:off
30     STRING("string"),
31     INTEGER("integer"),
32     FLOAT("float"),
33     BOOLEAN("boolean"),
34     TIMESTAMP("timestamp"),
35     NULL("null"),
36     MAP("map"),
37     LIST("list"),
38     SCALAR_UNIT_SIZE("scalar-unit.size"),
39     SCALAR_UNIT_TIME("scalar-unit.time"),
40     SCALAR_UNIT_FREQUENCY("scalar-unit.frequency");
41     // @formatter:on
42
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;
46
47     /**
48      * Initilize property type display name mapping.
49      *
50      * @return Map
51      */
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);
56         }
57         return typeMap;
58     }
59
60     /**
61      * Get Property type by display name.
62      *
63      * @param displayName
64      * @return PropertyType
65      */
66     public static PropertyType getPropertyTypeByDisplayName(final String displayName) {
67         if (M_MAP.containsKey(displayName)) {
68             return M_MAP.get(displayName);
69         }
70         return null;
71     }
72
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;
83     }
84
85     public static Set<String> getSimplePropertyTypes() {
86         return SIMPLE_PROPERTY_TYPES;
87     }
88 }