Improve test coverage
[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
16 package org.openecomp.sdc.be.datatypes.enums;
17
18 import java.util.Arrays;
19 import lombok.AllArgsConstructor;
20 import lombok.Getter;
21
22 /**
23  * Resource Type Enum
24  *
25  * @author mshitrit
26  */
27 @Getter
28 @AllArgsConstructor
29 public enum ResourceTypeEnum {
30
31     VFC("VFC"/* (Virtual Function Component)"*/, true),
32     VF("VF"/* (Virtual Function)" */, false),
33     CR("CR"/* (Complex Resource"*/, false),
34     CP("CP"/* (Connection Point)"*/, true),
35     PNF("PNF"/* (Physical Network Function)" */, false),
36     CVFC("CVFC"/* Complex Virtual Function Component*/, false),
37     VL("VL"/* (Virtual Link)"*/, true),
38     VFCMT("VFCMT"/* (VFC Monitoring Template)"*/, true),
39     Configuration("Configuration", true),
40     ServiceProxy("ServiceProxy", true),
41     //Generic VFC/VF/PNF/Service Type
42     ABSTRACT("Abstract", true),
43     SERVICE("Service"/*(Network Service)"*/, false);
44
45     private final String value;
46     private final boolean isAtomicType;
47
48     public static ResourceTypeEnum getType(final String type) {
49         if (type == null) {
50             return null;
51         }
52         return Arrays.stream(ResourceTypeEnum.values())
53             .filter(resourceTypeEnum -> resourceTypeEnum.name().equals(type))
54             .findFirst()
55             .orElse(null);
56     }
57
58     public static ResourceTypeEnum getTypeByName(final String type) {
59         if (type == null) {
60             return null;
61         }
62         return Arrays.stream(ResourceTypeEnum.values())
63             .filter(resourceTypeEnum -> resourceTypeEnum.name().equalsIgnoreCase(type))
64             .findFirst()
65             .orElse(null);
66     }
67
68     /**
69      * Returns ResourceTypeEnum matching to received String ignore case
70      *
71      * @param type the resource type
72      * @return the resource type as a enum if found, {@code null} otherwise
73      */
74     public static ResourceTypeEnum getTypeIgnoreCase(final String type) {
75         if (type == null) {
76             return null;
77         }
78         return Arrays.stream(ResourceTypeEnum.values())
79             .filter(resourceTypeEnum -> resourceTypeEnum.name().equalsIgnoreCase(type))
80             .findFirst()
81             .orElse(null);
82     }
83
84     /**
85      * Checks if enum exist with given type
86      *
87      * @param type the resource type
88      * @return {@code true} if the given resource type exists, {@code false} otherwise
89      */
90     public static boolean containsName(final String type) {
91         if (type == null) {
92             return false;
93         }
94         return Arrays.stream(ResourceTypeEnum.values())
95             .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())
109             .anyMatch(resourceTypeEnum -> resourceTypeEnum.name().equalsIgnoreCase(type));
110     }
111
112 }