comparison geo-backend/src/main/java/de/intevation/gnv/geobackend/base/DefaultResult.java @ 280:72f5e8bd2791 0.2

merged geo-backend/0.2
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:13:45 +0200
parents 05912f0304ac
children 4af6379ac20b
comparison
equal deleted inserted replaced
262:8b634333f935 280:72f5e8bd2791
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 return getInteger(resultDescriptor.getColumnIndex(columnName));
91 }
92
93 public Integer getInteger(int column) {
94 Object value = values[column];
95 if (value instanceof Double){
96 value = new Integer(((Double)value).intValue());
97 }
98 return (Integer)value;
99 }
100 /**
101 * @see de.intevation.gnv.geobackend.base.Result#getResultDescriptor()
102 */
103 public ResultDescriptor getResultDescriptor() {
104 return this.resultDescriptor;
105 }
106
107 /**
108 * @see de.intevation.gnv.geobackend.base.Result#getString(java.lang.String)
109 */
110 public String getString(String columnName) {
111 return getString(resultDescriptor.getColumnIndex(columnName));
112 }
113
114 public String getString(int column) {
115
116 Object o = values[column];
117
118 if (o instanceof Date){
119 return DateUtils.getPatternedDateAmer((Date)o);
120 }
121
122 if (o instanceof GregorianCalendar){
123 Date d = ((GregorianCalendar)o).getTime();
124 return DateUtils.getPatternedDateAmer(d);
125 }
126
127 return o != null ? o.toString() : null;
128 }
129
130 /**
131 * @see de.intevation.gnv.geobackend.base.Result#addColumnValue(java.lang.String, java.lang.Object)
132 */
133 public void addColumnValue(int column, Object value) {
134 values[column] = value;
135 }
136
137 /**
138 * @see de.intevation.gnv.geobackend.base.Result#getObject(java.lang.String)
139 */
140 public Object getObject(String columnName) {
141 return getObject(resultDescriptor.getColumnIndex(columnName));
142 }
143
144 public Object getObject(int column) {
145 return values[column];
146 }
147
148 }

http://dive4elements.wald.intevation.org