lishuai | 91d986c | 2015-07-28 09:45:20 +0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
lishuai | 91d986c | 2015-07-28 09:45:20 +0800 | [diff] [blame] | 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.ovsdb.rfc.notation; |
| 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 | |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 23 | import org.onosproject.ovsdb.rfc.notation.json.UuidConverter; |
| 24 | import org.onosproject.ovsdb.rfc.notation.json.UuidSerializer; |
lishuai | 91d986c | 2015-07-28 09:45:20 +0800 | [diff] [blame] | 25 | |
lishuai | 35b3472 | 2015-08-05 14:34:25 +0800 | [diff] [blame] | 26 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; |
lishuai | 91d986c | 2015-07-28 09:45:20 +0800 | [diff] [blame] | 27 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; |
| 28 | |
| 29 | /** |
| 30 | * Handles both uuid and named-uuid. |
| 31 | */ |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 32 | @JsonSerialize(using = UuidSerializer.class) |
| 33 | @JsonDeserialize(converter = UuidConverter.class) |
| 34 | public final class Uuid { |
lishuai | 91d986c | 2015-07-28 09:45:20 +0800 | [diff] [blame] | 35 | private final String value; |
| 36 | |
| 37 | /** |
| 38 | * UUID constructor. |
| 39 | * @param value UUID value |
| 40 | */ |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 41 | private Uuid(String value) { |
lishuai | 2f19743 | 2015-07-31 16:27:58 +0800 | [diff] [blame] | 42 | checkNotNull(value, "value cannot be null"); |
lishuai | 91d986c | 2015-07-28 09:45:20 +0800 | [diff] [blame] | 43 | this.value = value; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Get UUID. |
| 48 | * @param value UUID value |
| 49 | * @return UUID |
| 50 | */ |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 51 | public static Uuid uuid(String value) { |
| 52 | return new Uuid(value); |
lishuai | 91d986c | 2015-07-28 09:45:20 +0800 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Returns value. |
| 57 | * @return value |
| 58 | */ |
| 59 | public String value() { |
| 60 | return value; |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public int hashCode() { |
HIGUCHI Yuta | ca9cc8e | 2015-10-29 23:26:51 -0700 | [diff] [blame] | 65 | return value.hashCode(); |
lishuai | 91d986c | 2015-07-28 09:45:20 +0800 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public boolean equals(Object obj) { |
| 70 | if (this == obj) { |
| 71 | return true; |
| 72 | } |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 73 | if (obj instanceof Uuid) { |
| 74 | final Uuid other = (Uuid) obj; |
lishuai | 91d986c | 2015-07-28 09:45:20 +0800 | [diff] [blame] | 75 | return Objects.equals(this.value, other.value); |
| 76 | } |
| 77 | return false; |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public String toString() { |
| 82 | return toStringHelper(this).add("value", value).toString(); |
| 83 | } |
| 84 | } |