blob: f6de3fe91a78d94e5eb95306a1e2c29e3b39d28b [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 */
tombe988312014-09-19 18:38:47 -070016package org.onlab.onos.net.topology;
tom2d331412014-09-10 21:31:20 -070017
18import org.onlab.onos.net.Link;
tom2d331412014-09-10 21:31:20 -070019
20import java.util.Objects;
21
22import static com.google.common.base.MoreObjects.toStringHelper;
23
24/**
25 * Implementation of the topology edge backed by a link.
26 */
tombe988312014-09-19 18:38:47 -070027public class DefaultTopologyEdge implements TopologyEdge {
tom2d331412014-09-10 21:31:20 -070028
29 private final Link link;
tom97937552014-09-11 10:48:42 -070030 private final TopologyVertex src;
31 private final TopologyVertex dst;
tom2d331412014-09-10 21:31:20 -070032
33 /**
34 * Creates a new topology edge.
35 *
36 * @param src source vertex
37 * @param dst destination vertex
38 * @param link infrastructure link
39 */
tombe988312014-09-19 18:38:47 -070040 public DefaultTopologyEdge(TopologyVertex src, TopologyVertex dst, Link link) {
tom2d331412014-09-10 21:31:20 -070041 this.src = src;
42 this.dst = dst;
43 this.link = link;
44 }
45
46 @Override
47 public Link link() {
48 return link;
49 }
50
51 @Override
tom97937552014-09-11 10:48:42 -070052 public TopologyVertex src() {
tom2d331412014-09-10 21:31:20 -070053 return src;
54 }
55
56 @Override
tom97937552014-09-11 10:48:42 -070057 public TopologyVertex dst() {
tom2d331412014-09-10 21:31:20 -070058 return dst;
59 }
60
61 @Override
62 public int hashCode() {
63 return Objects.hash(link);
64 }
65
66 @Override
67 public boolean equals(Object obj) {
tomfc9a4ff2014-09-22 18:22:47 -070068 if (this == obj) {
69 return true;
70 }
tom97937552014-09-11 10:48:42 -070071 if (obj instanceof DefaultTopologyEdge) {
72 final DefaultTopologyEdge other = (DefaultTopologyEdge) obj;
tom2d331412014-09-10 21:31:20 -070073 return Objects.equals(this.link, other.link);
74 }
75 return false;
76 }
77
78 @Override
79 public String toString() {
80 return toStringHelper(this).add("src", src).add("dst", dst).toString();
81 }
82
83}
84