comparison geo-backend/src/main/java/de/intevation/gnv/geobackend/base/DefaultResult.java @ 386:465e70422e66 0.3

merged geo-backend/0.3
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:13:47 +0200
parents da2da7bb1aa1
children 12f88239fb33
comparison
equal deleted inserted replaced
376:d8f3ef441bf2 386:465e70422e66
1 /**
2 *
3 */
4 package de.intevation.gnv.geobackend.base;
5
6 import java.util.Date;
7 import java.util.GregorianCalendar;
8 import java.util.HashMap;
9
10 import de.intevation.gnv.geobackend.util.DateUtils;
11
12 /**
13 * Defaultimplementation of the Interface Result.
14 * This Class stores the Attributevalues of one Result.
15 * @author Tim Englich <tim.englich@intevation.de>
16 *
17 */
18 public class DefaultResult
19 implements Result
20 {
21 /**
22 * THE UID of this Classe
23 */
24 private static final long serialVersionUID = -6886218808840982766L;
25
26
27 /**
28 * HashMap which stores the Columnvalues identified by the unique Columnname
29 */
30
31 private Object [] values;
32
33 /**
34 * The ResultDescriptor which describes the ColumnValues
35 */
36 private ResultDescriptor resultDescriptor = null;
37
38 /**
39 * Constructor
40 */
41 public DefaultResult(ResultDescriptor resultDescriptor) {
42 this.resultDescriptor = resultDescriptor;
43 values = new Object[resultDescriptor.getColumnCount()];
44 }
45
46 /**
47 * @see de.intevation.gnv.geobackend.base.Result#getDate(java.lang.String)
48 */
49 public Date getDate(String columnName) {
50 return getDate(resultDescriptor.getColumnIndex(columnName));
51 }
52
53 public Date getDate(int column) {
54 Object o = values[column];
55 Date d = null;
56 if(o instanceof Date){
57 d = (Date)o;
58 }else if (o instanceof GregorianCalendar){
59 d = ((GregorianCalendar)o).getTime();
60 }
61 return d;
62 }
63
64 /**
65 * @see de.intevation.gnv.geobackend.base.Result#getDouble(java.lang.String)
66 */
67 public Double getDouble(String columnName) {
68 return getDouble(resultDescriptor.getColumnIndex(columnName));
69 }
70
71 public Double getDouble(int column) {
72 return (Double)values[column];
73 }
74
75 /**
76 * @see de.intevation.gnv.geobackend.base.Result#getFloat(java.lang.String)
77 */
78 public Float getFloat(String columnName) {
79 return getFloat(resultDescriptor.getColumnIndex(columnName));
80 }
81
82 public Float getFloat(int column) {
83 return (Float)values[column];
84 }
85
86 /**
87 * @see de.intevation.gnv.geobackend.base.Result#getInteger(java.lang.String)
88 */
89 public Integer getInteger(String columnName) {
90 int idx = resultDescriptor.getColumnIndex(columnName);
91
92 return idx > -1 ? getInteger(idx) : -1;
93 //return getInteger(resultDescriptor.getColumnIndex(columnName));
94 }
95
96 public Integer getInteger(int column) {
97 Object value = values[column];
98 if (value instanceof Double){
99 value = new Integer(((Double)value).intValue());
100 }
101 return (Integer)value;
102 }
103 /**
104 * @see de.intevation.gnv.geobackend.base.Result#getResultDescriptor()
105 */
106 public ResultDescriptor getResultDescriptor() {
107 return this.resultDescriptor;
108 }
109
110 /**
111 * @see de.intevation.gnv.geobackend.base.Result#getString(java.lang.String)
112 */
113 public String getString(String columnName) {
114 int idx = resultDescriptor.getColumnIndex(columnName);
115
116 return idx > -1 ? getString(idx) : null;
117 }
118
119 public String getString(int column) {
120
121 Object o = values[column];
122
123 if (o instanceof Date){
124 return DateUtils.getPatternedDateAmer((Date)o);
125 }
126
127 if (o instanceof GregorianCalendar){
128 Date d = ((GregorianCalendar)o).getTime();
129 return DateUtils.getPatternedDateAmer(d);
130 }
131
132 return o != null ? o.toString() : null;
133 }
134
135 /**
136 * @see de.intevation.gnv.geobackend.base.Result#addColumnValue(java.lang.String, java.lang.Object)
137 */
138 public void addColumnValue(int column, Object value) {
139 values[column] = value;
140 }
141
142 /**
143 * @see de.intevation.gnv.geobackend.base.Result#getObject(java.lang.String)
144 */
145 public Object getObject(String columnName) {
146 return getObject(resultDescriptor.getColumnIndex(columnName));
147 }
148
149 public Object getObject(int column) {
150 return values[column];
151 }
152
153 }

http://dive4elements.wald.intevation.org