blob: e161016b1e3c58081dd7ac7859abb5e03995d57f [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.message;
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.schema.TableSchema;
25
26/**
27 * TableUpdates is an object that maps from a table name to a TableUpdate.
28 */
29public final class TableUpdates {
30
31 private final Map<String, TableUpdate> result;
32
33 /**
34 * Constructs a TableUpdates object.
35 * @param result the parameter of TableUpdates entity
36 */
37 private TableUpdates(Map<String, TableUpdate> result) {
38 this.result = result;
39 }
40
41 /**
42 * Get TableUpdates.
43 * @param result the parameter of TableUpdates entity
44 * @return TableUpdates
45 */
46 public static TableUpdates tableUpdates(Map<String, TableUpdate> result) {
lishuai2f197432015-07-31 16:27:58 +080047 checkNotNull(result, "result cannot be null");
lishuai91d986c2015-07-28 09:45:20 +080048 return new TableUpdates(result);
49 }
50
51 /**
52 * Return TableUpdate.
53 * @param table the TableSchema of TableUpdates
54 * @return TableUpdate
55 */
56 public TableUpdate tableUpdate(TableSchema table) {
57 return this.result.get(table.name());
58 }
59
60 /**
61 * Return the map of TableUpdate.
62 * @return result
63 */
64 public Map<String, TableUpdate> result() {
65 return result;
66 }
67
68 @Override
69 public int hashCode() {
HIGUCHI Yutaca9cc8e2015-10-29 23:26:51 -070070 return result.hashCode();
lishuai91d986c2015-07-28 09:45:20 +080071 }
72
73 @Override
74 public boolean equals(Object obj) {
75 if (this == obj) {
76 return true;
77 }
78 if (obj instanceof TableUpdates) {
79 final TableUpdates other = (TableUpdates) obj;
80 return Objects.equals(this.result, other.result);
81 }
82 return false;
83 }
84
85 @Override
86 public String toString() {
87 return toStringHelper(this).add("result", result).toString();
88 }
89}