[Dive4elements-commits] [PATCH] Add SQRelationJRDataSource class

Wald Commits scm-commit at wald.intevation.org
Mon Jun 3 17:16:50 CEST 2013


# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1370272607 -7200
# Node ID 5d88268f184d4379a07dba1a74ae0fd5a879ef9e
# Parent  58a6137983864ff371a65bca7c15c1efecd69e80
Add SQRelationJRDataSource class

    Forgot to add it in the last commit

diff -r 58a613798386 -r 5d88268f184d artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/SQRelationJRDataSource.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/SQRelationJRDataSource.java	Mon Jun 03 17:16:47 2013 +0200
@@ -0,0 +1,100 @@
+/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+
+package org.dive4elements.river.artifacts.model.sq;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import org.apache.log4j.Logger;
+
+import net.sf.jasperreports.engine.JRDataSource;
+import net.sf.jasperreports.engine.JRException;
+import net.sf.jasperreports.engine.JRField;
+
+
+/**
+ * @author <a href="mailto:raimund.renkert at intevation.de">Raimund Renkert</a>
+ */
+public class SQRelationJRDataSource implements JRDataSource
+{
+    /** The logger used in this exporter.*/
+    private static Logger logger = Logger.getLogger(SQRelationJRDataSource.class);
+
+    private ArrayList<String[]> data;
+    private HashMap<String, String> metaData;
+
+    private int index = -1;
+
+    public SQRelationJRDataSource() {
+        data = new ArrayList<String[]>();
+        metaData = new HashMap<String, String>();
+    }
+
+    public void addData(String[] val) {
+        data.add(val);
+    }
+
+    public void addMetaData(String key, String value) {
+        metaData.put(key, value);
+    }
+
+    public boolean next() throws JRException {
+        index++;
+        return (index < data.size());
+    }
+
+    public Object getFieldValue(JRField field) throws JRException {
+        Object value = "";
+        String fieldName = field.getName();
+        if ("river".equals(fieldName)) {
+            value = metaData.get("river");
+        }
+        else if ("date".equals(fieldName)) {
+            value = metaData.get("date");
+        }
+        else if ("calculation".equals(fieldName)) {
+            value = metaData.get("calculation");
+        }
+        else if ("location".equals(fieldName)) {
+            value = metaData.get("location");
+        }
+        else if ("outliers".equals(fieldName)) {
+            value = metaData.get("outliers");
+        }
+        else if ("outliertest".equals(fieldName)) {
+            value = metaData.get("outliertest");
+        }
+        else if ("periods".equals(fieldName)) {
+            value = metaData.get("periods");
+        }
+        else if ("km".equals(fieldName)) {
+            value = data.get(index)[0];
+        }
+        else if ("param".equals(fieldName)) {
+            value = data.get(index)[1];
+        }
+        else if ("a".equals(fieldName)) {
+            value = data.get(index)[2];
+        }
+        else if ("b".equals(fieldName)) {
+            value = data.get(index)[3];
+        }
+        else if ("total".equals(fieldName)) {
+            value = data.get(index)[4];
+        }
+        else if ("out".equals(fieldName)) {
+            value = data.get(index)[5];
+        }
+        else if ("variance".equals(fieldName)) {
+            value = data.get(index)[6];
+        }
+        return value;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :


More information about the Dive4elements-commits mailing list