changeset 8862:5b5bdce5a216

Introduced new number formats for some new data types Also using varargs in msg helper methods
author gernotbelger
date Fri, 19 Jan 2018 18:47:18 +0100
parents 571e5287dfbb
children 1009cab0f86b
files artifacts/src/main/java/org/dive4elements/river/exports/AbstractExporter.java artifacts/src/main/java/org/dive4elements/river/utils/Formatter.java
diffstat 2 files changed, 58 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/AbstractExporter.java	Fri Jan 19 18:46:20 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/AbstractExporter.java	Fri Jan 19 18:47:18 2018 +0100
@@ -94,6 +94,13 @@
 
     private NumberFormat qFormat;
 
+    private NumberFormat meanBedHeightFormat;
+
+    private NumberFormat tkhFormat;
+
+    private NumberFormat flowDepthFormat;
+
+    private NumberFormat w2Format;
 
     /**
      * Concrete subclasses need to use this method to write their special data
@@ -285,19 +292,19 @@
             request, XPATH_FACET, ArtifactNamespaceContext.INSTANCE);
     }
 
-    protected String msg(String key) {
+    protected String msg(final String key) {
         return Resources.getMsg(context.getMeta(), key, key);
     }
 
-    protected String msg(String key, String def) {
+    protected String msg(String key, final String def) {
         return Resources.getMsg(context.getMeta(), key, def);
     }
 
-    protected String msg(String key, Object[] args) {
+    protected String msg(final String key, final Object... args) {
         return Resources.getMsg(context.getMeta(), key, key, args);
     }
 
-    protected String msg(String key, String def, Object[] args) {
+    protected String msg(final String key, final String def, final Object args) {
         return Resources.getMsg(context.getMeta(), key, def, args);
     }
 
@@ -393,5 +400,29 @@
         }
         return qFormat;
     }
+    
+    protected final NumberFormat getMeanBedHeighFormatter() {
+        if( meanBedHeightFormat == null )
+            meanBedHeightFormat = Formatter.getMeanBedHeight(context); 
+        return meanBedHeightFormat;
+    }
+
+    protected final NumberFormat getTkhFormatter() {
+        if( tkhFormat == null )
+            tkhFormat = Formatter.getTkh(context);
+        return tkhFormat;
+    }
+
+    protected final NumberFormat getFlowDepthFormatter() {
+        if( flowDepthFormat == null )
+            flowDepthFormat = Formatter.getFlowDepth(context);
+        return flowDepthFormat;
+    }
+
+    protected final NumberFormat getW2Formatter() {
+        if( w2Format == null )
+            w2Format = Formatter.getFlowDepth(context);
+        return w2Format;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/artifacts/src/main/java/org/dive4elements/river/utils/Formatter.java	Fri Jan 19 18:46:20 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/utils/Formatter.java	Fri Jan 19 18:47:18 2018 +0100
@@ -489,5 +489,28 @@
         Locale locale = Resources.getLocale(m);
         return new SimpleDateFormat(pattern, locale);
     }
+
+    public static NumberFormat getMeanBedHeight(CallContext context) {
+        return Formatter.getFormatter(context, 2, 2);
+    }
+
+    public static NumberFormat getTkh(CallContext context) {
+        return Formatter.getFormatter(context, 1, 1);
+    }
+
+    public static NumberFormat getFlowDepth(CallContext context) {
+        return Formatter.getFormatter(context, 2, 2);
+    }
+
+    public static NumberFormat getW(CallContext context) {
+        return Formatter.getFormatter(context, 2, 2);
+    }
+
+    /**
+     * Another waterlevel formatter with fixed digits (always 2)
+     */
+    public static NumberFormat getWaterlevelW2(CallMeta meta) {
+        return getFormatter( meta, 2, 2);
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org