lishuai | 91d986c | 2015-07-28 09:45:20 +0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.ovsdb.rfc.message; |
| 17 | |
| 18 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 19 | import static com.google.common.base.Preconditions.checkNotNull; |
| 20 | |
| 21 | import java.util.Objects; |
| 22 | |
| 23 | import org.onosproject.ovsdb.rfc.notation.Row; |
| 24 | import org.onosproject.ovsdb.rfc.notation.UUID; |
| 25 | |
| 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 | */ |
| 31 | public final class RowUpdate { |
| 32 | private final UUID uuid; |
| 33 | 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 | */ |
| 42 | public RowUpdate(UUID uuid, Row oldRow, Row newRow) { |
| 43 | checkNotNull(uuid, "uuid is not null"); |
| 44 | this.uuid = uuid; |
| 45 | this.oldRow = oldRow; |
| 46 | this.newRow = newRow; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Return uuid. |
| 51 | * @return uuid |
| 52 | */ |
| 53 | public UUID uuid() { |
| 54 | 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 | } |