Code ReOrganization and Re-Architecture changes
[ovsdb.git] / library / src / main / java / org / opendaylight / ovsdb / lib / message / TableUpdate.java
1 /*
2  * Copyright (C) 2013 EBay Software Foundation
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  * Authors : Ashwin Raveendran, Madhu Venugopal
9  */
10 package org.opendaylight.ovsdb.lib.message;
11
12 import com.fasterxml.jackson.annotation.JsonAnyGetter;
13 import com.fasterxml.jackson.annotation.JsonAnySetter;
14 import com.fasterxml.jackson.annotation.JsonIgnore;
15 import com.fasterxml.jackson.annotation.JsonProperty;
16 import com.google.common.collect.Maps;
17
18 import java.util.Collection;
19 import java.util.Map;
20
21 import org.opendaylight.ovsdb.lib.table.Table;
22
23
24 public  class TableUpdate<T extends Table>  {
25     /*This could have been done as a map, but doing so would expose the inner wrapper class in type signature*/
26
27     Map<String, Row<T>> map = Maps.newHashMap();
28
29     @JsonAnyGetter
30     public Row<T> get(String rowId) {
31         return map.get(rowId);
32     }
33
34     @JsonAnySetter
35     public void set(String rowId, Row<T> value) {
36         map.put(rowId, value);
37         value.setId(rowId);
38     }
39
40     public Collection<Row<T>> getRows() {
41         return map.values();
42     }
43
44     @Override
45     public String toString() {
46         return "TableUpdate [map=" + map + "]";
47     }
48
49     public static class Row<T> {
50
51         @JsonIgnore
52         String id;
53
54         @JsonProperty("new")
55         T _new;
56         T old;
57
58         public String getId() {
59             return id;
60         }
61
62         public T getNew() {
63             return _new;
64         }
65
66         public void setNew(T neww) {
67             this._new = neww;
68         }
69
70         public T getOld() {
71             return old;
72         }
73
74         public void setOld(T old) {
75             this.old = old;
76         }
77
78         void setId(String id) {
79             this.id = id;
80         }
81
82         @Override
83         public String toString() {
84             return "Row{" +
85                     "id='" + id + '\'' +
86                     ", _new=" + _new.toString() +
87                     '}';
88         }
89
90     }
91 }