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 | */ |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 16 | package org.onlab.onos.net; |
| 17 | |
Jonathan Hart | b79d641 | 2014-09-19 11:24:06 -0700 | [diff] [blame] | 18 | import java.util.Objects; |
Yuta HIGUCHI | 9827a35 | 2014-09-21 17:01:29 -0700 | [diff] [blame] | 19 | |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 20 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 21 | |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 22 | /** |
| 23 | * Default port implementation. |
| 24 | */ |
tom | 3ea1125 | 2014-10-02 04:32:26 -0700 | [diff] [blame] | 25 | public class DefaultPort extends AbstractAnnotated implements Port { |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 26 | |
| 27 | private final Element element; |
| 28 | private final PortNumber number; |
| 29 | private final boolean isEnabled; |
| 30 | |
Jonathan Hart | b79d641 | 2014-09-19 11:24:06 -0700 | [diff] [blame] | 31 | /** |
| 32 | * Creates a network element attributed to the specified provider. |
| 33 | * |
| 34 | * @param element parent network element |
| 35 | * @param number port number |
| 36 | * @param isEnabled indicator whether the port is up and active |
tom | 3ea1125 | 2014-10-02 04:32:26 -0700 | [diff] [blame] | 37 | * @param annotations optional key/value annotations |
Jonathan Hart | b79d641 | 2014-09-19 11:24:06 -0700 | [diff] [blame] | 38 | */ |
| 39 | public DefaultPort(Element element, PortNumber number, |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 40 | boolean isEnabled, Annotations... annotations) { |
tom | 3ea1125 | 2014-10-02 04:32:26 -0700 | [diff] [blame] | 41 | super(annotations); |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 42 | this.element = element; |
| 43 | this.number = number; |
| 44 | this.isEnabled = isEnabled; |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public int hashCode() { |
| 49 | return Objects.hash(number, isEnabled); |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public boolean equals(Object obj) { |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 54 | if (this == obj) { |
| 55 | return true; |
| 56 | } |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 57 | if (obj instanceof DefaultPort) { |
| 58 | final DefaultPort other = (DefaultPort) obj; |
| 59 | return Objects.equals(this.element.id(), other.element.id()) && |
| 60 | Objects.equals(this.number, other.number) && |
| 61 | Objects.equals(this.isEnabled, other.isEnabled); |
| 62 | } |
| 63 | return false; |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public String toString() { |
| 68 | return toStringHelper(this) |
| 69 | .add("element", element.id()) |
| 70 | .add("number", number) |
| 71 | .add("isEnabled", isEnabled) |
| 72 | .toString(); |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public PortNumber number() { |
| 77 | return number; |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public boolean isEnabled() { |
| 82 | return isEnabled; |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public Element element() { |
| 87 | return element; |
| 88 | } |
| 89 | |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 90 | } |