blob: 99d700e128d416cfa3c6dc198bbe06f6879a8585 [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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.topology;
tom2d331412014-09-10 21:31:20 -070017
Brian O'Connorabafb502014-12-02 22:26:20 -080018import org.onosproject.net.Link;
tom2d331412014-09-10 21:31:20 -070019
20import java.util.Objects;
21
22import static com.google.common.base.MoreObjects.toStringHelper;
HIGUCHI Yutaca9cc8e2015-10-29 23:26:51 -070023import static com.google.common.base.Preconditions.checkNotNull;
tom2d331412014-09-10 21:31:20 -070024
25/**
26 * Implementation of the topology edge backed by a link.
27 */
tombe988312014-09-19 18:38:47 -070028public class DefaultTopologyEdge implements TopologyEdge {
tom2d331412014-09-10 21:31:20 -070029
30 private final Link link;
tom97937552014-09-11 10:48:42 -070031 private final TopologyVertex src;
32 private final TopologyVertex dst;
tom2d331412014-09-10 21:31:20 -070033
34 /**
35 * Creates a new topology edge.
36 *
37 * @param src source vertex
38 * @param dst destination vertex
39 * @param link infrastructure link
40 */
tombe988312014-09-19 18:38:47 -070041 public DefaultTopologyEdge(TopologyVertex src, TopologyVertex dst, Link link) {
tom2d331412014-09-10 21:31:20 -070042 this.src = src;
43 this.dst = dst;
HIGUCHI Yutaca9cc8e2015-10-29 23:26:51 -070044 this.link = checkNotNull(link);
tom2d331412014-09-10 21:31:20 -070045 }
46
47 @Override
48 public Link link() {
49 return link;
50 }
51
52 @Override
tom97937552014-09-11 10:48:42 -070053 public TopologyVertex src() {
tom2d331412014-09-10 21:31:20 -070054 return src;
55 }
56
57 @Override
tom97937552014-09-11 10:48:42 -070058 public TopologyVertex dst() {
tom2d331412014-09-10 21:31:20 -070059 return dst;
60 }
61
62 @Override
63 public int hashCode() {
HIGUCHI Yutaca9cc8e2015-10-29 23:26:51 -070064 return link.hashCode();
tom2d331412014-09-10 21:31:20 -070065 }
66
67 @Override
68 public boolean equals(Object obj) {
tomfc9a4ff2014-09-22 18:22:47 -070069 if (this == obj) {
70 return true;
71 }
tom97937552014-09-11 10:48:42 -070072 if (obj instanceof DefaultTopologyEdge) {
73 final DefaultTopologyEdge other = (DefaultTopologyEdge) obj;
tom2d331412014-09-10 21:31:20 -070074 return Objects.equals(this.link, other.link);
75 }
76 return false;
77 }
78
79 @Override
80 public String toString() {
81 return toStringHelper(this).add("src", src).add("dst", dst).toString();
82 }
83
84}
85