changeset 1616:ff8312688cd5

Added utility functions for double arrays. flys-client/trunk@3985 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 09 Feb 2012 09:50:22 +0000
parents 07c38d054f91
children f13a7c126f24
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/shared/DoubleUtils.java
diffstat 2 files changed, 33 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Thu Feb 09 08:51:00 2012 +0000
+++ b/flys-client/ChangeLog	Thu Feb 09 09:50:22 2012 +0000
@@ -1,3 +1,9 @@
+2012-02-09	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/shared/DoubleUtils.java:
+	  (fill,copyOf): Pendant to java.util.Arrays, which misbehaves with
+			 GWT.
+
 2012-02-09	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/ui/LocationPanel.java,
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/DoubleUtils.java	Thu Feb 09 08:51:00 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/DoubleUtils.java	Thu Feb 09 09:50:22 2012 +0000
@@ -50,5 +50,32 @@
             ? mm
             : null;
     }
+
+    /** toIndex is not inclusive, fromIndex is. */
+    static void fill(double[] array, int fromIndex, int toIndex, double val) {
+        for (int i = fromIndex; i < toIndex; i++) {
+            array[i] = val;
+        }
+    }
+
+    /** @see java.util.Arrays.copyOf */
+    public static double[] copyOf(double[] toCopy, int newLen) {
+        double[] nArray = new double[newLen];
+
+        if (toCopy == null) {
+            fill(nArray, 0, nArray.length, 0d);
+            return nArray;
+        }
+
+        int goTo = (newLen < toCopy.length)
+            ? newLen
+            : toCopy.length; 
+
+        for (int i = 0; i < goTo; i++) {
+            nArray[i] = toCopy[i];
+        }
+        fill (nArray, goTo, nArray.length, 0d);
+        return nArray;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org