blob: 1f45e80e06c57deabba74d6979c18cbfd2d6e95d [file] [log] [blame]
Phaneendra Manda635f6212015-10-26 18:27:41 +05301/*
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.MoreObjects.toStringHelper;
Mahesh Poojary Huaweid0b1d132015-11-05 11:00:18 +053019import static com.google.common.base.Preconditions.checkNotNull;
Phaneendra Manda635f6212015-10-26 18:27:41 +053020
21import java.util.UUID;
Mahesh Poojary Se74f9012015-10-29 12:22:47 +053022import java.util.Objects;
Phaneendra Manda635f6212015-10-26 18:27:41 +053023
24/**
25 * Representation of a Port Pair ID.
26 */
27public final class PortPairId {
28
29 private final UUID portPairId;
30
31 /**
32 * Private constructor for port pair id.
33 *
34 * @param id UUID id of port pair
35 */
Mahesh Poojary Huaweid0b1d132015-11-05 11:00:18 +053036 private PortPairId(UUID id) {
37 checkNotNull(id, "Port chain id can not be null");
Phaneendra Manda635f6212015-10-26 18:27:41 +053038 this.portPairId = id;
39 }
40
41 /**
Mahesh Poojary Huaweid0b1d132015-11-05 11:00:18 +053042 * Returns newly created port pair id object.
Phaneendra Manda635f6212015-10-26 18:27:41 +053043 *
44 * @param id UUID of port pair id
45 * @return object of port pair id
46 */
Mahesh Poojary Huaweid0b1d132015-11-05 11:00:18 +053047 public static PortPairId of(UUID id) {
Phaneendra Manda635f6212015-10-26 18:27:41 +053048 return new PortPairId(id);
49 }
50
51 /**
Mahesh Poojary Huaweid0b1d132015-11-05 11:00:18 +053052 * Returns newly created port pair id object.
Phaneendra Manda635f6212015-10-26 18:27:41 +053053 *
54 * @param id port pair id in string
55 * @return object of port pair id
56 */
Mahesh Poojary Huaweid0b1d132015-11-05 11:00:18 +053057 public static PortPairId of(String id) {
Phaneendra Manda635f6212015-10-26 18:27:41 +053058 return new PortPairId(UUID.fromString(id));
59 }
60
61 /**
62 * Returns teh value of port pair id.
63 *
64 * @return port pair id
65 */
66 public UUID value() {
67 return portPairId;
68 }
69
70 @Override
71 public boolean equals(Object obj) {
72 if (this == obj) {
73 return true;
74 }
Mahesh Poojary Se74f9012015-10-29 12:22:47 +053075 if (obj instanceof PortPairId) {
76 final PortPairId other = (PortPairId) obj;
77 return Objects.equals(this.portPairId, other.portPairId);
Phaneendra Manda635f6212015-10-26 18:27:41 +053078 }
79 return false;
80 }
81
82 @Override
83 public int hashCode() {
84 return Objects.hashCode(this.portPairId);
85 }
86
87 @Override
88 public String toString() {
Mahesh Poojary Huaweid0b1d132015-11-05 11:00:18 +053089 return toStringHelper(this)
90 .add("portPairId", portPairId)
91 .toString();
Phaneendra Manda635f6212015-10-26 18:27:41 +053092 }
93}