blob: 2430d5261bffc651c7a9a6508bb9019450585839 [file] [log] [blame]
tom73d6d1e2014-09-17 20:08:01 -07001package org.onlab.onos.cluster;
2
tomfc9a4ff2014-09-22 18:22:47 -07003import java.util.Objects;
4
tom73d6d1e2014-09-17 20:08:01 -07005/**
6 * Controller cluster identity.
7 */
tome4729872014-09-23 00:37:37 -07008public class NodeId {
tomfc9a4ff2014-09-22 18:22:47 -07009
10 private final String id;
11
12 // Default constructor for serialization
tome4729872014-09-23 00:37:37 -070013 protected NodeId() {
tomfc9a4ff2014-09-22 18:22:47 -070014 id = null;
15 }
16
17 /**
tome4729872014-09-23 00:37:37 -070018 * Creates a new cluster node identifier from the specified string.
tomfc9a4ff2014-09-22 18:22:47 -070019 *
20 * @param id string identifier
21 */
tome4729872014-09-23 00:37:37 -070022 public NodeId(String id) {
tomfc9a4ff2014-09-22 18:22:47 -070023 this.id = id;
24 }
25
26 @Override
27 public int hashCode() {
28 return Objects.hash(id);
29 }
30
31 @Override
32 public boolean equals(Object obj) {
33 if (this == obj) {
34 return true;
35 }
tome4729872014-09-23 00:37:37 -070036 if (obj instanceof NodeId) {
37 final NodeId other = (NodeId) obj;
tomfc9a4ff2014-09-22 18:22:47 -070038 return Objects.equals(this.id, other.id);
39 }
40 return false;
41 }
42
43 @Override
44 public String toString() {
tome4729872014-09-23 00:37:37 -070045 return id;
tomfc9a4ff2014-09-22 18:22:47 -070046 }
47
tom73d6d1e2014-09-17 20:08:01 -070048}