Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
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 | 2d33141 | 2014-09-10 21:31:20 -0700 | [diff] [blame] | 17 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 18 | import org.onosproject.net.Link; |
tom | 2d33141 | 2014-09-10 21:31:20 -0700 | [diff] [blame] | 19 | |
| 20 | import java.util.Objects; |
| 21 | |
| 22 | import static com.google.common.base.MoreObjects.toStringHelper; |
HIGUCHI Yuta | ca9cc8e | 2015-10-29 23:26:51 -0700 | [diff] [blame] | 23 | import static com.google.common.base.Preconditions.checkNotNull; |
tom | 2d33141 | 2014-09-10 21:31:20 -0700 | [diff] [blame] | 24 | |
| 25 | /** |
| 26 | * Implementation of the topology edge backed by a link. |
| 27 | */ |
tom | be98831 | 2014-09-19 18:38:47 -0700 | [diff] [blame] | 28 | public class DefaultTopologyEdge implements TopologyEdge { |
tom | 2d33141 | 2014-09-10 21:31:20 -0700 | [diff] [blame] | 29 | |
| 30 | private final Link link; |
tom | 9793755 | 2014-09-11 10:48:42 -0700 | [diff] [blame] | 31 | private final TopologyVertex src; |
| 32 | private final TopologyVertex dst; |
tom | 2d33141 | 2014-09-10 21:31:20 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
| 35 | * Creates a new topology edge. |
| 36 | * |
| 37 | * @param src source vertex |
| 38 | * @param dst destination vertex |
| 39 | * @param link infrastructure link |
| 40 | */ |
tom | be98831 | 2014-09-19 18:38:47 -0700 | [diff] [blame] | 41 | public DefaultTopologyEdge(TopologyVertex src, TopologyVertex dst, Link link) { |
tom | 2d33141 | 2014-09-10 21:31:20 -0700 | [diff] [blame] | 42 | this.src = src; |
| 43 | this.dst = dst; |
HIGUCHI Yuta | ca9cc8e | 2015-10-29 23:26:51 -0700 | [diff] [blame] | 44 | this.link = checkNotNull(link); |
tom | 2d33141 | 2014-09-10 21:31:20 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public Link link() { |
| 49 | return link; |
| 50 | } |
| 51 | |
| 52 | @Override |
tom | 9793755 | 2014-09-11 10:48:42 -0700 | [diff] [blame] | 53 | public TopologyVertex src() { |
tom | 2d33141 | 2014-09-10 21:31:20 -0700 | [diff] [blame] | 54 | return src; |
| 55 | } |
| 56 | |
| 57 | @Override |
tom | 9793755 | 2014-09-11 10:48:42 -0700 | [diff] [blame] | 58 | public TopologyVertex dst() { |
tom | 2d33141 | 2014-09-10 21:31:20 -0700 | [diff] [blame] | 59 | return dst; |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public int hashCode() { |
HIGUCHI Yuta | ca9cc8e | 2015-10-29 23:26:51 -0700 | [diff] [blame] | 64 | return link.hashCode(); |
tom | 2d33141 | 2014-09-10 21:31:20 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public boolean equals(Object obj) { |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 69 | if (this == obj) { |
| 70 | return true; |
| 71 | } |
tom | 9793755 | 2014-09-11 10:48:42 -0700 | [diff] [blame] | 72 | if (obj instanceof DefaultTopologyEdge) { |
| 73 | final DefaultTopologyEdge other = (DefaultTopologyEdge) obj; |
tom | 2d33141 | 2014-09-10 21:31:20 -0700 | [diff] [blame] | 74 | 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 | |