ec10b71c4c5f8835c5de3fc0b88530cb489ef122
[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 com.google.common.collect.Maps;
12 import java.util.Map;
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 public class TableUpdate<E extends TableSchema<E>> {
18     private Map<UUID, RowUpdate<E>> rows;
19
20     public Map<UUID, RowUpdate<E>> getRows() {
21         return rows;
22     }
23
24     public class RowUpdate<E extends TableSchema<E>> {
25         private UUID uuid;
26         private Row<E> oldRow;
27         private Row<E> newRow;
28
29         public RowUpdate(UUID uuid, Row<E> oldRow, Row<E> newRow) {
30             this.uuid = uuid;
31             this.oldRow = oldRow;
32             this.newRow = newRow;
33         }
34
35         public UUID getUuid() {
36             return this.uuid;
37         }
38
39         public Row<E> getOld() {
40             return oldRow;
41         }
42
43         public void setOld(Row<E> oldRow) {
44             this.oldRow = oldRow;
45         }
46
47         public Row<E> getNew() {
48             return newRow;
49         }
50
51         public void setNew(Row<E> newRow) {
52             this.newRow = newRow;
53         }
54
55         @Override
56         public String toString() {
57             return "RowUpdate [uuid=" + uuid + ", oldRow=" + oldRow + ", newRow=" + newRow
58                     + "]";
59         }
60     }
61
62     public TableUpdate() {
63         super();
64         rows = Maps.newHashMap();
65     }
66
67     public void addRow(UUID uuid, Row<E> oldRow, Row<E> newRow) {
68         rows.put(uuid, new RowUpdate<>(uuid, oldRow, newRow));
69     }
70
71     public Row<E> getOld(UUID uuid) {
72         RowUpdate<E> rowUpdate = rows.get(uuid);
73         if (rowUpdate == null) {
74             return null;
75         }
76         return rowUpdate.getOld();
77     }
78
79     public Row<E> getNew(UUID uuid) {
80         RowUpdate<E> rowUpdate = rows.get(uuid);
81         if (rowUpdate == null) {
82             return null;
83         }
84         return rowUpdate.getNew();
85     }
86
87     @Override
88     public String toString() {
89         return "TableUpdate [" + rows + "]";
90     }
91 }