blob: 304deabe5291e4586848c3e036142449403bb71f [file] [log] [blame]
lishuai91d986c2015-07-28 09:45:20 +08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
lishuai91d986c2015-07-28 09:45:20 +08003 *
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.Objects;
22
23import org.onosproject.ovsdb.rfc.notation.Row;
Jonathan Hart51539b82015-10-29 09:53:04 -070024import org.onosproject.ovsdb.rfc.notation.Uuid;
lishuai91d986c2015-07-28 09:45:20 +080025
26/**
27 * A TableUpdate is an object that maps from the row's UUID to a RowUpdate object.
28 * A RowUpdate is an object with the following members: "old": row, "new": row.
29 * Refer to RFC 7047 Section 4.1.6.
30 */
31public final class RowUpdate {
Jonathan Hart51539b82015-10-29 09:53:04 -070032 private final Uuid uuid;
lishuai91d986c2015-07-28 09:45:20 +080033 private final Row oldRow;
34 private final Row newRow;
35
36 /**
37 * Constructs a RowUpdate object.
38 * @param uuid UUID
39 * @param oldRow present for "delete" and "modify" updates
40 * @param newRow present for "initial", "insert", and "modify" updates
41 */
Jonathan Hart51539b82015-10-29 09:53:04 -070042 public RowUpdate(Uuid uuid, Row oldRow, Row newRow) {
lishuai2f197432015-07-31 16:27:58 +080043 checkNotNull(uuid, "uuid cannot be null");
lishuai91d986c2015-07-28 09:45:20 +080044 this.uuid = uuid;
45 this.oldRow = oldRow;
46 this.newRow = newRow;
47 }
48
49 /**
50 * Return uuid.
51 * @return uuid
52 */
Jonathan Hart51539b82015-10-29 09:53:04 -070053 public Uuid uuid() {
lishuai91d986c2015-07-28 09:45:20 +080054 return this.uuid;
55 }
56
57 /**
58 * Return oldRow.
59 * @return oldRow
60 */
61 public Row oldRow() {
62 return oldRow;
63 }
64
65 /**
66 * Return newRow.
67 * @return newRow
68 */
69 public Row newRow() {
70 return newRow;
71 }
72
73 @Override
74 public int hashCode() {
75 return Objects.hash(uuid, oldRow, newRow);
76 }
77
78 @Override
79 public boolean equals(Object obj) {
80 if (this == obj) {
81 return true;
82 }
83 if (obj instanceof RowUpdate) {
84 final RowUpdate other = (RowUpdate) obj;
85 return Objects.equals(this.uuid, other.uuid)
86 && Objects.equals(this.oldRow, other.oldRow)
87 && Objects.equals(this.newRow, other.newRow);
88 }
89 return false;
90 }
91
92 @Override
93 public String toString() {
94 return toStringHelper(this).add("uuid", uuid).add("oldRow", oldRow)
95 .add("newRow", newRow).toString();
96 }
97}