Fix license header violations in sal-dom-xsql
[controller.git] / opendaylight / md-sal / sal-dom-xsql / src / main / java / org / opendaylight / controller / md / sal / dom / xsql / XSQLColumn.java
1 /*
2  * Copyright (c) 2014, 2015 Cisco Systems, Inc. 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.controller.md.sal.dom.xsql;
10
11 import java.io.Serializable;
12
13 public class XSQLColumn implements Serializable, Comparable<Object> {
14     private static final long serialVersionUID = 4854919735031714751L;
15
16     private String name = null;
17     private String tableName = null;
18     private int charWidth = -1;
19     private Class<?> type = null;
20     private transient Object bluePrintNode = null;
21     private String origName = null;
22     private String origTableName = null;
23
24     public XSQLColumn(Object odlNode, String _tableName, Object _bluePrintNode) {
25         this.name = XSQLODLUtils.getNodeNameFromDSN(odlNode);
26         this.tableName = _tableName;
27         this.bluePrintNode = _bluePrintNode;
28         this.type = XSQLODLUtils.getTypeForODLColumn(odlNode);
29     }
30
31     public XSQLColumn(String _name, String _tableName,String _origName, String _origTableName){
32         this.name = _name;
33         this.tableName = _tableName;
34         this.origName = _origName;
35         this.origTableName = _origTableName;
36     }
37
38     public String getName() {
39         return name;
40     }
41
42     public String getTableName() {
43         return tableName;
44     }
45
46     public void setCharWidth(int i) {
47         if (this.charWidth < i) {
48             this.charWidth = i;
49         }
50     }
51
52     public int getCharWidth() {
53         return this.charWidth;
54     }
55
56     @Override
57     public int hashCode() {
58         return this.name.hashCode() + this.tableName.hashCode();
59     }
60
61     @Override
62     public boolean equals(Object obj) {
63         if (!(obj instanceof XSQLColumn)) {
64             return false;
65         }
66         XSQLColumn other = (XSQLColumn) obj;
67         return tableName.equals(other.tableName) && name.equals(other.name);
68     }
69
70     public Object getBluePrintNode() {
71         return this.bluePrintNode;
72     }
73
74     @Override
75     public String toString() {
76         return tableName + "." + name;
77     }
78
79     @Override
80     public int compareTo(Object o) {
81         return this.toString().compareTo(o.toString());
82     }
83
84     public Object getResultSetValue(Object obj){
85         if(this.type.equals(String.class)){
86             return obj.toString();
87         }else
88         if(this.type.equals(int.class)){
89             return Integer.parseInt(obj.toString());
90         }else
91         if(this.type.equals(long.class)){
92             return Long.parseLong(obj.toString());
93         }else
94         if(this.type.equals(byte.class)){
95             return Byte.parseByte(obj.toString());
96         }
97         return null;
98     }
99 }