Removing blueprints-processor
[ccsdk/features.git] / sdnr / wt / netconfnode-state-service / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / netconfnodestateservice / impl / conf / odlGeo / ClusterRoleInfo.java
1 /*******************************************************************************
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.conf.odlGeo;
19
20 import java.util.regex.Matcher;
21 import java.util.regex.Pattern;
22
23 public class ClusterRoleInfo {
24     private final String Role;
25     private final int Index;
26
27     public ClusterRoleInfo(String s) throws Exception {
28         final String regex = "([a-zA-Z]*)-([0-9]*)";
29         final Pattern pattern = Pattern.compile(regex);
30         final Matcher matcher = pattern.matcher(s);
31         if (!matcher.find()) {
32             throw new Exception("unexpected role format:"+s);
33         }
34         this.Role = matcher.group(1);
35         this.Index = Integer.parseInt(matcher.group(2));
36     }
37
38     private ClusterRoleInfo(String role, int idx) {
39         this.Role=role;
40         this.Index=idx;
41     }
42
43     public static ClusterRoleInfo defaultSingleNodeRole() {
44         return new ClusterRoleInfo("member",1);
45     }
46
47     public String getRole() {
48         return Role;
49     }
50     public int getIndex() {
51         return Index;
52     }
53
54     @Override
55     public int hashCode() {
56         final int prime = 31;
57         int result = 1;
58         result = prime * result + Index;
59         result = prime * result + (Role == null ? 0 : Role.hashCode());
60         return result;
61     }
62
63     @Override
64     public boolean equals(Object obj) {
65         if (this == obj) {
66             return true;
67         }
68         if (obj == null) {
69             return false;
70         }
71         if (getClass() != obj.getClass()) {
72             return false;
73         }
74         ClusterRoleInfo other = (ClusterRoleInfo) obj;
75         if (Index != other.Index) {
76             return false;
77         }
78         if (Role == null) {
79             if (other.Role != null) {
80                 return false;
81             }
82         } else if (!Role.equals(other.Role)) {
83             return false;
84         }
85         return true;
86     }
87     @Override
88     public String toString() {
89         return "ClusterRoleInfo [Role=" + Role + ", Index=" + Index + "]";
90     }
91 }