changeset 3025:5d286d7e54cd

FixA: Prevent duplicates in analysis periods. flys-artifacts/trunk@4592 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 05 Jun 2012 15:37:38 +0000
parents 005f0130e6d6
children 65b6e27c6f25
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/FixationArtifactAccess.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/DateRange.java
diffstat 3 files changed, 28 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Tue Jun 05 15:28:32 2012 +0000
+++ b/flys-artifacts/ChangeLog	Tue Jun 05 15:37:38 2012 +0000
@@ -1,3 +1,11 @@
+2012-06-05	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/FixationArtifactAccess.java:
+	  Prevent duplicates in analysis periods.
+
+	* src/main/java/de/intevation/flys/artifacts/model/fixings/DateRange.java:
+	  Added equals.
+
 2012-06-05	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/utils/EpsilonComparator.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FixationArtifactAccess.java	Tue Jun 05 15:28:32 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FixationArtifactAccess.java	Tue Jun 05 15:37:38 2012 +0000
@@ -320,7 +320,10 @@
                     try {
                         Date from = new Date(Long.parseLong(fromTo[0]));
                         Date to   = new Date(Long.parseLong(fromTo[1]));
-                        aPs.add(new DateRange(from, to));
+                        DateRange aP = new DateRange(from, to);
+                        if (!aPs.contains(aP)) {
+                            aPs.add(aP);
+                        }
                     }
                     catch (NumberFormatException nfe) {
                         log.warn("ana_data contains no long values.", nfe);
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/DateRange.java	Tue Jun 05 15:28:32 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/DateRange.java	Tue Jun 05 15:37:38 2012 +0000
@@ -30,5 +30,21 @@
     public void setTo(Date to) {
         this.to = to;
     }
+
+    private static final boolean equalDates(Date a, Date b) {
+        if (a == null && b != null) return false;
+        if (a != null && b == null) return false;
+        if (a == null) return true;
+        return a.equals(b);
+    }
+
+    @Override
+    public boolean equals(Object other) {
+        if (!(other instanceof DateRange)) {
+            return false;
+        }
+        DateRange o = (DateRange)other;
+        return equalDates(from, o.from) && equalDates(to, o.to);
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org