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