lishuai | 91d986c | 2015-07-28 09:45:20 +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.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 | |
lishuai | 35b3472 | 2015-08-05 14:34:25 +0800 | [diff] [blame] | 23 | import org.onosproject.ovsdb.rfc.notation.json.UUIDConverter; |
lishuai | 91d986c | 2015-07-28 09:45:20 +0800 | [diff] [blame] | 24 | import org.onosproject.ovsdb.rfc.notation.json.UUIDSerializer; |
| 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 | */ |
| 32 | @JsonSerialize(using = UUIDSerializer.class) |
lishuai | 35b3472 | 2015-08-05 14:34:25 +0800 | [diff] [blame] | 33 | @JsonDeserialize(converter = UUIDConverter.class) |
lishuai | 91d986c | 2015-07-28 09:45:20 +0800 | [diff] [blame] | 34 | public final class UUID { |
| 35 | private final String value; |
| 36 | |
| 37 | /** |
| 38 | * UUID constructor. |
| 39 | * @param value UUID value |
| 40 | */ |
| 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 | */ |
| 51 | public static UUID uuid(String value) { |
| 52 | return new UUID(value); |
| 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 | } |
| 73 | if (obj instanceof UUID) { |
| 74 | final UUID other = (UUID) obj; |
| 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 | } |