changeset 8957:7565d7dce850

Implemented calculation of 'year' for fixations
author gernotbelger
date Fri, 23 Mar 2018 17:52:59 +0100
parents ee5ce13016ed
children 3c95b89da5ea
files artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixRealizingCalculationExtended.java
diffstat 1 files changed, 16 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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;
     }
 }

http://dive4elements.wald.intevation.org