blob: 2e51823f5de932cc0efc1b89362a88caba1482f7 [file] [log] [blame]
lishuai91d986c2015-07-28 09:45:20 +08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
lishuai91d986c2015-07-28 09:45:20 +08003 *
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
Jonathan Hart51539b82015-10-29 09:53:04 -070023import org.onosproject.ovsdb.rfc.notation.json.UuidConverter;
24import org.onosproject.ovsdb.rfc.notation.json.UuidSerializer;
lishuai91d986c2015-07-28 09:45:20 +080025
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 */
Jonathan Hart51539b82015-10-29 09:53:04 -070032@JsonSerialize(using = UuidSerializer.class)
33@JsonDeserialize(converter = UuidConverter.class)
34public final class Uuid {
lishuai91d986c2015-07-28 09:45:20 +080035 private final String value;
36
37 /**
38 * UUID constructor.
39 * @param value UUID value
40 */
Jonathan Hart51539b82015-10-29 09:53:04 -070041 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 */
Jonathan Hart51539b82015-10-29 09:53:04 -070051 public static Uuid uuid(String value) {
52 return new Uuid(value);
lishuai91d986c2015-07-28 09:45:20 +080053 }
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 }
Jonathan Hart51539b82015-10-29 09:53:04 -070073 if (obj instanceof Uuid) {
74 final Uuid other = (Uuid) obj;
lishuai91d986c2015-07-28 09:45:20 +080075 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}