Merge "Updating fix for bug 3989 based on discussion in OVSDB meeting"
[ovsdb.git] / library / impl / src / main / java / org / opendaylight / ovsdb / lib / message / TableUpdate.java
1 /*
2  * Copyright (c) 2014, 2015 EBay Software Foundation and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.ovsdb.lib.message;
10
11 import java.util.Map;
12
13 import org.opendaylight.ovsdb.lib.notation.Row;
14 import org.opendaylight.ovsdb.lib.notation.UUID;
15 import org.opendaylight.ovsdb.lib.schema.TableSchema;
16
17 import com.google.common.collect.Maps;
18
19 public class TableUpdate<E extends TableSchema<E>> {
20     private Map<UUID, RowUpdate<E>> rows;
21
22     public Map<UUID, RowUpdate<E>> getRows() {
23         return rows;
24     }
25
26     public class RowUpdate<E extends TableSchema<E>> {
27         private UUID uuid;
28         private Row<E> oldRow;
29         private Row<E> newRow;
30
31         public RowUpdate(UUID uuid, Row<E> oldRow, Row<E> newRow) {
32             this.uuid = uuid;
33             this.oldRow = oldRow;
34             this.newRow = newRow;
35         }
36
37         public UUID getUuid() {
38             return this.uuid;
39         }
40
41         public Row<E> getOld() {
42             return oldRow;
43         }
44
45         public void setOld(Row<E> oldRow) {
46             this.oldRow = oldRow;
47         }
48
49         public Row<E> getNew() {
50             return newRow;
51         }
52
53         public void setNew(Row<E> newRow) {
54             this.newRow = newRow;
55         }
56
57         @Override
58         public String toString() {
59             return "RowUpdate [uuid=" + uuid + ", oldRow=" + oldRow + ", newRow=" + newRow
60                     + "]";
61         }
62     }
63
64     public TableUpdate() {
65         super();
66         rows = Maps.newHashMap();
67     }
68
69     public void addRow(UUID uuid, Row<E> oldRow, Row<E> newRow) {
70         rows.put(uuid, new RowUpdate<E>(uuid, oldRow, newRow));
71     }
72
73     public Row<E> getOld(UUID uuid) {
74         RowUpdate<E> rowUpdate = rows.get(uuid);
75         if (rowUpdate == null) {
76             return null;
77         }
78         return rowUpdate.getOld();
79     }
80
81     public Row<E> getNew(UUID uuid) {
82         RowUpdate<E> rowUpdate = rows.get(uuid);
83         if (rowUpdate == null) {
84             return null;
85         }
86         return rowUpdate.getNew();
87     }
88
89     @Override
90     public String toString() {
91         return "TableUpdate [" + rows + "]";
92     }
93 }