Phaneendra Manda | 635f621 | 2015-10-26 18:27:41 +0530 | [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.vtnrsc; |
| 17 | |
| 18 | import static com.google.common.base.MoreObjects.toStringHelper; |
Phaneendra Manda | 635f621 | 2015-10-26 18:27:41 +0530 | [diff] [blame] | 19 | |
| 20 | import java.util.UUID; |
Mahesh Poojary S | e74f901 | 2015-10-29 12:22:47 +0530 | [diff] [blame^] | 21 | import java.util.Objects; |
Phaneendra Manda | 635f621 | 2015-10-26 18:27:41 +0530 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * Representation of a Port Pair ID. |
| 25 | */ |
| 26 | public final class PortPairId { |
| 27 | |
| 28 | private final UUID portPairId; |
| 29 | |
| 30 | /** |
| 31 | * Private constructor for port pair id. |
| 32 | * |
| 33 | * @param id UUID id of port pair |
| 34 | */ |
Mahesh Poojary S | e74f901 | 2015-10-29 12:22:47 +0530 | [diff] [blame^] | 35 | private PortPairId(final UUID id) { |
Phaneendra Manda | 635f621 | 2015-10-26 18:27:41 +0530 | [diff] [blame] | 36 | this.portPairId = id; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Constructor to create port pair id from UUID. |
| 41 | * |
| 42 | * @param id UUID of port pair id |
| 43 | * @return object of port pair id |
| 44 | */ |
Mahesh Poojary S | e74f901 | 2015-10-29 12:22:47 +0530 | [diff] [blame^] | 45 | public static PortPairId portPairId(final UUID id) { |
Phaneendra Manda | 635f621 | 2015-10-26 18:27:41 +0530 | [diff] [blame] | 46 | return new PortPairId(id); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Constructor to create port pair id from string. |
| 51 | * |
| 52 | * @param id port pair id in string |
| 53 | * @return object of port pair id |
| 54 | */ |
Mahesh Poojary S | e74f901 | 2015-10-29 12:22:47 +0530 | [diff] [blame^] | 55 | public static PortPairId portPairId(final String id) { |
Phaneendra Manda | 635f621 | 2015-10-26 18:27:41 +0530 | [diff] [blame] | 56 | return new PortPairId(UUID.fromString(id)); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Returns teh value of port pair id. |
| 61 | * |
| 62 | * @return port pair id |
| 63 | */ |
| 64 | public UUID value() { |
| 65 | return portPairId; |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public boolean equals(Object obj) { |
| 70 | if (this == obj) { |
| 71 | return true; |
| 72 | } |
Mahesh Poojary S | e74f901 | 2015-10-29 12:22:47 +0530 | [diff] [blame^] | 73 | if (obj instanceof PortPairId) { |
| 74 | final PortPairId other = (PortPairId) obj; |
| 75 | return Objects.equals(this.portPairId, other.portPairId); |
Phaneendra Manda | 635f621 | 2015-10-26 18:27:41 +0530 | [diff] [blame] | 76 | } |
| 77 | return false; |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public int hashCode() { |
| 82 | return Objects.hashCode(this.portPairId); |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public String toString() { |
Mahesh Poojary S | e74f901 | 2015-10-29 12:22:47 +0530 | [diff] [blame^] | 87 | return toStringHelper(this).add("portPairId", portPairId.toString()).toString(); |
Phaneendra Manda | 635f621 | 2015-10-26 18:27:41 +0530 | [diff] [blame] | 88 | } |
| 89 | } |