blob: a38634836775d60009fbcac866d56ed273dbef76 [file] [log] [blame]
Sho SHIMIZUb2b2d982015-09-11 15:35:06 -07001/*
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 */
16package org.onosproject.vtnrsc;
17
18import static com.google.common.base.Preconditions.checkNotNull;
19
20import java.util.Objects;
21
22/**
23 * Immutable representation of a virtual port identifier.
24 */
25public final class VirtualPortId {
26 private final String portId;
27 // Public construction is prohibited
28 private VirtualPortId(String virtualPortId) {
29 checkNotNull(virtualPortId, "VirtualPortId cannot be null");
30 this.portId = virtualPortId;
31 }
32
33 public String portId() {
34 return portId;
35 }
36
37 /**
38 * Creates a virtualPort id using the supplied portId.
39 *
40 * @param portId virtualport identifier
41 * @return VirtualPortId
42 */
43 public static VirtualPortId portId(String portId) {
44 return new VirtualPortId(portId);
45 }
46
47 @Override
48 public int hashCode() {
HIGUCHI Yutaca9cc8e2015-10-29 23:26:51 -070049 return portId.hashCode();
Sho SHIMIZUb2b2d982015-09-11 15:35:06 -070050 }
51
52 @Override
53 public boolean equals(Object obj) {
54 if (this == obj) {
55 return true;
56 }
57 if (obj instanceof VirtualPortId) {
58 final VirtualPortId that = (VirtualPortId) obj;
59 return this.getClass() == that.getClass()
60 && Objects.equals(this.portId, that.portId);
61 }
62 return false;
63 }
64
65 @Override
66 public String toString() {
67 return portId;
68 }
69
70}