8f4446bb434531d225dfbe9a832ccc78b0b3ce73
[ccsdk/features.git] /
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
51     public int getIndex() {
52         return Index;
53     }
54
55     @Override
56     public int hashCode() {
57         final int prime = 31;
58         int result = 1;
59         result = prime * result + Index;
60         result = prime * result + (Role == null ? 0 : Role.hashCode());
61         return result;
62     }
63
64     @Override
65     public boolean equals(Object obj) {
66         if (this == obj) {
67             return true;
68         }
69         if (obj == null) {
70             return false;
71         }
72         if (getClass() != obj.getClass()) {
73             return false;
74         }
75         ClusterRoleInfo other = (ClusterRoleInfo) obj;
76         if (Index != other.Index) {
77             return false;
78         }
79         if (Role == null) {
80             if (other.Role != null) {
81                 return false;
82             }
83         } else if (!Role.equals(other.Role)) {
84             return false;
85         }
86         return true;
87     }
88
89     @Override
90     public String toString() {
91         return "ClusterRoleInfo [Role=" + Role + ", Index=" + Index + "]";
92     }
93 }