Future-proof OvsdbTypesIdResolver
[ovsdb.git] / library / impl / src / main / java / org / opendaylight / ovsdb / lib / notation / Column.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.notation;
10
11
12 import org.opendaylight.ovsdb.lib.schema.ColumnSchema;
13 import org.opendaylight.ovsdb.lib.schema.TableSchema;
14
15 import com.fasterxml.jackson.annotation.JsonIgnore;
16
17
18 public class Column<E extends TableSchema<E>, D> {
19     @JsonIgnore
20     private ColumnSchema<E, D> schema;
21     private D data;
22
23     public Column(ColumnSchema<E, D> schema, D data) {
24         this.schema = schema;
25         this.data = data;
26     }
27
28     public <E extends TableSchema<E>, T> T getData(ColumnSchema<E, T> schema) {
29         return schema.validate(data);
30     }
31
32     public D getData() {
33         return data;
34     }
35
36     public void setData(D data) {
37         this.data = data;
38     }
39
40     public ColumnSchema<E, D> getSchema() {
41         return schema;
42     }
43
44     public void setSchema(ColumnSchema<E, D> schema) {
45         this.schema = schema;
46     }
47
48     @Override
49     public String toString() {
50         return "[" + schema.getName() + "=" + data + "]";
51     }
52
53     @Override
54     public int hashCode() {
55         final int prime = 31;
56         int result = 1;
57         result = prime * result + ((data == null) ? 0 : data.hashCode());
58         result = prime * result + ((schema == null) ? 0 : schema.hashCode());
59         return result;
60     }
61
62     @Override
63     public boolean equals(Object obj) {
64         if (this == obj) {
65             return true;
66         }
67         if (obj == null) {
68             return false;
69         }
70         if (getClass() != obj.getClass()) {
71             return false;
72         }
73         Column other = (Column) obj;
74         if (data == null) {
75             if (other.data != null) {
76                 return false;
77             }
78         } else if (!data.equals(other.data)) {
79             return false;
80         }
81         if (schema == null) {
82             if (other.schema != null) {
83                 return false;
84             }
85         } else if (!schema.equals(other.schema)) {
86             return false;
87         }
88         return true;
89     }
90 }