changeset 800:db5b04ecb426

ISSUE215: Improved ODV-Export. now all Columns which have identical values but different Parameters will be merged to one row. gnv-artifacts/trunk@882 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Tue, 06 Apr 2010 13:07:11 +0000
parents feeaf5aec552
children d766fe2d917a
files gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/exports/ODVExport.java gnv-artifacts/src/main/java/de/intevation/gnv/exports/StringArrayKey.java
diffstat 3 files changed, 88 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog	Tue Apr 06 11:56:53 2010 +0000
+++ b/gnv-artifacts/ChangeLog	Tue Apr 06 13:07:11 2010 +0000
@@ -1,3 +1,16 @@
+2010-04-06  Tim Englich  <tim.englich@intevation.de>
+
+	ISSUE215: Rows will not be merged to one Single Row if their values are identical.
+
+	* src/main/java/de/intevation/gnv/exports/ODVExport.java (writeData): 
+	  Replaced the StringArray using as Key against the new Class StringArrayKey.
+	  This was nessesarry tp detect Rows with same Values joining them to one
+	  Row.
+	* src/main/java/de/intevation/gnv/exports/StringArrayKey.java (StringArrayKey): 
+	  Added new Class for representing the Key of an StringArray not using the 
+	  Hash of the Array but using the hash of the values which are stored in 
+	  the Array.
+
 2010-04-06  Tim Englich  <tim.englich@intevation.de>
 	  ISSUE213: Wrong Geometrytype used for the generation of an Layer with 
 	            Multipolygon-Geometries
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/exports/ODVExport.java	Tue Apr 06 11:56:53 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/exports/ODVExport.java	Tue Apr 06 13:07:11 2010 +0000
@@ -1,13 +1,5 @@
 package de.intevation.gnv.exports;
 
-import au.com.bytecode.opencsv.CSVWriter;
-
-import de.intevation.gnv.geobackend.base.Result;
-
-import de.intevation.gnv.state.describedata.KeyValueDescibeData;
-
-import de.intevation.gnv.state.exception.StateException;
-
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
@@ -16,6 +8,11 @@
 
 import org.apache.log4j.Logger;
 
+import au.com.bytecode.opencsv.CSVWriter;
+import de.intevation.gnv.geobackend.base.Result;
+import de.intevation.gnv.state.describedata.KeyValueDescibeData;
+import de.intevation.gnv.state.exception.StateException;
+
 /**
  * This class is used to create a specific export document which is similar to
  * an CSV document.
@@ -61,14 +58,15 @@
         }
         ArrayList<String> paramids = new ArrayList<String>();
 
-        Map<String[], Map<String,String>> aggregatedRows = new HashMap<String[],  Map<String,String>>();
+        Map<StringArrayKey, Map<String,String>> aggregatedRows = new HashMap<StringArrayKey, Map<String,String>>();
 
         String currentParameterID = "N/N";
 
         while (it.hasNext()) {
             Result res = it.next();
 
-            String[] key = collector.getData(res);
+            String[] value = collector.getData(res);
+            StringArrayKey key = new StringArrayKey(value);
             String parameterValue = res.getString("DATAVALUE");
             String parameterID = res.getString("PARAMETER");
 
@@ -93,13 +91,14 @@
             writer.writeNext(headerList.toArray(header));
         }
 
-        Iterator<String[]> rows = aggregatedRows.keySet().iterator();
+        Iterator<StringArrayKey> rows = aggregatedRows.keySet().iterator();
         while (rows.hasNext()){
-            String[] row = rows.next();
+            StringArrayKey row = rows.next();
             Map<String,String> params = aggregatedRows.get(row);
             ArrayList<String> rowList = new ArrayList<String>();
-            for (int i= 0; i < row.length; i++){
-                rowList.add(row[i]);
+            String[] rowArray = row.getValue();
+            for (int i= 0; i < rowArray.length; i++){
+                rowList.add(rowArray[i]);
             }
             for (int i = 0; i < paramids.size();i++){
                 String key = paramids.get(i);
@@ -110,7 +109,7 @@
                 rowList.add(value);
                 rowList.add("1");
             }
-            writer.writeNext(rowList.toArray(row));
+            writer.writeNext(rowList.toArray(rowArray));
         }
     }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/exports/StringArrayKey.java	Tue Apr 06 13:07:11 2010 +0000
@@ -0,0 +1,61 @@
+package de.intevation.gnv.exports;
+/**
+ * A simple Key Class for generating an syntetic key using the 
+ * values of the given Stringarray and not the Hash of the Stringarray
+ * 
+ * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a>
+ *
+ */
+public class StringArrayKey {
+
+    /**
+     * The Stringarray which contains the Values.
+     */
+    private String[] value = null;
+
+    /**
+     * The Key which should be used to compare the Stringarrays.
+     */
+    private String key = null;
+
+    /**
+     * Constructor
+     * @param value the Value which should be used to generate the key
+     */
+    public StringArrayKey(String[] value) {
+        this.value = value;
+        if (value != null){
+            key = "";
+            for (int i = 0; i < value.length; i++){
+                key += value[i];
+            }
+        }
+    }
+
+    /**
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if (obj instanceof StringArrayKey){
+            return (((StringArrayKey)obj).key).equals(this.key);
+        }
+        return false;
+    }
+
+    /**
+     * @see java.lang.Object#hashCode()
+     */
+    @Override
+    public int hashCode() {
+        return this.key.hashCode();
+    }
+
+    /**
+     * Returns the stored origin Values of the Key
+     * @return the stored origin Values of the Key
+     */
+    public String[] getValue() {
+        return value;
+    }
+}

http://dive4elements.wald.intevation.org