lishuai | 91d986c | 2015-07-28 09:45:20 +0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
lishuai | 91d986c | 2015-07-28 09:45:20 +0800 | [diff] [blame] | 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 | */ |
| 16 | package org.onosproject.ovsdb.rfc.notation; |
| 17 | |
| 18 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 19 | import static com.google.common.base.Preconditions.checkNotNull; |
| 20 | |
| 21 | import java.util.Map; |
| 22 | import java.util.Objects; |
| 23 | |
| 24 | import org.onosproject.ovsdb.rfc.notation.json.OvsdbMapSerializer; |
| 25 | |
| 26 | import 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) |
| 32 | public 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) { |
lishuai | 2f19743 | 2015-07-31 16:27:58 +0800 | [diff] [blame] | 41 | checkNotNull(map, "map cannot be null"); |
lishuai | 91d986c | 2015-07-28 09:45:20 +0800 | [diff] [blame] | 42 | 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 Yuta | ca9cc8e | 2015-10-29 23:26:51 -0700 | [diff] [blame] | 64 | return map.hashCode(); |
lishuai | 91d986c | 2015-07-28 09:45:20 +0800 | [diff] [blame] | 65 | } |
| 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 | } |