blob: 0177eea3f7f8e4b546820e19706962e029910737 [file] [log] [blame]
lishuai91d986c2015-07-28 09:45:20 +08001/*
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 */
16package org.onosproject.ovsdb.rfc.notation;
17
18import static com.google.common.base.MoreObjects.toStringHelper;
19import static com.google.common.base.Preconditions.checkNotNull;
20
21import java.util.Objects;
22
lishuai35b34722015-08-05 14:34:25 +080023import org.onosproject.ovsdb.rfc.notation.json.UUIDConverter;
lishuai91d986c2015-07-28 09:45:20 +080024import org.onosproject.ovsdb.rfc.notation.json.UUIDSerializer;
25
lishuai35b34722015-08-05 14:34:25 +080026import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
lishuai91d986c2015-07-28 09:45:20 +080027import com.fasterxml.jackson.databind.annotation.JsonSerialize;
28
29/**
30 * Handles both uuid and named-uuid.
31 */
32@JsonSerialize(using = UUIDSerializer.class)
lishuai35b34722015-08-05 14:34:25 +080033@JsonDeserialize(converter = UUIDConverter.class)
lishuai91d986c2015-07-28 09:45:20 +080034public final class UUID {
35 private final String value;
36
37 /**
38 * UUID constructor.
39 * @param value UUID value
40 */
41 private UUID(String value) {
lishuai2f197432015-07-31 16:27:58 +080042 checkNotNull(value, "value cannot be null");
lishuai91d986c2015-07-28 09:45:20 +080043 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 Yutaca9cc8e2015-10-29 23:26:51 -070065 return value.hashCode();
lishuai91d986c2015-07-28 09:45:20 +080066 }
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}