changeset 7927:07cc4cd9233e

Add new DateUtil class.
author "Tom Gottfried <tom@intevation.de>"
date Thu, 12 Jun 2014 12:21:55 +0200
parents e3b74679b2b4
children 5b3c795385ef
files backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightParser.java backend/src/main/java/org/dive4elements/river/importer/parsers/LineParser.java backend/src/main/java/org/dive4elements/river/importer/parsers/PorosityParser.java backend/src/main/java/org/dive4elements/river/importer/parsers/SQRelationParser.java backend/src/main/java/org/dive4elements/river/importer/parsers/SedimentYieldParser.java backend/src/main/java/org/dive4elements/river/importer/parsers/WaterlevelDifferencesParser.java backend/src/main/java/org/dive4elements/river/importer/parsers/WaterlevelParser.java backend/src/main/java/org/dive4elements/river/utils/DateUtil.java
diffstat 8 files changed, 56 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightParser.java	Tue Jun 10 15:27:31 2014 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightParser.java	Thu Jun 12 12:21:55 2014 +0200
@@ -41,6 +41,7 @@
 import org.dive4elements.river.model.BedHeightType;
 import org.dive4elements.river.importer.ImporterSession;
 import org.dive4elements.river.utils.EpsilonComparator;
+import org.dive4elements.river.utils.DateUtil;
 
 public abstract class BedHeightParser {
 
@@ -233,8 +234,8 @@
                 int lower = Integer.valueOf(lo);
                 int upper = Integer.valueOf(up);
 
-                Date fromYear = LineParser.getStartDateFromYear(lower);
-                Date toYear   = LineParser.getEndDateFromYear(upper);
+                Date fromYear = DateUtil.getStartDateFromYear(lower);
+                Date toYear   = DateUtil.getEndDateFromYear(upper);
 
                 obj.setTimeInterval(new ImportTimeInterval(fromYear, toYear));
             }
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/LineParser.java	Tue Jun 10 15:27:31 2014 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/LineParser.java	Thu Jun 12 12:21:55 2014 +0200
@@ -14,7 +14,6 @@
 import java.text.NumberFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.util.Calendar;
 import java.util.Date;
 import java.util.Locale;
 
@@ -135,25 +134,5 @@
 
         return df.parse(dateString);
     }
-
-
-    /** Create Date on first moment (1st jan) of given year. */
-    public static Date getStartDateFromYear(int year) {
-        Calendar cal = Calendar.getInstance();
-        cal.clear();
-        cal.set(year, 0, 1, 0, 0, 0);
-
-        return cal.getTime();
-    }
-
-
-    /** Create Date on last moment (31st dec) of given year. */
-    public static Date getEndDateFromYear(int year) {
-        Calendar cal = Calendar.getInstance();
-        cal.clear();
-        cal.set(year, 11, 31, 23, 59, 59);
-
-        return cal.getTime();
-    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/PorosityParser.java	Tue Jun 10 15:27:31 2014 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/PorosityParser.java	Thu Jun 12 12:21:55 2014 +0200
@@ -12,6 +12,7 @@
 import org.dive4elements.river.importer.ImportPorosity;
 import org.dive4elements.river.importer.ImportPorosityValue;
 import org.dive4elements.river.importer.ImportTimeInterval;
+import org.dive4elements.river.utils.DateUtil;
 
 import java.io.File;
 import java.io.IOException;
@@ -110,8 +111,8 @@
                 int lower = Integer.valueOf(lo);
                 int upper = Integer.valueOf(up);
 
-                Date fromYear = LineParser.getStartDateFromYear(lower);
-                Date toYear   = LineParser.getEndDateFromYear(upper);
+                Date fromYear = DateUtil.getStartDateFromYear(lower);
+                Date toYear   = DateUtil.getEndDateFromYear(upper);
 
                 current.setTimeInterval(new ImportTimeInterval(fromYear, toYear));
             }
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/SQRelationParser.java	Tue Jun 10 15:27:31 2014 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/SQRelationParser.java	Thu Jun 12 12:21:55 2014 +0200
@@ -22,6 +22,7 @@
 import org.dive4elements.river.importer.ImportSQRelation;
 import org.dive4elements.river.importer.ImportSQRelationValue;
 import org.dive4elements.river.importer.ImportTimeInterval;
