blob: 190a39281b2893aa00f205975d6b71bf69bd1590 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
tomcfde0622014-09-09 11:02:42 -070016package org.onlab.onos.net.topology;
17
18import org.onlab.onos.net.DeviceId;
19
20import java.util.Objects;
21
22import static com.google.common.base.MoreObjects.toStringHelper;
23
24/**
25 * Default implementation of a network topology cluster.
26 */
27public class DefaultTopologyCluster implements TopologyCluster {
28
29 private final ClusterId id;
30 private final int deviceCount;
31 private final int linkCount;
32 private final DeviceId root;
33
34 /**
35 * Creates a new topology cluster descriptor with the specified attributes.
36 *
37 * @param id cluster id
38 * @param deviceCount number of devices in the cluster
39 * @param linkCount number of links in the cluster
40 * @param root cluster root node
41 */
42 public DefaultTopologyCluster(ClusterId id, int deviceCount, int linkCount,
43 DeviceId root) {
44 this.id = id;
45 this.deviceCount = deviceCount;
46 this.linkCount = linkCount;
47 this.root = root;
48 }
49
50 @Override
51 public ClusterId id() {
52 return id;
53 }
54
55 @Override
56 public int deviceCount() {
57 return deviceCount;
58 }
59
60 @Override
61 public int linkCount() {
62 return linkCount;
63 }
64
65 @Override
66 public DeviceId root() {
67 return root;
68 }
69
70 @Override
71 public int hashCode() {
72 return Objects.hash(id, deviceCount, linkCount, root);
73 }
74
75 @Override
76 public boolean equals(Object obj) {
tomfc9a4ff2014-09-22 18:22:47 -070077 if (this == obj) {
78 return true;
79 }
tomcfde0622014-09-09 11:02:42 -070080 if (obj instanceof DefaultTopologyCluster) {
81 final DefaultTopologyCluster other = (DefaultTopologyCluster) obj;
82 return Objects.equals(this.id, other.id) &&
83 Objects.equals(this.deviceCount, other.deviceCount) &&
84 Objects.equals(this.linkCount, other.linkCount) &&
85 Objects.equals(this.root, other.root);
86 }
87 return false;
88 }
89
90 @Override
91 public String toString() {
92 return toStringHelper(this)
93 .add("id", id)
94 .add("deviceCount", deviceCount)
95 .add("linkCount", linkCount)
96 .add("root", root)
97 .toString();
98 }
99}