# HG changeset patch # User Felix Wolfsteller # Date 1328781022 0 # Node ID ff8312688cd511ef572e0ac50dd8938fcf4fb538 # Parent 07c38d054f91acf391e1cd2613f0412346ec6989 Added utility functions for double arrays. flys-client/trunk@3985 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 07c38d054f91 -r ff8312688cd5 flys-client/ChangeLog --- 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 + + * 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 * src/main/java/de/intevation/flys/client/client/ui/LocationPanel.java, diff -r 07c38d054f91 -r ff8312688cd5 flys-client/src/main/java/de/intevation/flys/client/shared/DoubleUtils.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 :