Release version 1.13.7
[sdc.git] / common-be / src / main / java / org / openecomp / sdc / be / datatypes / enums / ResourceTypeEnum.java
1 /*-
2  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *      http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 package org.openecomp.sdc.be.datatypes.enums;
16
17 import java.util.Arrays;
18 import lombok.AllArgsConstructor;
19 import lombok.Getter;
20
21 /**
22  * Resource Type Enum
23  *
24  * @author mshitrit
25  */
26 @Getter
27 @AllArgsConstructor
28 public enum ResourceTypeEnum {
29     // @formatter:off
30     VFC("VFC"/* (Virtual Function Component)"*/, true),
31     VF("VF"/* (Virtual Function)" */, false),
32
33     CR("CR"/* (Complex Resource"*/, false),
34     CP("CP"/* (Connection Point)"*/, true),
35
36     PNF("PNF"/* (Physical Network Function)" */, false),
37     CVFC("CVFC"/* Complex Virtual Function Component*/, false),
38
39     VL("VL"/* (Virtual Link)"*/, true),
40     VFCMT("VFCMT"/* (VFC Monitoring Template)"*/, true),
41     Configuration("Configuration", true),
42     ServiceProxy("ServiceProxy", true),
43     //Generic VFC/VF/PNF/Service Type
44     ABSTRACT("Abstract", true),
45     SERVICE("Service"/*(Network Service)"*/, false);
46     // @formatter:on
47
48     private final String value;
49     private final boolean isAtomicType;
50
51     public static ResourceTypeEnum getType(final String type) {
52         if (type == null) {
53             return null;
54         }
55         return Arrays.stream(ResourceTypeEnum.values())
56             .filter(resourceTypeEnum -> resourceTypeEnum.name().equals(type))
57             .findFirst()
58             .orElse(null);
59     }
60
61     public static ResourceTypeEnum getTypeByName(final String type) {
62         if (type == null) {
63             return null;
64         }
65         return Arrays.stream(ResourceTypeEnum.values())
66             .filter(resourceTypeEnum -> resourceTypeEnum.name().equalsIgnoreCase(type))
67             .findFirst()
68             .orElse(null);
69     }
70
71     /**
72      * Returns ResourceTypeEnum matching to received String ignore case
73      *
74      * @param type the resource type
75      * @return the resource type as a enum if found, {@code null} otherwise
76      */
77     public static ResourceTypeEnum getTypeIgnoreCase(final String type) {
78         if (type == null) {
79             return null;
80         }
81         return Arrays.stream(ResourceTypeEnum.values()).filter(resourceTypeEnum -> resourceTypeEnum.name().equalsIgnoreCase(type)).findFirst()
82             .orElse(null);
83     }
84
85     /**
86      * Checks if enum exist with given type
87      *
88      * @param type the resource type
89      * @return {@code true} if the given resource type exists, {@code false} otherwise
90      */
91     public static boolean containsName(final String type) {
92         if (type == null) {
93             return false;
94         }
95         return Arrays.stream(ResourceTypeEnum.values()).anyMatch(resourceTypeEnum -> resourceTypeEnum.name().equals(type));
96     }
97
98     /**
99      * Checks if enum exist with given type ignore case
100      *
101      * @param type the resource type
102      * @return {@code true} if the type exists, {@code false} otherwise
103      */
104     public static boolean containsIgnoreCase(final String type) {
105         if (type == null) {
106             return false;
107         }
108         return Arrays.stream(ResourceTypeEnum.values()).anyMatch(resourceTypeEnum -> resourceTypeEnum.name().equalsIgnoreCase(type));
109     }
110 }