blob: 3b70856fca02f3e92f5ab2ba4983737d14aaa386 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.topology;
tomcfde0622014-09-09 11:02:42 -070017
tomcfde0622014-09-09 11:02:42 -070018import java.util.Objects;
19
20import static com.google.common.base.MoreObjects.toStringHelper;
21
22/**
23 * Default implementation of a network topology cluster.
24 */
25public class DefaultTopologyCluster implements TopologyCluster {
26
27 private final ClusterId id;
28 private final int deviceCount;
29 private final int linkCount;
Thomas Vachuskac31d9f12015-01-22 12:33:27 -080030 private final TopologyVertex root;
tomcfde0622014-09-09 11:02:42 -070031
32 /**
33 * Creates a new topology cluster descriptor with the specified attributes.
34 *
35 * @param id cluster id
36 * @param deviceCount number of devices in the cluster
37 * @param linkCount number of links in the cluster
38 * @param root cluster root node
39 */
40 public DefaultTopologyCluster(ClusterId id, int deviceCount, int linkCount,
Thomas Vachuskac31d9f12015-01-22 12:33:27 -080041 TopologyVertex root) {
tomcfde0622014-09-09 11:02:42 -070042 this.id = id;
43 this.deviceCount = deviceCount;
44 this.linkCount = linkCount;
45 this.root = root;
46 }
47
48 @Override
49 public ClusterId id() {
50 return id;
51 }
52
53 @Override
54 public int deviceCount() {
55 return deviceCount;
56 }
57
58 @Override
59 public int linkCount() {
60 return linkCount;
61 }
62
63 @Override
Thomas Vachuskac31d9f12015-01-22 12:33:27 -080064 public TopologyVertex root() {
tomcfde0622014-09-09 11:02:42 -070065 return root;
66 }
67
68 @Override
69 public int hashCode() {
70 return Objects.hash(id, deviceCount, linkCount, root);
71 }
72
73 @Override
74 public boolean equals(Object obj) {
tomfc9a4ff2014-09-22 18:22:47 -070075 if (this == obj) {
76 return true;
77 }
tomcfde0622014-09-09 11:02:42 -070078 if (obj instanceof DefaultTopologyCluster) {
79 final DefaultTopologyCluster other = (DefaultTopologyCluster) obj;
80 return Objects.equals(this.id, other.id) &&
81 Objects.equals(this.deviceCount, other.deviceCount) &&
82 Objects.equals(this.linkCount, other.linkCount) &&
83 Objects.equals(this.root, other.root);
84 }
85 return false;
86 }
87
88 @Override
89 public String toString() {
90 return toStringHelper(this)
91 .add("id", id)
92 .add("deviceCount", deviceCount)
93 .add("linkCount", linkCount)
94 .add("root", root)
95 .toString();
96 }
97}