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
This commit is contained in:
Gilles Sadowski 2010-07-19 14:51:24 +00:00
parent 968c4a2cf4
commit 730e17083e
3 changed files with 17 additions and 14 deletions

View File

@ -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;
}
}

View File

@ -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);
}
}

View File

@ -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.