Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.topology; |
tom | cfde062 | 2014-09-09 11:02:42 -0700 | [diff] [blame] | 17 | |
tom | cfde062 | 2014-09-09 11:02:42 -0700 | [diff] [blame] | 18 | import java.util.Objects; |
| 19 | |
| 20 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 21 | |
| 22 | /** |
| 23 | * Default implementation of a network topology cluster. |
| 24 | */ |
| 25 | public class DefaultTopologyCluster implements TopologyCluster { |
| 26 | |
| 27 | private final ClusterId id; |
| 28 | private final int deviceCount; |
| 29 | private final int linkCount; |
Thomas Vachuska | c31d9f1 | 2015-01-22 12:33:27 -0800 | [diff] [blame] | 30 | private final TopologyVertex root; |
tom | cfde062 | 2014-09-09 11:02:42 -0700 | [diff] [blame] | 31 | |
| 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 Vachuska | c31d9f1 | 2015-01-22 12:33:27 -0800 | [diff] [blame] | 41 | TopologyVertex root) { |
tom | cfde062 | 2014-09-09 11:02:42 -0700 | [diff] [blame] | 42 | 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 Vachuska | c31d9f1 | 2015-01-22 12:33:27 -0800 | [diff] [blame] | 64 | public TopologyVertex root() { |
tom | cfde062 | 2014-09-09 11:02:42 -0700 | [diff] [blame] | 65 | 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) { |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 75 | if (this == obj) { |
| 76 | return true; |
| 77 | } |
tom | cfde062 | 2014-09-09 11:02:42 -0700 | [diff] [blame] | 78 | 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 | } |