Fix checkstyle violations in sdc-main/common
[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> M_MAP =
34       Collections.unmodifiableMap(initializeMapping());
35   private static final Set<String> SIMPLE_PROPERTY_TYPES =
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 (M_MAP.containsKey(displayName)) {
63       return M_MAP.get(displayName);
64     }
65     return null;
66   }
67
68   private static Set<String> initializeSimplePropertyTypes() {
69     final int setSize = 4;
70     Set<String> simplePropertyTypes = new HashSet<>(setSize);
71     simplePropertyTypes.add(STRING.getDisplayName().toLowerCase());
72     simplePropertyTypes.add(INTEGER.getDisplayName().toLowerCase());
73     simplePropertyTypes.add(FLOAT.getDisplayName().toLowerCase());
74     simplePropertyTypes.add(BOOLEAN.getDisplayName().toLowerCase());
75     return simplePropertyTypes;
76   }
77
78   public static Set<String> getSimplePropertyTypes() {
79     return SIMPLE_PROPERTY_TYPES;
80   }
81
82   public String getDisplayName() {
83     return displayName;
84   }
85
86 }