Phaneendra Manda | ac63650 | 2015-10-26 22:28:09 +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; |
| 19 | import static com.google.common.base.Preconditions.checkNotNull; |
| 20 | |
| 21 | import java.util.UUID; |
| 22 | |
| 23 | import com.google.common.base.Objects; |
| 24 | |
| 25 | /** |
| 26 | * Representation of a Port Chain ID. |
| 27 | */ |
| 28 | public final class PortChainId { |
| 29 | |
| 30 | private final UUID portChainId; |
| 31 | |
| 32 | /** |
| 33 | * Private constructor for port chain id. |
| 34 | * |
| 35 | * @param id UUID id of port chain |
| 36 | */ |
| 37 | private PortChainId(UUID id) { |
| 38 | checkNotNull(id, "Port chain id can not be null"); |
| 39 | this.portChainId = id; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Constructor to create port chain id from UUID. |
| 44 | * |
| 45 | * @param id UUID of port chain |
| 46 | * @return object of port chain id |
| 47 | */ |
| 48 | public static PortChainId portChainId(UUID id) { |
| 49 | return new PortChainId(id); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Constructor to create port chain id from string. |
| 54 | * |
| 55 | * @param id port chain id in string |
| 56 | * @return object of port chain id |
| 57 | */ |
| 58 | public static PortChainId portChainId(String id) { |
| 59 | return new PortChainId(UUID.fromString(id)); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Returns the value of port chain id. |
| 64 | * |
| 65 | * @return port chain id |
| 66 | */ |
| 67 | public UUID value() { |
| 68 | return portChainId; |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public boolean equals(Object obj) { |
| 73 | if (this == obj) { |
| 74 | return true; |
| 75 | } |
| 76 | |
| 77 | if (obj.getClass() == this.getClass()) { |
| 78 | PortChainId that = (PortChainId) obj; |
| 79 | return Objects.equal(this.portChainId, that.portChainId); |
| 80 | } |
| 81 | return false; |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public int hashCode() { |
| 86 | return Objects.hashCode(this.portChainId); |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public String toString() { |
| 91 | return toStringHelper(this) |
| 92 | .add("portChainId", portChainId.toString()) |
| 93 | .toString(); |
| 94 | } |
| 95 | } |