ref #9541 move distance formatting to own formatting class
authorAndreas Müller <a.mueller@bgbm.org>
Wed, 31 Mar 2021 19:28:22 +0000 (21:28 +0200)
committerAndreas Müller <a.mueller@bgbm.org>
Wed, 31 Mar 2021 19:28:22 +0000 (21:28 +0200)
cdmlib-model/src/main/java/eu/etaxonomy/cdm/format/occurrences/DistanceStringFormatter.java [new file with mode: 0644]
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/facade/DerivedUnitFacade.java

diff --git a/cdmlib-model/src/main/java/eu/etaxonomy/cdm/format/occurrences/DistanceStringFormatter.java b/cdmlib-model/src/main/java/eu/etaxonomy/cdm/format/occurrences/DistanceStringFormatter.java
new file mode 100644 (file)
index 0000000..8d0f321
--- /dev/null
@@ -0,0 +1,43 @@
+/**
+* Copyright (C) 2021 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.cdm.format.occurrences;
+
+import org.apache.commons.lang3.StringUtils;
+
+import eu.etaxonomy.cdm.common.CdmUtils;
+import eu.etaxonomy.cdm.common.UTF8;
+
+/**
+ * @author a.mueller
+ * @since 31.03.2021
+ */
+public class DistanceStringFormatter {
+
+    /**
+     * Computes the correct distance string for given values for min, max and text.
+     * If text is not blank, text is returned, otherwise "min - max" or a single value is returned.
+     * @param min min value as number
+     * @param max max value as number
+     * @param text text representation of distance
+     * @return the formatted distance string
+     */
+    public static String distanceString(Number min, Number max, String text, String unit) {
+        if (StringUtils.isNotBlank(text)){
+            return text;
+        }else{
+            String minStr = min == null? null : String.valueOf(min);
+            String maxStr = max == null? null : String.valueOf(max);
+            String result = CdmUtils.concat(UTF8.EN_DASH_SPATIUM.toString(), minStr, maxStr);
+            if (StringUtils.isNotBlank(result) && StringUtils.isNotBlank(unit)){
+                result = result + " " + unit;
+            }
+            return result;
+        }
+    }
+}
index 7e88f288b192a87e5aa5f7b7174269739a293d0c..3bcfa5ad7c67c51ffbbb2fbb6f91d65a603c3059 100644 (file)
@@ -24,9 +24,8 @@ import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
 
 import eu.etaxonomy.cdm.api.service.IOccurrenceService;
 import org.apache.log4j.Logger;
 
 import eu.etaxonomy.cdm.api.service.IOccurrenceService;
-import eu.etaxonomy.cdm.common.CdmUtils;
 import eu.etaxonomy.cdm.common.URI;
 import eu.etaxonomy.cdm.common.URI;
-import eu.etaxonomy.cdm.common.UTF8;
+import eu.etaxonomy.cdm.format.occurrences.DistanceStringFormatter;
 import eu.etaxonomy.cdm.model.agent.AgentBase;
 import eu.etaxonomy.cdm.model.agent.Person;
 import eu.etaxonomy.cdm.model.common.Annotation;
 import eu.etaxonomy.cdm.model.agent.AgentBase;
 import eu.etaxonomy.cdm.model.agent.Person;
 import eu.etaxonomy.cdm.model.common.Annotation;
@@ -983,7 +982,7 @@ public class DerivedUnitFacade {
                                String text = ev.getAbsoluteElevationText();
                                Integer min = getAbsoluteElevation();
                                Integer max = getAbsoluteElevationMaximum();
                                String text = ev.getAbsoluteElevationText();
                                Integer min = getAbsoluteElevation();
                                Integer max = getAbsoluteElevationMaximum();
-                               return distanceString(min, max, text, METER);
+                               return DistanceStringFormatter.distanceString(min, max, text, METER);
                        }
                }
        }
                        }
                }
        }
@@ -1094,7 +1093,7 @@ public class DerivedUnitFacade {
                        String text = ev.getDistanceToGroundText();
                        Double min = getDistanceToGround();
                        Double max = getDistanceToGroundMax();
                        String text = ev.getDistanceToGroundText();
                        Double min = getDistanceToGround();
                        Double max = getDistanceToGroundMax();
-                       return distanceString(min, max, text, METER);
+                       return DistanceStringFormatter.distanceString(min, max, text, METER);
                }
        }
 
                }
        }
 
@@ -1170,7 +1169,7 @@ public class DerivedUnitFacade {
                        String text = ev.getDistanceToWaterSurfaceText();
                        Double min = getDistanceToWaterSurface();
                        Double max = getDistanceToWaterSurfaceMax();
                        String text = ev.getDistanceToWaterSurfaceText();
                        Double min = getDistanceToWaterSurface();
                        Double max = getDistanceToWaterSurfaceMax();
-                       return distanceString(min, max, text, METER);
+                       return DistanceStringFormatter.distanceString(min, max, text, METER);
                }
        }
 
                }
        }
 
@@ -2589,27 +2588,7 @@ public class DerivedUnitFacade {
        }
 
 
        }
 
 
-       /**
-        * Computes the correct distance string for given values for min, max and text.
-        * If text is not blank, text is returned, otherwise "min - max" or a single value is returned.
-        * @param min min value as number
-        * @param max max value as number
-        * @param text text representation of distance
-        * @return the formatted distance string
-        */
-       public static String distanceString(Number min, Number max, String text, String unit) {
-               if (StringUtils.isNotBlank(text)){
-                       return text;
-               }else{
-                       String minStr = min == null? null : String.valueOf(min);
-                       String maxStr = max == null? null : String.valueOf(max);
-                       String result = CdmUtils.concat(UTF8.EN_DASH_SPATIUM.toString(), minStr, maxStr);
-                       if (StringUtils.isNotBlank(result) && StringUtils.isNotBlank(unit)){
-                               result = result + " " + unit;
-                       }
-                       return result;
-               }
-       }
+
 
        /**
         * First checks the inner field unit for the publish flag. If set to <code>true</code>
 
        /**
         * First checks the inner field unit for the publish flag. If set to <code>true</code>