blob: a62ab0db75e10c92287458195f4363da8dbaf7c3 [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.Map;
22import java.util.Objects;
23
24import org.onosproject.ovsdb.rfc.notation.json.OvsdbMapSerializer;
25
26import com.fasterxml.jackson.databind.annotation.JsonSerialize;
27
28/**
29 * OvsdbMap is a 2-element JSON array that represents a database map value.
30 */
31@JsonSerialize(using = OvsdbMapSerializer.class)
32public final class OvsdbMap {
33
34 private final Map map;
35
36 /**
37 * OvsdbMap constructor.
38 * @param map java.util.Map
39 */
40 private OvsdbMap(Map map) {
lishuai2f197432015-07-31 16:27:58 +080041 checkNotNull(map, "map cannot be null");
lishuai91d986c2015-07-28 09:45:20 +080042 this.map = map;
43 }
44
45 /**
46 * Returns map.
47 * @return map
48 */
49 public Map map() {
50 return map;
51 }
52
53 /**
54 * convert Map into OvsdbMap.
55 * @param map java.util.Map
56 * @return OvsdbMap
57 */
58 public static OvsdbMap ovsdbMap(Map map) {
59 return new OvsdbMap(map);
60 }
61
62 @Override
63 public int hashCode() {
HIGUCHI Yutaca9cc8e2015-10-29 23:26:51 -070064 return map.hashCode();
lishuai91d986c2015-07-28 09:45:20 +080065 }
66
67 @Override
68 public boolean equals(Object obj) {
69 if (this == obj) {
70 return true;
71 }
72 if (obj instanceof OvsdbMap) {
73 final OvsdbMap other = (OvsdbMap) obj;
74 return Objects.equals(this.map, other.map);
75 }
76 return false;
77 }
78
79 @Override
80 public String toString() {
81 return toStringHelper(this).add("map", map).toString();
82 }
83}