jiangrui | 72d343a | 2015-11-11 18:00:16 +0800 | [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.Objects; |
| 22 | import java.util.UUID; |
| 23 | |
| 24 | /** |
| 25 | * Immutable representation of a floating IP identifier. |
| 26 | */ |
| 27 | public final class FloatingIpId { |
| 28 | private final UUID floatingIpId; |
| 29 | |
| 30 | // Public construction is prohibited |
| 31 | private FloatingIpId(UUID floatingIpId) { |
| 32 | this.floatingIpId = checkNotNull(floatingIpId, "floatingIpId cannot be null"); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Creates a floating IP identifier. |
| 37 | * |
| 38 | * @param floatingIpId the UUID id of floating IP identifier |
| 39 | * @return object of floating IP identifier |
| 40 | */ |
| 41 | public static FloatingIpId of(UUID floatingIpId) { |
| 42 | return new FloatingIpId(floatingIpId); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Creates a floating IP identifier. |
| 47 | * |
| 48 | * @param floatingIpId the floating IP identifier in string |
| 49 | * @return object of floating IP identifier |
| 50 | */ |
| 51 | public static FloatingIpId of(String floatingIpId) { |
| 52 | return new FloatingIpId(UUID.fromString(floatingIpId)); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Returns the floating IP identifier. |
| 57 | * |
| 58 | * @return the floating IP identifier |
| 59 | */ |
| 60 | public UUID floatingIpId() { |
| 61 | return floatingIpId; |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public int hashCode() { |
| 66 | return floatingIpId.hashCode(); |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public boolean equals(Object obj) { |
| 71 | if (this == obj) { |
| 72 | return true; |
| 73 | } |
| 74 | if (obj instanceof FloatingIpId) { |
| 75 | final FloatingIpId that = (FloatingIpId) obj; |
| 76 | return Objects.equals(this.floatingIpId, that.floatingIpId); |
| 77 | } |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public String toString() { |
| 83 | return toStringHelper(this).add("floatingIpId", floatingIpId).toString(); |
| 84 | } |
| 85 | } |