blob: b6cc9bd0e6285ca22a2202747a2cb18d52ea5663 [file] [log] [blame]
tomcfde0622014-09-09 11:02:42 -07001package org.onlab.onos.net.topology;
2
3import org.onlab.onos.net.DeviceId;
4
5import java.util.Objects;
6
7import static com.google.common.base.MoreObjects.toStringHelper;
8
9/**
10 * Default implementation of a network topology cluster.
11 */
12public class DefaultTopologyCluster implements TopologyCluster {
13
14 private final ClusterId id;
15 private final int deviceCount;
16 private final int linkCount;
17 private final DeviceId root;
18
19 /**
20 * Creates a new topology cluster descriptor with the specified attributes.
21 *
22 * @param id cluster id
23 * @param deviceCount number of devices in the cluster
24 * @param linkCount number of links in the cluster
25 * @param root cluster root node
26 */
27 public DefaultTopologyCluster(ClusterId id, int deviceCount, int linkCount,
28 DeviceId root) {
29 this.id = id;
30 this.deviceCount = deviceCount;
31 this.linkCount = linkCount;
32 this.root = root;
33 }
34
35 @Override
36 public ClusterId id() {
37 return id;
38 }
39
40 @Override
41 public int deviceCount() {
42 return deviceCount;
43 }
44
45 @Override
46 public int linkCount() {
47 return linkCount;
48 }
49
50 @Override
51 public DeviceId root() {
52 return root;
53 }
54
55 @Override
56 public int hashCode() {
57 return Objects.hash(id, deviceCount, linkCount, root);
58 }
59
60 @Override
61 public boolean equals(Object obj) {
tomfc9a4ff2014-09-22 18:22:47 -070062 if (this == obj) {
63 return true;
64 }
tomcfde0622014-09-09 11:02:42 -070065 if (obj instanceof DefaultTopologyCluster) {
66 final DefaultTopologyCluster other = (DefaultTopologyCluster) obj;
67 return Objects.equals(this.id, other.id) &&
68 Objects.equals(this.deviceCount, other.deviceCount) &&
69 Objects.equals(this.linkCount, other.linkCount) &&
70 Objects.equals(this.root, other.root);
71 }
72 return false;
73 }
74
75 @Override
76 public String toString() {
77 return toStringHelper(this)
78 .add("id", id)
79 .add("deviceCount", deviceCount)
80 .add("linkCount", linkCount)
81 .add("root", root)
82 .toString();
83 }
84}