Initial Netty + JSON Deserializer + all the enhancements happening in many private...
[ovsdb.git] / ovsdb / src / main / java / org / opendaylight / ovsdb / message / TableUpdate.java
1 package org.opendaylight.ovsdb.message;
2
3 import com.fasterxml.jackson.annotation.JsonAnyGetter;
4 import com.fasterxml.jackson.annotation.JsonAnySetter;
5 import com.fasterxml.jackson.annotation.JsonIgnore;
6 import com.fasterxml.jackson.annotation.JsonProperty;
7 import com.google.common.collect.Maps;
8
9 import java.util.Collection;
10 import java.util.Map;
11 import java.util.Set;
12
13 import org.opendaylight.ovsdb.table.internal.Table;
14
15
16 public  class TableUpdate<T extends Table>  {
17     /*This could have been done as a map, but doing so would expose the inner wrapper class in type signature*/
18
19     Map<String, Row<T>> map = Maps.newHashMap();
20
21     @JsonAnyGetter
22     public Row<T> get(String rowId) {
23         return map.get(rowId);
24     }
25
26     @JsonAnySetter
27     public void set(String rowId, Row<T> value) {
28         map.put(rowId, value);
29         value.setId(rowId);
30     }
31
32     public Collection<Row<T>> getRows() {
33         return map.values();
34     }
35
36     @Override
37     public String toString() {
38         return "TableUpdate [map=" + map + "]";
39     }
40
41     static class Row<T> {
42
43         @JsonIgnore
44         String id;
45
46         @JsonProperty("new")
47         T _new;
48         T old;
49
50         public String getId() {
51             return id;
52         }
53
54         public T getNew() {
55             return _new;
56         }
57
58         public void setNew(T neww) {
59             this._new = neww;
60         }
61
62         public T getOld() {
63             return old;
64         }
65
66         public void setOld(T old) {
67             this.old = old;
68         }
69
70         void setId(String id) {
71             this.id = id;
72         }
73
74         @Override
75         public String toString() {
76             return "Row{" +
77                     "id='" + id + '\'' +
78                     ", _new=" + _new.toString() +
79                     '}';
80         }
81
82     }
83 }