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