[PATCH 1 of 2] Implemented calculation of 'year' for fixations

Wald Commits scm-commit at wald.intevation.org
Fri Mar 23 17:54:05 CET 2018


# HG changeset patch
# User gernotbelger
# Date 1521823979 -3600
# Node ID 7565d7dce85084bb1bce3e1f3fcfd281fc3fb3f7
# Parent  ee5ce13016ed1872f8e2dcb176715c20d75da35a
Implemented calculation of 'year' for fixations

diff -r ee5ce13016ed -r 7565d7dce850 artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixRealizingCalculationExtended.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixRealizingCalculationExtended.java	Tue Mar 20 13:30:07 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixRealizingCalculationExtended.java	Fri Mar 23 17:52:59 2018 +0100
@@ -9,8 +9,11 @@
  */
 package org.dive4elements.river.artifacts.model.fixings;
 
+import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
+import java.util.SortedSet;
+import java.util.TreeSet;
 
 import org.dive4elements.river.artifacts.access.FixRealizingAccess;
 import org.dive4elements.river.artifacts.model.FixingsOverview;
@@ -29,19 +32,28 @@
         super(fixAccess);
     }
 
-    // FIXME: implement
-    // FIXME: check if this breaks serialization
     public int determineMeanYear() {
         final FixingsOverview overview = FixingsOverviewFactory.getOverview(this.river);
         final ColumnCache cc = new ColumnCache();
 
-        // FIXME: die Hälfte der zeitlichen Differenz zwischen der ältesten und neusten WSPL
+        final SortedSet<Integer> years = new TreeSet<>();
+
+        final Calendar cal = Calendar.getInstance();
 
         final List<Column> columns = getEventColumns(overview, cc);
         for (final Column column : columns) {
             final Date date = column.getDate();
+            cal.setTime(date);
+
+            final int year = cal.get(Calendar.YEAR);
+            years.add(year);
         }
 
-        return 1999;
+        final Integer first = years.first();
+        final Integer last = years.last();
+        if (first == null || last == null)
+            return -1;
+
+        return (first + last) / 2;
     }
 }


More information about the Dive4Elements-commits mailing list