fixed another set of warnings identified by recent findbugs versions

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@790368 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2009-07-01 20:31:50 +00:00
parent 1a303e82db
commit 121f832ef9
6 changed files with 81 additions and 37 deletions

View File

@ -203,6 +203,11 @@
<Method name="testNewNewtonSolverNull" params="" returns="void" />
<Bug pattern="NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS" />
</Match>
<Match>
<Class name="org.apache.commons.math.stat.regression.OLSMultipleLinearRegressionTest" />
<Method name="cannotAddNullYSampleData" params="" returns="void" />
<Bug pattern="NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS" />
</Match>
<!-- IntDoublePair intentionally implements Comparable inconsistently with equals -->
<Match>

View File

@ -18,7 +18,6 @@
package org.apache.commons.math.ode.nonstiff;
import org.apache.commons.math.linear.Array2DRowRealMatrix;
import org.apache.commons.math.linear.RealMatrix;
import org.apache.commons.math.ode.DerivativeException;
import org.apache.commons.math.ode.FirstOrderDifferentialEquations;
import org.apache.commons.math.ode.IntegratorException;

View File

@ -19,6 +19,8 @@ package org.apache.commons.math.stat.descriptive;
import java.io.Serializable;
import org.apache.commons.math.util.MathUtils;
/**
* <p>
* A StatisticalSummary that aggregates statistics from several data sets or
@ -242,5 +244,35 @@ public class AggregateSummaryStatistics implements StatisticalSummary,
aggregateStatistics.addValue(value);
}
}
/**
* Returns true iff <code>object</code> is a
* <code>SummaryStatistics</code> instance and all statistics have the
* same values as this.
* @param object the object to test equality against.
* @return true if object equals this
*/
@Override
public boolean equals(Object object) {
if (object == this) {
return true;
}
if (object instanceof AggregatingSummaryStatistics == false) {
return false;
}
AggregatingSummaryStatistics stat = (AggregatingSummaryStatistics)object;
return (super.equals(stat) &&
aggregateStatistics.equals(stat.aggregateStatistics));
}
/**
* Returns hash code based on values of statistics
* @return hash code
*/
@Override
public int hashCode() {
return 123 + super.hashCode() + aggregateStatistics.hashCode();
}
}
}

View File

