From 730e17083e45c6fa8015d47a79263aee416035ca Mon Sep 17 00:00:00 2001 From: Gilles Sadowski Date: Mon, 19 Jul 2010 14:51:24 +0000 Subject: [PATCH] MATH-387: Allow "null" array arguments in "RealPointValuePair" and "VectorialPointValuePair" constructors. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@965509 13f79535-47bb-0310-9956-ffa450edef68 --- .../math/optimization/RealPointValuePair.java | 12 ++++++------ .../optimization/SimpleScalarValueChecker.java | 3 +-- .../optimization/VectorialPointValuePair.java | 16 ++++++++++------ 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/apache/commons/math/optimization/RealPointValuePair.java b/src/main/java/org/apache/commons/math/optimization/RealPointValuePair.java index 3848e3868..39c8704ac 100644 --- a/src/main/java/org/apache/commons/math/optimization/RealPointValuePair.java +++ b/src/main/java/org/apache/commons/math/optimization/RealPointValuePair.java @@ -29,7 +29,6 @@ import java.io.Serializable; * @since 2.0 */ public class RealPointValuePair implements Serializable { - /** Serializable version identifier. */ private static final long serialVersionUID = 1003888396256744753L; @@ -45,7 +44,7 @@ public class RealPointValuePair implements Serializable { * @param value value of an objective function at the point */ public RealPointValuePair(final double[] point, final double value) { - this.point = point.clone(); + this.point = (point == null ? null : point.clone()); this.value = value; } @@ -57,8 +56,10 @@ public class RealPointValuePair implements Serializable { * it will be referenced */ public RealPointValuePair(final double[] point, final double value, - final boolean copyArray) { - this.point = copyArray ? point.clone() : point; + final boolean copyArray) { + this.point = (copyArray ? + (point == null ? null : point.clone()) : + point); this.value = value; } @@ -66,7 +67,7 @@ public class RealPointValuePair implements Serializable { * @return a copy of the stored point */ public double[] getPoint() { - return point.clone(); + return (point == null ? null : point.clone()); } /** Get a reference to the point. @@ -84,5 +85,4 @@ public class RealPointValuePair implements Serializable { public double getValue() { return value; } - } diff --git a/src/main/java/org/apache/commons/math/optimization/SimpleScalarValueChecker.java b/src/main/java/org/apache/commons/math/optimization/SimpleScalarValueChecker.java index b58834af7..b7dd0c087 100644 --- a/src/main/java/org/apache/commons/math/optimization/SimpleScalarValueChecker.java +++ b/src/main/java/org/apache/commons/math/optimization/SimpleScalarValueChecker.java @@ -62,7 +62,7 @@ public class SimpleScalarValueChecker implements RealConvergenceChecker { * @param absoluteThreshold absolute tolerance threshold */ public SimpleScalarValueChecker(final double relativeThreshold, - final double absoluteThreshold) { + final double absoluteThreshold) { this.relativeThreshold = relativeThreshold; this.absoluteThreshold = absoluteThreshold; } @@ -77,5 +77,4 @@ public class SimpleScalarValueChecker implements RealConvergenceChecker { final double size = Math.max(Math.abs(p), Math.abs(c)); return (difference <= (size * relativeThreshold)) || (difference <= absoluteThreshold); } - } diff --git a/src/main/java/org/apache/commons/math/optimization/VectorialPointValuePair.java b/src/main/java/org/apache/commons/math/optimization/VectorialPointValuePair.java index a2d72306b..24ba8fce2 100644 --- a/src/main/java/org/apache/commons/math/optimization/VectorialPointValuePair.java +++ b/src/main/java/org/apache/commons/math/optimization/VectorialPointValuePair.java @@ -44,8 +44,8 @@ public class VectorialPointValuePair implements Serializable { * @param value value of an objective function at the point */ public VectorialPointValuePair(final double[] point, final double[] value) { - this.point = point.clone(); - this.value = value.clone(); + this.point = (point == null ? null : point.clone()); + this.value = (value == null ? null : value.clone()); } /** Build a point/objective function value pair. @@ -57,15 +57,19 @@ public class VectorialPointValuePair implements Serializable { */ public VectorialPointValuePair(final double[] point, final double[] value, final boolean copyArray) { - this.point = copyArray ? point.clone() : point; - this.value = copyArray ? value.clone() : value; + this.point = (copyArray ? + (point == null ? null : point.clone()) : + point); + this.value = (copyArray ? + (value == null ? null : value.clone()) : + value); } /** Get the point. * @return a copy of the stored point */ public double[] getPoint() { - return point.clone(); + return (point == null ? null : point.clone()); } /** Get a reference to the point. @@ -81,7 +85,7 @@ public class VectorialPointValuePair implements Serializable { * @return a copy of the stored value of the objective function */ public double[] getValue() { - return value.clone(); + return (value == null ? null : value.clone()); } /** Get a reference to the value of the objective function.