Support for Test Topology Auto Design- Service Import
[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
20 /**
21  * Resource Type Enum
22  *
23  * @author mshitrit
24  */
25 public enum ResourceTypeEnum {
26
27     VFC("VFC"/* (Virtual Function Component)"*/, true),
28     VF("VF"/* (Virtual Function)" */, false),
29     CR("CR"/* (Complex Resource"*/, false),
30     CP("CP"/* (Connection Point)"*/, true),
31     PNF("PNF"/* (Physical Network Function)" */, false),
32     CVFC("CVFC"/* Complex Virtual Function Component*/, false),
33     VL("VL"/* (Virtual Link)"*/, true),
34     VFCMT("VFCMT"/* (VFC Monitoring Template)"*/, true),
35     Configuration("Configuration", true),
36     ServiceProxy("ServiceProxy", true),
37     //Generic VFC/VF/PNF/Service Type
38     ABSTRACT("Abstract", true),
39         SERVICE("Service"/*(Network Service)"*/,false);
40
41     private final String value;
42     private final boolean isAtomicType;
43
44     ResourceTypeEnum(final String value, final boolean isAtomicType) {
45         this.value = value;
46         this.isAtomicType = isAtomicType;
47     }
48
49     public String getValue() {
50         return value;
51     }
52
53     public boolean isAtomicType() {
54         return isAtomicType;
55     }
56
57     public static ResourceTypeEnum getType(final String type) {
58         if (type == null) {
59             return null;
60         }
61         return Arrays.stream(ResourceTypeEnum.values())
62             .filter(resourceTypeEnum -> resourceTypeEnum.name().equals(type))
63             .findFirst()
64             .orElse(null);
65     }
66
67     public static ResourceTypeEnum getTypeByName(final String type) {
68         if (type == null) {
69             return null;
70         }
71         return Arrays.stream(ResourceTypeEnum.values())
72             .filter(resourceTypeEnum -> resourceTypeEnum.name().equalsIgnoreCase(type))
73             .findFirst()
74             .orElse(null);
75     }
76
77     /**
78      * Returns ResourceTypeEnum matching to received String ignore case
79      *
80      * @param type the resource type
81      * @return the resource type as a enum if found, {@code null} otherwise
82      */
83     public static ResourceTypeEnum getTypeIgnoreCase(final String type) {
84         if (type == null) {
85             return null;
86         }
87         return Arrays.stream(ResourceTypeEnum.values())
88             .filter(resourceTypeEnum -> resourceTypeEnum.name().equalsIgnoreCase(type))
89             .findFirst()
90             .orElse(null);
91     }
92
93     /**
94      * Checks if enum exist with given type
95      *
96      * @param type the resource type
97      * @return {@code true} if the given resource type exists, {@code false} otherwise
98      */
99     public static boolean containsName(final String type) {
100         if (type == null) {
101             return false;
102         }
103         return Arrays.stream(ResourceTypeEnum.values())
104             .anyMatch(resourceTypeEnum -> resourceTypeEnum.name().equals(type));
105     }
106
107     /**
108      * Checks if enum exist with given type ignore case
109      *
110      * @param type the resource type
111      * @return {@code true} if the type exists, {@code false} otherwise
112      */
113     public static boolean containsIgnoreCase(final String type) {
114         if (type == null) {
115             return false;
116         }
117         return Arrays.stream(ResourceTypeEnum.values())
118             .anyMatch(resourceTypeEnum -> resourceTypeEnum.name().equalsIgnoreCase(type));
119     }
120
121 }