Make RowUpdate immutable and final
[ovsdb.git] / library / impl / src / main / java / org / opendaylight / ovsdb / lib / message / TableUpdate.java
1 /*
2  * Copyright © 2014, 2017 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 package org.opendaylight.ovsdb.lib.message;
9
10 import java.util.HashMap;
11 import java.util.Map;
12 import org.opendaylight.ovsdb.lib.notation.Row;
13 import org.opendaylight.ovsdb.lib.notation.UUID;
14 import org.opendaylight.ovsdb.lib.schema.TableSchema;
15
16 public class TableUpdate<E extends TableSchema<E>> {
17     private final Map<UUID, RowUpdate<E>> rows = new HashMap<>();
18
19     public Map<UUID, RowUpdate<E>> getRows() {
20         return rows;
21     }
22
23     public static final class RowUpdate<E extends TableSchema<E>> {
24         private final UUID uuid;
25         private final Row<E> oldRow;
26         private final Row<E> newRow;
27
28         public RowUpdate(final UUID uuid, final Row<E> oldRow, final Row<E> newRow) {
29             this.uuid = uuid;
30             this.oldRow = oldRow;
31             this.newRow = newRow;
32         }
33
34         public UUID getUuid() {
35             return this.uuid;
36         }
37
38         public Row<E> getOld() {
39             return oldRow;
40         }
41
42         public Row<E> getNew() {
43             return newRow;
44         }
45
46         @Override
47         public String toString() {
48             return "RowUpdate [uuid=" + uuid + ", oldRow=" + oldRow + ", newRow=" + newRow + "]";
49         }
50     }
51
52     public void addRow(final UUID uuid, final Row<E> oldRow, final Row<E> newRow) {
53         rows.put(uuid, new RowUpdate<>(uuid, oldRow, newRow));
54     }
55
56     public Row<E> getOld(final UUID uuid) {
57         RowUpdate<E> rowUpdate = rows.get(uuid);
58         return rowUpdate != null ? rowUpdate.getOld() : null;
59     }
60
61     public Row<E> getNew(final UUID uuid) {
62         RowUpdate<E> rowUpdate = rows.get(uuid);
63         return rowUpdate != null ? rowUpdate.getNew() : null;
64     }
65
66     @Override
67     public String toString() {
68         return "TableUpdate [" + rows + "]";
69     }
70 }