changeset 3730:487a8cb4a222

FixA: Improved robustness and performance in facet generation for dates. flys-artifacts/trunk@5403 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sat, 08 Sep 2012 14:42:16 +0000
parents e727e3ebdf85
children e32b822f3cfa
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisResult.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/fixation/FixAnalysisCompute.java
diffstat 3 files changed, 22 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Sat Sep 08 14:19:40 2012 +0000
+++ b/flys-artifacts/ChangeLog	Sat Sep 08 14:42:16 2012 +0000
@@ -1,3 +1,12 @@
+2012-09-08	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/states/fixation/FixAnalysisCompute.java:
+	  Simplified code.
+
+	* src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisResult.java:
+	  Improved robustness and performance.
+	  Only expose date events as Collections not TreeSets.
+
 2012-09-08	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/model/QW.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisResult.java	Sat Sep 08 14:19:40 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisResult.java	Sat Sep 08 14:42:16 2012 +0000
@@ -1,5 +1,6 @@
 package de.intevation.flys.artifacts.model.fixings;
 
+import java.util.Collection;
 import java.util.Date;
 import java.util.TreeSet;
 
@@ -40,24 +41,26 @@
         return result;
     }
 
-    public TreeSet<Date> getReferenceEventsDates() {
+    public Collection<Date> getReferenceEventsDates() {
         TreeSet<Date> dates = new TreeSet<Date>();
         for (KMIndex.Entry<QWD []> entry: referenced) {
-            for (int i = 0; i < entry.getValue().length; i++) {
-                QWD qwd = entry.getValue()[i];
-                dates.add(qwd.date);
+            QWD [] values = entry.getValue();
+            for (int i = 0; i < values.length; i++) {
+                dates.add(values[i].date);
             }
         }
         return dates;
     }
 
-    public TreeSet<Date> getAnalysisEventsDates(int analysisPeriod) {
+    public Collection<Date> getAnalysisEventsDates(int analysisPeriod) {
         TreeSet<Date> dates = new TreeSet<Date>();
         for (KMIndex.Entry<AnalysisPeriod []> entry: analysisPeriods) {
-            AnalysisPeriod period = entry.getValue()[analysisPeriod];
-            for (int i = 0; i < period.qwds.length; i++) {
-                QWD qwd = period.qwds[i];
-                dates.add(qwd.date);
+            QWD [] qwds = entry.getValue()[analysisPeriod].getQWDs();
+            if (qwds == null) {
+                continue;
+            }
+            for (int i = 0; i < qwds.length; i++) {
+                dates.add(qwds[i].date);
             }
         }
         return dates;
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/fixation/FixAnalysisCompute.java	Sat Sep 08 14:19:40 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/fixation/FixAnalysisCompute.java	Sat Sep 08 14:42:16 2012 +0000
@@ -2,9 +2,7 @@
 
 import java.text.DateFormat;
 import java.util.Date;
-import java.util.Iterator;
 import java.util.List;
-import java.util.TreeSet;
 
 import org.apache.log4j.Logger;
 
@@ -209,11 +207,8 @@
                 I18N_REFERENCEDEVIATION,
                 I18N_REFERENCEDEVIATION);
 
-        TreeSet<Date> dates = fr.getReferenceEventsDates();
-        Iterator<Date> iter = dates.iterator();
         int i = 0;
-        while (iter.hasNext()) {
-            Date d = iter.next();
+        for (Date d: fr.getReferenceEventsDates()) {
             int refNdx = idg.next() << 8;
             refNdx |=  i;
             facets.add(new FixReferenceEventsFacet(refNdx,

http://dive4elements.wald.intevation.org