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