Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
| 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'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.link; |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 17 | |
alshabib | dfc7afb | 2014-10-21 20:13:27 -0700 | [diff] [blame] | 18 | import com.google.common.base.MoreObjects; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 19 | import org.onosproject.net.AbstractDescription; |
| 20 | import org.onosproject.net.ConnectPoint; |
| 21 | import org.onosproject.net.Link; |
| 22 | import org.onosproject.net.SparseAnnotations; |
HIGUCHI Yuta | 703a5af | 2015-11-18 23:43:50 -0800 | [diff] [blame] | 23 | import com.google.common.base.Objects; |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 24 | |
| 25 | /** |
| 26 | * Default implementation of immutable link description entity. |
| 27 | */ |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 28 | public class DefaultLinkDescription extends AbstractDescription |
| 29 | implements LinkDescription { |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 30 | |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 31 | private final ConnectPoint src; |
| 32 | private final ConnectPoint dst; |
| 33 | private final Link.Type type; |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * Creates a link description using the supplied information. |
| 37 | * |
Thomas Vachuska | 57126fe | 2014-11-11 17:13:24 -0800 | [diff] [blame] | 38 | * @param src link source |
| 39 | * @param dst link destination |
| 40 | * @param type link type |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 41 | * @param annotations optional key/value annotations |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 42 | */ |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 43 | public DefaultLinkDescription(ConnectPoint src, ConnectPoint dst, |
| 44 | Link.Type type, SparseAnnotations... annotations) { |
| 45 | super(annotations); |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 46 | this.src = src; |
| 47 | this.dst = dst; |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 48 | this.type = type; |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public ConnectPoint src() { |
| 53 | return src; |
| 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public ConnectPoint dst() { |
| 58 | return dst; |
| 59 | } |
| 60 | |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 61 | @Override |
| 62 | public Link.Type type() { |
tom | d176fc4 | 2014-09-08 00:12:30 -0700 | [diff] [blame] | 63 | return type; |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 64 | } |
| 65 | |
alshabib | dfc7afb | 2014-10-21 20:13:27 -0700 | [diff] [blame] | 66 | @Override |
| 67 | public String toString() { |
Thomas Vachuska | 57126fe | 2014-11-11 17:13:24 -0800 | [diff] [blame] | 68 | return MoreObjects.toStringHelper(this) |
| 69 | .add("src", src()) |
| 70 | .add("dst", dst()) |
| 71 | .add("type", type()).toString(); |
alshabib | dfc7afb | 2014-10-21 20:13:27 -0700 | [diff] [blame] | 72 | } |
| 73 | |
HIGUCHI Yuta | 703a5af | 2015-11-18 23:43:50 -0800 | [diff] [blame] | 74 | @Override |
| 75 | public int hashCode() { |
| 76 | return Objects.hashCode(super.hashCode(), src, dst, type); |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public boolean equals(Object object) { |
| 81 | if (object != null && getClass() == object.getClass()) { |
| 82 | if (!super.equals(object)) { |
| 83 | return false; |
| 84 | } |
| 85 | DefaultLinkDescription that = (DefaultLinkDescription) object; |
| 86 | return Objects.equal(this.src, that.src) |
| 87 | && Objects.equal(this.dst, that.dst) |
| 88 | && Objects.equal(this.type, that.type); |
| 89 | } |
| 90 | return false; |
| 91 | } |
| 92 | |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 93 | } |