blob: 50778633e4c228853dd2e363b84dfdcf370667cb [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
23import org.onosproject.ovsdb.rfc.notation.json.UUIDSerializer;
24
25import com.fasterxml.jackson.databind.annotation.JsonSerialize;
26
27/**
28 * Handles both uuid and named-uuid.
29 */
30@JsonSerialize(using = UUIDSerializer.class)
31public final class UUID {
32 private final String value;
33
34 /**
35 * UUID constructor.
36 * @param value UUID value
37 */
38 private UUID(String value) {
lishuai2f197432015-07-31 16:27:58 +080039 checkNotNull(value, "value cannot be null");
lishuai91d986c2015-07-28 09:45:20 +080040 this.value = value;
41 }
42
43 /**
44 * Get UUID.
45 * @param value UUID value
46 * @return UUID
47 */
48 public static UUID uuid(String value) {
49 return new UUID(value);
50 }
51
52 /**
53 * Returns value.
54 * @return value
55 */
56 public String value() {
57 return value;
58 }
59
60 @Override
61 public int hashCode() {
62 return Objects.hash(value);
63 }
64
65 @Override
66 public boolean equals(Object obj) {
67 if (this == obj) {
68 return true;
69 }
70 if (obj instanceof UUID) {
71 final UUID other = (UUID) obj;
72 return Objects.equals(this.value, other.value);
73 }
74 return false;
75 }
76
77 @Override
78 public String toString() {
79 return toStringHelper(this).add("value", value).toString();
80 }
81}