@ -629,7 +629,7 @@ public class GaussNewtonEstimatorTest
}
public void addPoint(double px, double py) {
points.add(new PointModel(px, py));
points.add(new PointModel(this, px, py));
}
public int getM() {
@ -680,45 +680,47 @@ public class GaussNewtonEstimatorTest
return cy.getEstimate();
}
private class PointModel extends WeightedMeasurement {
private static class PointModel extends WeightedMeasurement {
public PointModel(double px, double py) {
public PointModel(Circle circle, double px, double py) {
super(1.0, 0.0);
this.px = px;
this.py = py;
this.circle = circle;
}
@Override
public double getPartial(EstimatedParameter parameter) {
if (parameter == cx) {
return getPartialDiX() - getPartialRadiusX();
} else if (parameter == cy) {
return getPartialDiY() - getPartialRadiusY();
if (parameter == circle.cx) {
return getPartialDiX() - circle.getPartialRadiusX();
} else if (parameter == circle.cy) {
return getPartialDiY() - circle.getPartialRadiusY();
}
return 0;
}
public double getCenterDistance() {
double dx = px - cx.getEstimate();
double dy = py - cy.getEstimate();
double dx = px - circle.cx.getEstimate();
double dy = py - circle.cy.getEstimate();
return Math.sqrt(dx * dx + dy * dy);
}
public double getPartialDiX() {
return (cx.getEstimate() - px) / getCenterDistance();
return (circle.cx.getEstimate() - px) / getCenterDistance();
}
public double getPartialDiY() {
return (cy.getEstimate() - py) / getCenterDistance();
return (circle.cy.getEstimate() - py) / getCenterDistance();
}
@Override
public double getTheoreticalValue() {
return getCenterDistance() - getRadius();
return getCenterDistance() - circle.getRadius();
}
private double px;
private double py;
private transient final Circle circle;
private static final long serialVersionUID = 1L;
}

View File

@ -674,7 +674,7 @@ public class LevenbergMarquardtEstimatorTest
}
public void addPoint(double px, double py) {
points.add(new PointModel(px, py));
points.add(new PointModel(this, px, py));
}
public int getM() {
@ -725,45 +725,47 @@ public class LevenbergMarquardtEstimatorTest
return cy.getEstimate();
}
private class PointModel extends WeightedMeasurement {
private static class PointModel extends WeightedMeasurement {
public PointModel(double px, double py) {
public PointModel(Circle circle, double px, double py) {
super(1.0, 0.0);
this.px = px;
this.py = py;
this.circle = circle;
}
@Override
public double getPartial(EstimatedParameter parameter) {
if (parameter == cx) {
return getPartialDiX() - getPartialRadiusX();
} else if (parameter == cy) {
return getPartialDiY() - getPartialRadiusY();
if (parameter == circle.cx) {
return getPartialDiX() - circle.getPartialRadiusX();
} else if (parameter == circle.cy) {
return getPartialDiY() - circle.getPartialRadiusY();
}
return 0;
}
public double getCenterDistance() {
double dx = px - cx.getEstimate();
double dy = py - cy.getEstimate();
double dx = px - circle.cx.getEstimate();
double dy = py - circle.cy.getEstimate();
return Math.sqrt(dx * dx + dy * dy);
}
public double getPartialDiX() {
return (cx.getEstimate() - px) / getCenterDistance();
return (circle.cx.getEstimate() - px) / getCenterDistance();
}
public double getPartialDiY() {
return (cy.getEstimate() - py) / getCenterDistance();
return (circle.cy.getEstimate() - py) / getCenterDistance();
}
@Override
public double getTheoreticalValue() {
return getCenterDistance() - getRadius();
return getCenterDistance() - circle.getRadius();
}
private double px;
private double py;
private transient final Circle circle;
private static final long serialVersionUID = 1L;
}
@ -790,7 +792,7 @@ public class LevenbergMarquardtEstimatorTest
}
public void addPoint(double x, double y, double w) {
addMeasurement(new LocalMeasurement(x, y, w));
addMeasurement(new LocalMeasurement(this, x, y, w));
}
public double theoreticalValue(double x) {
@ -807,25 +809,27 @@ public class LevenbergMarquardtEstimatorTest
}
}
private class LocalMeasurement extends WeightedMeasurement {
private static class LocalMeasurement extends WeightedMeasurement {
private static final long serialVersionUID = 1555043155023729130L;
private final double x;
private transient final QuadraticProblem pb;
// constructor
public LocalMeasurement(double x, double y, double w) {
public LocalMeasurement(QuadraticProblem pb, double x, double y, double w) {
super(w, y);
this.x = x;
this.pb = pb;
}
@Override
public double getTheoreticalValue() {
return theoreticalValue(x);
return pb.theoreticalValue(x);
}
@Override
public double getPartial(EstimatedParameter parameter) {
return partial(x, parameter);
return pb.partial(x, parameter);
}
}

View File

@ -568,7 +568,7 @@ public class MinpackTest
public WeightedMeasurement[] getMeasurements() {
WeightedMeasurement[] measurements = new WeightedMeasurement[m];
for (int i = 0; i < m; ++i) {
measurements[i] = new MinpackMeasurement(i);
measurements[i] = new MinpackMeasurement(this, i);
}
return measurements;
}
@ -585,11 +585,12 @@ public class MinpackTest
protected abstract double[] getResiduals();
private class MinpackMeasurement extends WeightedMeasurement {
private static class MinpackMeasurement extends WeightedMeasurement {
public MinpackMeasurement(int index) {
public MinpackMeasurement(MinpackFunction f, int index) {
super(1.0, 0.0);
this.index = index;
this.f = f;
}
@Override
@ -598,7 +599,7 @@ public class MinpackTest
// each time we need only one element, but it is only for test
// purposes and is simpler to check.
// This implementation should NOT be taken as an example, it is ugly!
return getResiduals()[index];
return f.getResiduals()[index];
}
@Override
@ -607,15 +608,16 @@ public class MinpackTest
// each time we need only one element, but it is only for test
// purposes and is simpler to check.
// This implementation should NOT be taken as an example, it is ugly!
for (int j = 0; j < n; ++j) {
if (parameter == parameters[j]) {
return getJacobian()[index][j];
for (int j = 0; j < f.n; ++j) {
if (parameter == f.parameters[j]) {
return f.getJacobian()[index][j];
}
}
return 0;
}
private int index;
private transient final MinpackFunction f;
private static final long serialVersionUID = 1L;
}