[MSO-8] Update the maven dependency
[so.git] / adapters / mso-adapter-utils / src / main / java / org / openecomp / mso / cloud / IdentityServerTypeAbstract.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * OPENECOMP - MSO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.openecomp.mso.cloud;
21
22 import java.util.Map;
23 import java.util.concurrent.ConcurrentHashMap;
24
25 import org.openecomp.mso.openstack.utils.MsoTenantUtils;
26
27
28 public abstract class IdentityServerTypeAbstract {
29
30         // This map will prevent duplicates (as if it was an Enum).
31         // Without this, using an instance specific field for the class could allow
32         // different classes bound to the same entry name.
33         private static final Map<String, IdentityServerTypeAbstract> entries = new ConcurrentHashMap<>();
34
35         private String serverType;
36
37         private Class<? extends MsoTenantUtils> utilsClass;
38
39         protected IdentityServerTypeAbstract(String serverType, Class<? extends MsoTenantUtils> utilsClass) {
40                 if ((serverType == null) || (serverType.isEmpty())) {
41                         throw new IllegalArgumentException("Server Type name cannot be null or empty, provided value was " + serverType);
42                 }
43                 if (entries.containsKey(serverType)) {
44                         throw new IllegalArgumentException("Duplicate Server Type entry for registration: " + serverType);
45                 }
46                 this.serverType = serverType;
47                 this.utilsClass = utilsClass;
48                 entries.put(serverType, this);
49         }
50
51         public static final IdentityServerTypeAbstract valueOf(String serverType) {
52                 return entries.get(serverType);
53         }
54
55         @Override
56         public final String toString() {
57                 return this.serverType;
58         }
59
60         public final String name() {
61                 return this.serverType;
62         }
63
64         public static final IdentityServerTypeAbstract[] values() {
65                 return (IdentityServerTypeAbstract[]) entries.values().stream().toArray(IdentityServerTypeAbstract[]::new);
66         }
67
68         public final Class<? extends MsoTenantUtils> getMsoTenantUtilsClass() {
69                 return this.utilsClass;
70         }
71
72         @Override
73         public final boolean equals(Object other) {
74                 return ((this.serverType != null) && (other != null) && (other instanceof IdentityServerTypeAbstract) && (this.serverType.equals(other.toString())));
75         }
76
77 }