Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/utils/VectorDataProcessor.java @ 1040:70653c29fc1d
Finished vector support for timeseriespoints (Issue27).
gnv-artifacts/trunk@1112 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 19 May 2010 14:05:33 +0000 |
parents | |
children | 9bb1979aabbe |
comparison
equal
deleted
inserted
replaced
1039:3be83ac4cfde | 1040:70653c29fc1d |
---|---|
1 package de.intevation.gnv.utils; | |
2 | |
3 import de.intevation.gnv.geobackend.base.DefaultResult; | |
4 import de.intevation.gnv.geobackend.base.DefaultResultDescriptor; | |
5 import de.intevation.gnv.geobackend.base.Result; | |
6 import de.intevation.gnv.geobackend.base.ResultDescriptor; | |
7 | |
8 import java.util.ArrayList; | |
9 import java.util.Collection; | |
10 import java.util.HashMap; | |
11 import java.util.Iterator; | |
12 import java.util.List; | |
13 import java.util.Map; | |
14 | |
15 import org.apache.log4j.Logger; | |
16 | |
17 /** | |
18 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
19 */ | |
20 public final class VectorDataProcessor { | |
21 | |
22 private static Logger logger = Logger.getLogger(VectorDataProcessor.class); | |
23 | |
24 public static final String[] COLUMNS = { | |
25 "YORDINATE", "XORDINATE", "GROUP1", "GROUP2", "GROUP3", "GAPID", "SERIES" | |
26 }; | |
27 | |
28 public static Collection<Result> process(Collection<Result> input) { | |
29 logger.info("Process vector data (" + input.size() + " items)"); | |
30 | |
31 ResultDescriptor outDescriptor = initResultDescriptor(); | |
32 ResultDescriptor inDescriptor = null; | |
33 int[] inIndices = null; | |
34 int columns = -1; | |
35 | |
36 Map series = new HashMap(); | |
37 | |
38 // for each result of the incoming result | |
39 for (Result result: input) { | |
40 if (inDescriptor == null || inIndices == null) { | |
41 inDescriptor = result.getResultDescriptor(); | |
42 inIndices = inDescriptor.getColumnIndices(COLUMNS); | |
43 columns = inDescriptor.getColumnCount(); | |
44 } | |
45 | |
46 // for each column of the incoming result object | |
47 for (int i = 0; i < columns; i++) { | |
48 String name = inDescriptor.getColumnName(i); | |
49 | |
50 if (!StringUtils.contains(COLUMNS, name)) { | |
51 List list = (List) series.get(name); | |
52 if (list == null) | |
53 list = new ArrayList(); | |
54 | |
55 Result out = new DefaultResult(outDescriptor); | |
56 Object value = result.getObject(i); | |
57 | |
58 // skipp results that have no data value | |
59 if (value == null) | |
60 continue; | |
61 | |
62 out.addColumnValue(0, value); | |
63 | |
64 // add meta data to result object | |
65 // TODO: Maybe we could do this one single time, because the | |
66 // TODO: meta data will not change | |
67 for (int j = 1; j < inIndices.length -1; j++) { | |
68 out.addColumnValue(j, result.getObject(inIndices[j])); | |
69 } | |
70 | |
71 // add the name of the component to distinguish between | |
72 // different series later in the chart creation | |
73 out.addColumnValue(inIndices.length-1, name); | |
74 | |
75 list.add(out); | |
76 series.put(name, list); | |
77 } | |
78 } | |
79 } | |
80 | |
81 // finally, we put all lists together | |
82 Iterator iter = series.values().iterator(); | |
83 List output = new ArrayList(); | |
84 while (iter.hasNext()) { | |
85 output.addAll((Collection)iter.next()); | |
86 } | |
87 | |
88 logger.info("Data processing created " + output.size() + " elements."); | |
89 return output; | |
90 } | |
91 | |
92 | |
93 public static ResultDescriptor initResultDescriptor() { | |
94 logger.debug("Init ResultDescriptor for outgoing results."); | |
95 | |
96 ResultDescriptor desc = new DefaultResultDescriptor(); | |
97 | |
98 for (String name: COLUMNS) { | |
99 desc.addColumn(name, "java.lang.String"); | |
100 } | |
101 | |
102 logger.debug("Outgoing ResultDescriptor has " + desc.getColumnCount() + | |
103 " columns"); | |
104 return desc; | |
105 } | |
106 } | |
107 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |