CNlucius | 74fd494 | 2015-07-20 14:28:04 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | */ |
| 16 | package org.onosproject.ovsdb.controller; |
| 17 | |
| 18 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 19 | import static com.google.common.base.Preconditions.checkNotNull; |
| 20 | |
| 21 | import java.util.Objects; |
| 22 | |
| 23 | /** |
| 24 | * The class representing a ovsdb port. This class is immutable. |
| 25 | */ |
| 26 | public final class OvsdbPort { |
| 27 | |
| 28 | private final OvsdbPortNumber portNumber; |
| 29 | private final OvsdbPortName portName; |
| 30 | |
| 31 | /** |
BitOhenry | b887813 | 2015-10-29 17:46:46 +0800 | [diff] [blame] | 32 | * Constructor from OvsdbPortNumber portNumber, OvsdbPortName portName. |
CNlucius | 74fd494 | 2015-07-20 14:28:04 +0800 | [diff] [blame] | 33 | * |
| 34 | * @param portNumber the portNumber to use |
| 35 | * @param portName the portName to use |
| 36 | */ |
| 37 | public OvsdbPort(OvsdbPortNumber portNumber, OvsdbPortName portName) { |
| 38 | checkNotNull(portNumber, "portNumber is not null"); |
| 39 | checkNotNull(portName, "portName is not null"); |
| 40 | this.portNumber = portNumber; |
| 41 | this.portName = portName; |
| 42 | } |
| 43 | |
| 44 | /** |
BitOhenry | b887813 | 2015-10-29 17:46:46 +0800 | [diff] [blame] | 45 | * Gets the port number of port. |
CNlucius | 74fd494 | 2015-07-20 14:28:04 +0800 | [diff] [blame] | 46 | * |
BitOhenry | b887813 | 2015-10-29 17:46:46 +0800 | [diff] [blame] | 47 | * @return the port number of port |
CNlucius | 74fd494 | 2015-07-20 14:28:04 +0800 | [diff] [blame] | 48 | */ |
| 49 | public OvsdbPortNumber portNumber() { |
| 50 | return portNumber; |
| 51 | } |
| 52 | |
| 53 | /** |
BitOhenry | b887813 | 2015-10-29 17:46:46 +0800 | [diff] [blame] | 54 | * Gets the port name of port. |
CNlucius | 74fd494 | 2015-07-20 14:28:04 +0800 | [diff] [blame] | 55 | * |
BitOhenry | b887813 | 2015-10-29 17:46:46 +0800 | [diff] [blame] | 56 | * @return the port name of port |
CNlucius | 74fd494 | 2015-07-20 14:28:04 +0800 | [diff] [blame] | 57 | */ |
| 58 | public OvsdbPortName portName() { |
| 59 | return portName; |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public int hashCode() { |
| 64 | return Objects.hash(portNumber, portName); |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public boolean equals(Object obj) { |
| 69 | if (this == obj) { |
| 70 | return true; |
| 71 | } |
| 72 | if (obj instanceof OvsdbPort) { |
| 73 | final OvsdbPort otherOvsdbPort = (OvsdbPort) obj; |
| 74 | return Objects.equals(this.portNumber, otherOvsdbPort.portNumber) |
| 75 | && Objects.equals(this.portName, otherOvsdbPort.portName); |
| 76 | } |
| 77 | return false; |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public String toString() { |
| 82 | return toStringHelper(this) |
| 83 | .add("portNumber", String.valueOf(portNumber.value())) |
| 84 | .add("portName", portName.value()).toString(); |
| 85 | } |
| 86 | } |