Java 5 is already eol. Anybody still using it is certainly in maintenance
mode thus adding now a feature that is available in java 6 does not make
any sense.
On 20 Jun 2014 15:38, <er...@apache.org> wrote:

> Author: erans
> Date: Fri Jun 20 13:37:42 2014
> New Revision: 1604172
>
> URL: http://svn.apache.org/r1604172
> Log:
> MATH-1130
> Method "copyOfRange" (available as of Java 6 in "java.util.Arrays").
>
> Modified:
>
> commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/MathArrays.java
>
> commons/proper/math/trunk/src/test/java/org/apache/commons/math3/util/MathArraysTest.java
>
> Modified:
> commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/MathArrays.java
> URL:
> http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/MathArrays.java?rev=1604172&r1=1604171&r2=1604172&view=diff
>
> ==============================================================================
> ---
> commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/MathArrays.java
> (original)
> +++
> commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/MathArrays.java
> Fri Jun 20 13:37:42 2014
> @@ -799,6 +799,21 @@ public class MathArrays {
>       }
>
>      /**
> +     * Creates a copy of the {@code source} array.
> +     *
> +     * @param source Array to be copied.
> +     * @param from Initial index of the range to be copied, inclusive.
> +     * @param to Final index of the range to be copied, exclusive. (This
> index may lie outside the array.)
> +     * @return the copied array.
> +     */
> +    public static double[] copyOfRange(double[] source, int from, int to)
> {
> +        final int len = to - from;
> +        final double[] output = new double[len];
> +        System.arraycopy(source, from, output, 0, FastMath.min(len,
> source.length - from));
> +        return output;
> +     }
> +
> +    /**
>       * Compute a linear combination accurately.
>       * This method computes the sum of the products
>       * <code>a<sub>i</sub> b<sub>i</sub></code> to high accuracy.
>
> Modified:
> commons/proper/math/trunk/src/test/java/org/apache/commons/math3/util/MathArraysTest.java
> URL:
> http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/util/MathArraysTest.java?rev=1604172&r1=1604171&r2=1604172&view=diff
>
> ==============================================================================
> ---
> commons/proper/math/trunk/src/test/java/org/apache/commons/math3/util/MathArraysTest.java
> (original)
> +++
> commons/proper/math/trunk/src/test/java/org/apache/commons/math3/util/MathArraysTest.java
> Fri Jun 20 13:37:42 2014
> @@ -588,6 +588,29 @@ public class MathArraysTest {
>          }
>      }
>
> +    @Test
> +    public void testCopyOfRange() {
> +        final double[] source = { Double.NEGATIVE_INFINITY,
> +                                  -Double.MAX_VALUE,
> +                                  -1, 0,
> +                                  Double.MIN_VALUE,
> +                                  FastMath.ulp(1d),
> +                                  1, 3, 113, 4769,
> +                                  Double.MAX_VALUE,
> +                                  Double.POSITIVE_INFINITY };
> +        final int from = 3;
> +        final int to = source.length + 14;
> +        final double[] dest = MathArrays.copyOfRange(source, from, to);
> +
> +        Assert.assertEquals(dest.length, to - from);
> +        for (int i = from; i < source.length; i++) {
> +            Assert.assertEquals(source[i], dest[i - from], 0);
> +        }
> +        for (int i = source.length; i < dest.length; i++) {
> +            Assert.assertEquals(0, dest[i - from], 0);
> +        }
> +    }
> +
>      // MATH-1005
>      @Test
>      public void testLinearCombinationWithSingleElementArray() {
>
>
>

Reply via email to