blob: 5228490efed29d06e024e1009e4fcfbac9ba2d89 [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;
19
20import java.util.Map;
21import java.util.Objects;
22
23import org.onosproject.ovsdb.rfc.notation.Row;
24import org.onosproject.ovsdb.rfc.notation.UUID;
25
26/**
27 * TableUpdate is an object that maps from the row's UUID to a RowUpdate object.
28 */
29public final class TableUpdate {
30
31 private final Map<UUID, RowUpdate> rows;
32
33 /**
34 * Constructs a TableUpdate object.
35 * @param rows the parameter of TableUpdate entity
36 */
37 private TableUpdate(Map<UUID, RowUpdate> rows) {
38 this.rows = rows;
39 }
40
41 /**
42 * Get TableUpdate entity.
43 * @param rows the parameter of TableUpdate entity
44 * @return TableUpdate entity
45 */
46 public static TableUpdate tableUpdate(Map<UUID, RowUpdate> rows) {
47 return new TableUpdate(rows);
48 }
49
50 /**
51 * Return old row.
52 * @param uuid the key of rows
53 * @return Row old row
54 */
55 public Row getOld(UUID uuid) {
56 RowUpdate rowUpdate = rows.get(uuid);
57 if (rowUpdate == null) {
58 return null;
59 }
60 return rowUpdate.oldRow();
61 }
62
63 /**
64 * Return new row.
65 * @param uuid the key of rows
66 * @return Row new row
67 */
68 public Row getNew(UUID uuid) {
69 RowUpdate rowUpdate = rows.get(uuid);
70 if (rowUpdate == null) {
71 return null;
72 }
73 return rowUpdate.newRow();
74 }
75
76 /**
77 * Return rows.
78 * @return rows
79 */
80 public Map<UUID, RowUpdate> rows() {
81 return rows;
82 }
83
84 @Override
85 public int hashCode() {
86 return Objects.hash(rows);
87 }
88
89 @Override
90 public boolean equals(Object obj) {
91 if (this == obj) {
92 return true;
93 }
94 if (obj instanceof TableUpdate) {
95 final TableUpdate other = (TableUpdate) obj;
96 return Objects.equals(this.rows, other.rows);
97 }
98 return false;
99 }
100
101 @Override
102 public String toString() {
103 return toStringHelper(this).add("rows", rows).toString();
104 }
105}