ad0b2492a0696b3611827706d3a8483b775c10ac
[ovsdb.git] / library / src / main / java / org / opendaylight / ovsdb / lib / notation / Column.java
1 /*
2  *
3  *  * Copyright (C) 2014 EBay Software Foundation
4  *  *
5  *  * This program and the accompanying materials are made available under the
6  *  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  *  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  *  *
9  *  * Authors : Ashwin Raveendran
10  *
11  */
12
13 package org.opendaylight.ovsdb.lib.notation;
14
15
16 import org.opendaylight.ovsdb.lib.schema.ColumnSchema;
17 import org.opendaylight.ovsdb.lib.schema.TableSchema;
18
19 import com.fasterxml.jackson.annotation.JsonIgnore;
20
21
22 public class Column<E extends TableSchema<E>, D> {
23     @JsonIgnore
24     private ColumnSchema<E, D> schema;
25     private D data;
26
27     public Column(ColumnSchema<E, D> schema, D d) {
28         this.schema = schema;
29         this.data = d;
30     }
31
32     public <E extends TableSchema<E>, T> T getData(ColumnSchema<E, T> schema) {
33         return schema.validate(data);
34     }
35
36     public D getData() {
37         return data;
38     }
39
40     public void setData(D data) {
41         this.data = data;
42     }
43
44     public ColumnSchema<E, D> getSchema() {
45         return schema;
46     }
47
48     public void setSchema(ColumnSchema<E, D> schema) {
49         this.schema = schema;
50     }
51
52     @Override
53     public String toString() {
54         return "Column [schema=" + schema + ", data=" + data + "]";
55     }
56
57     @Override
58     public int hashCode() {
59         final int prime = 31;
60         int result = 1;
61         result = prime * result + ((data == null) ? 0 : data.hashCode());
62         result = prime * result + ((schema == null) ? 0 : schema.hashCode());
63         return result;
64     }
65
66     @Override
67     public boolean equals(Object obj) {
68         if (this == obj)
69             return true;
70         if (obj == null)
71             return false;
72         if (getClass() != obj.getClass())
73             return false;
74         Column other = (Column) obj;
75         if (data == null) {
76             if (other.data != null)
77                 return false;
78         } else if (!data.equals(other.data))
79             return false;
80         if (schema == null) {
81             if (other.schema != null)
82                 return false;
83         } else if (!schema.equals(other.schema))
84             return false;
85         return true;
86     }
87 }