ActivitySpec - Correcting logger messages
[sdc.git] / common / openecomp-tosca-datatype / src / main / java / org / openecomp / 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
17 package org.openecomp.sdc.tosca.datatypes.model;
18
19 import java.util.Collections;
20 import java.util.HashMap;
21 import java.util.HashSet;
22 import java.util.Map;
23 import java.util.Set;
24
25 public enum PropertyType {
26
27   STRING("string"),
28   INTEGER("integer"),
29   FLOAT("float"),
30   BOOLEAN("boolean"),
31   TIMESTAMP("timestamp"),
32   NULL("null"),
33   MAP("map"),
34   LIST("list"),
35   SCALAR_UNIT_SIZE("scalar-unit.size"),
36   SCALAR_UNIT_FREQUENCY("scalar-unit.frequency");
37
38   private static final Map<String, PropertyType> mMap =
39       Collections.unmodifiableMap(initializeMapping());
40   private static final Set<String> simplePropertyTypes =
41       Collections.unmodifiableSet(initializeSimplePropertyTypes());
42   private String displayName;
43
44   PropertyType(String displayName) {
45
46     this.displayName = displayName;
47   }
48
49   /**
50    * Initilize property type display name mapping.
51    * @return Map
52    */
53   public static Map<String, PropertyType> initializeMapping() {
54     Map<String, PropertyType> typeMap = new HashMap<>();
55     for (PropertyType v : PropertyType.values()) {
56       typeMap.put(v.displayName, v);
57     }
58     return typeMap;
59   }
60
61   /**
62    * Get Property type by display name.
63    * @param displayName
64    * @return PropertyType
65    */
66   public static PropertyType getPropertyTypeByDisplayName(String displayName) {
67     if (mMap == null) {
68       initializeMapping();
69     }
70     if (mMap.containsKey(displayName)) {
71       return mMap.get(displayName);
72     }
73     return null;
74   }
75
76   private static Set<String> initializeSimplePropertyTypes() {
77     Set<String> simplePropertyTypes = new HashSet<>(4);
78     simplePropertyTypes.add(STRING.getDisplayName().toLowerCase());
79     simplePropertyTypes.add(INTEGER.getDisplayName().toLowerCase());
80     simplePropertyTypes.add(FLOAT.getDisplayName().toLowerCase());
81     simplePropertyTypes.add(BOOLEAN.getDisplayName().toLowerCase());
82     return simplePropertyTypes;
83   }
84
85   public static Set<String> getSimplePropertyTypes() {
86     return simplePropertyTypes;
87   }
88
89   public String getDisplayName() {
90     return displayName;
91   }
92
93
94 }