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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
16 * ============LICENSE_END==========================================================================
17 ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.conf.odlGeo;
20 import java.util.regex.Matcher;
21 import java.util.regex.Pattern;
23 public class ClusterRoleInfo {
24 private final String Role;
25 private final int Index;
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);
34 this.Role = matcher.group(1);
35 this.Index = Integer.parseInt(matcher.group(2));
38 private ClusterRoleInfo(String role, int idx) {
43 public static ClusterRoleInfo defaultSingleNodeRole() {
44 return new ClusterRoleInfo("member",1);
47 public String getRole() {
50 public int getIndex() {
55 public int hashCode() {
58 result = prime * result + Index;
59 result = prime * result + (Role == null ? 0 : Role.hashCode());
64 public boolean equals(Object obj) {
71 if (getClass() != obj.getClass()) {
74 ClusterRoleInfo other = (ClusterRoleInfo) obj;
75 if (Index != other.Index) {
79 if (other.Role != null) {
82 } else if (!Role.equals(other.Role)) {
88 public String toString() {
89 return "ClusterRoleInfo [Role=" + Role + ", Index=" + Index + "]";