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