blob: f33dcf7d47eee4e551c51c4b66e5b07fdc63dcd7 [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) {
62 if (obj instanceof DefaultTopologyCluster) {
63 final DefaultTopologyCluster other = (DefaultTopologyCluster) obj;
64 return Objects.equals(this.id, other.id) &&
65 Objects.equals(this.deviceCount, other.deviceCount) &&
66 Objects.equals(this.linkCount, other.linkCount) &&
67 Objects.equals(this.root, other.root);
68 }
69 return false;
70 }
71
72 @Override
73 public String toString() {
74 return toStringHelper(this)
75 .add("id", id)
76 .add("deviceCount", deviceCount)
77 .add("linkCount", linkCount)
78 .add("root", root)
79 .toString();
80 }
81}