blob: 7833c27e191e91c47d1eceebcdcc50efdb66d297 [file] [log] [blame]
CNlucius74fd4942015-07-20 14:28:04 +08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
CNlucius74fd4942015-07-20 14:28:04 +08003 *
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 */
16package org.onosproject.ovsdb.controller;
17
18import static com.google.common.base.MoreObjects.toStringHelper;
19import static com.google.common.base.Preconditions.checkNotNull;
20
21import java.util.Objects;
22
23/**
24 * The class representing a ovsdb port. This class is immutable.
25 */
26public final class OvsdbPort {
27
28 private final OvsdbPortNumber portNumber;
29 private final OvsdbPortName portName;
30
31 /**
BitOhenryb8878132015-10-29 17:46:46 +080032 * Constructor from OvsdbPortNumber portNumber, OvsdbPortName portName.
CNlucius74fd4942015-07-20 14:28:04 +080033 *
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 /**
BitOhenryb8878132015-10-29 17:46:46 +080045 * Gets the port number of port.
CNlucius74fd4942015-07-20 14:28:04 +080046 *
BitOhenryb8878132015-10-29 17:46:46 +080047 * @return the port number of port
CNlucius74fd4942015-07-20 14:28:04 +080048 */
49 public OvsdbPortNumber portNumber() {
50 return portNumber;
51 }
52
53 /**
BitOhenryb8878132015-10-29 17:46:46 +080054 * Gets the port name of port.
CNlucius74fd4942015-07-20 14:28:04 +080055 *
BitOhenryb8878132015-10-29 17:46:46 +080056 * @return the port name of port
CNlucius74fd4942015-07-20 14:28:04 +080057 */
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}