blob: 21f0b72b8b2aa553fdcd6dd4519d0299c7e3a7aa [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;
22import java.util.Set;
23
24import org.onosproject.ovsdb.rfc.notation.json.OvsdbSetSerializer;
25
26import com.fasterxml.jackson.databind.annotation.JsonSerialize;
27
28/**
29 * OvsdbSet is either an atom, representing a set with exactly one element, or
30 * a 2-element JSON array that represents a database set value.
31 *
32 */
33@JsonSerialize(using = OvsdbSetSerializer.class)
34public final class OvsdbSet {
35
36 private final Set set;
37
38 /**
39 * OvsdbSet constructor.
40 * @param set java.util.Set
41 */
42 private OvsdbSet(Set set) {
lishuai2f197432015-07-31 16:27:58 +080043 checkNotNull(set, "set cannot be null");
lishuai91d986c2015-07-28 09:45:20 +080044 this.set = set;
45 }
46
47 /**
48 * Returns set.
49 * @return set
50 */
51 public Set set() {
52 return set;
53 }
54
55 /**
56 * convert Set into OvsdbSet.
57 * @param set java.util.Set
58 * @return OvsdbSet
59 */
60 public static OvsdbSet ovsdbSet(Set set) {
61 return new OvsdbSet(set);
62 }
63
64 @Override
65 public int hashCode() {
HIGUCHI Yutaca9cc8e2015-10-29 23:26:51 -070066 return set.hashCode();
lishuai91d986c2015-07-28 09:45:20 +080067 }
68
69 @Override
70 public boolean equals(Object obj) {
71 if (this == obj) {
72 return true;
73 }
74 if (obj instanceof OvsdbSet) {
75 final OvsdbSet other = (OvsdbSet) obj;
76 return Objects.equals(this.set, other.set);
77 }
78 return false;
79 }
80
81 @Override
82 public String toString() {
83 return toStringHelper(this).add("set", set).toString();
84 }
85}