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