+import org.dive4elements.river.utils.DateUtil;
 
 
 public class SQRelationParser extends LineParser {
@@ -99,8 +100,8 @@
                 int high = nf.parse(hi).intValue();
 
                 current.setTimeInterval(new ImportTimeInterval(
-                    getStartDateFromYear(low),
-                    getEndDateFromYear(high)
+                    DateUtil.getStartDateFromYear(low),
+                    DateUtil.getEndDateFromYear(high)
                 ));
             }
             catch (ParseException nfe) {
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/SedimentYieldParser.java	Tue Jun 10 15:27:31 2014 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/SedimentYieldParser.java	Thu Jun 12 12:21:55 2014 +0200
@@ -27,6 +27,7 @@
 import org.dive4elements.river.importer.ImportTimeInterval;
 import org.dive4elements.river.importer.ImportUnit;
 import org.dive4elements.river.model.GrainFraction;
+import org.dive4elements.river.utils.DateUtil;
 
 
 /** Parses Sediment Yield files. */
@@ -275,8 +276,8 @@
                 int yearB = nf.parse(a.group(2)).intValue();
 
                 return new ImportTimeInterval(
-                    getStartDateFromYear(yearA),
-                    getEndDateFromYear(yearB)
+                    DateUtil.getStartDateFromYear(yearA),
+                    DateUtil.getEndDateFromYear(yearB)
                 );
             }
 
@@ -284,7 +285,7 @@
             if (b.matches()) {
                 int year = nf.parse(b.group(1)).intValue();
 
-                return new ImportTimeInterval(getStartDateFromYear(year));
+                return new ImportTimeInterval(DateUtil.getStartDateFromYear(year));
             }
 
             log.warn("SYP: Unknown time interval string: '" + column + "'");
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/WaterlevelDifferencesParser.java	Tue Jun 10 15:27:31 2014 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/WaterlevelDifferencesParser.java	Thu Jun 12 12:21:55 2014 +0200
@@ -27,6 +27,7 @@
 import org.dive4elements.river.importer.ImportWstQRange;
 import org.dive4elements.river.importer.ImportWstColumn;
 import org.dive4elements.river.importer.ImportWstColumnValue;
+import org.dive4elements.river.utils.DateUtil;
 
 
 /**
@@ -199,8 +200,8 @@
                 int startYear = Integer.parseInt(m.group(1));
                 int endYear   = Integer.parseInt(m.group(2));
                 ImportTimeInterval time = new ImportTimeInterval(
-                    getStartDateFromYear(startYear),
-                    getEndDateFromYear(endYear)
+                    DateUtil.getStartDateFromYear(startYear),
+                    DateUtil.getEndDateFromYear(endYear)
                 );
                 column.setTimeInterval(time);
             } else {
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/WaterlevelParser.java	Tue Jun 10 15:27:31 2014 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/WaterlevelParser.java	Thu Jun 12 12:21:55 2014 +0200
@@ -28,6 +28,7 @@
 import org.dive4elements.river.importer.ImportWstColumn;
 import org.dive4elements.river.importer.ImportWstColumnValue;
 import org.dive4elements.river.importer.ImportWstQRange;
+import org.dive4elements.river.utils.DateUtil;
 
 
 /**
@@ -102,8 +103,8 @@
             int startYear = Integer.parseInt(m.group(1));
             int endYear   = Integer.parseInt(m.group(2));
             ImportTimeInterval time = new ImportTimeInterval(
-                getStartDateFromYear(startYear),
-                getEndDateFromYear(endYear)
+                DateUtil.getStartDateFromYear(startYear),
+                DateUtil.getEndDateFromYear(endYear)
             );
             column.setTimeInterval(time);
         } else {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/backend/src/main/java/org/dive4elements/river/utils/DateUtil.java	Thu Jun 12 12:21:55 2014 +0200
@@ -0,0 +1,37 @@
+/* Copyright (C) 2014 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.utils;
+
+import java.util.Date;
+import java.util.Calendar;
+
+public final class DateUtil {
+
+    private DateUtil() {
+    }
+
+    /** Create Date on first moment (1st jan) of given year. */
+    public static Date getStartDateFromYear(int year) {
+        Calendar cal = Calendar.getInstance();
+        cal.clear();
+        cal.set(year, 0, 1, 0, 0, 0);
+
+        return cal.getTime();
+    }
+
+
+    /** Create Date on last moment (31st dec) of given year. */
+    public static Date getEndDateFromYear(int year) {
+        Calendar cal = Calendar.getInstance();
+        cal.clear();
+        cal.set(year, 11, 31, 23, 59, 59);
+
+        return cal.getTime();
+    }
+}

http://dive4elements.wald.intevation.org