From 2e405f1724a9f9ad62a26b361adb05d277c916cf Mon Sep 17 00:00:00 2001 From: Luc Maisonobe Date: Sun, 18 Jan 2009 16:57:29 +0000 Subject: [PATCH] fixed various minor bugs identified by checkstyle and findbugs git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@735501 13f79535-47bb-0310-9956-ffa450edef68 --- findbugs-exclude-filter.xml | 5 + pom.xml | 8 +- .../analysis/minimization/BrentMinimizer.java | 7 +- .../UnivariateRealMinimizerImpl.java | 24 +--- .../solvers/UnivariateRealSolver.java | 4 +- .../solvers/UnivariateRealSolverImpl.java | 2 +- .../ode/SecondOrderDifferentialEquations.java | 4 +- .../transform/FastFourierTransformer.java | 25 ++-- .../math/util/OpenIntToDoubleHashMap.java | 15 +++ .../math/util/ResizableDoubleArray.java | 16 ++- src/site/xdoc/userguide/index.xml | 121 +++++++++--------- 11 files changed, 115 insertions(+), 116 deletions(-) diff --git a/findbugs-exclude-filter.xml b/findbugs-exclude-filter.xml index eec93c367..18b143ce6 100644 --- a/findbugs-exclude-filter.xml +++ b/findbugs-exclude-filter.xml @@ -25,6 +25,11 @@ + + + + + diff --git a/pom.xml b/pom.xml index e1ce6ec1c..11eecf371 100644 --- a/pom.xml +++ b/pom.xml @@ -224,11 +224,10 @@ - org.codehaus.mojo clirr-maven-plugin @@ -264,13 +262,11 @@ ${basedir}/findbugs-exclude-filter.xml - org.apache.maven.plugins maven-changes-plugin diff --git a/src/java/org/apache/commons/math/analysis/minimization/BrentMinimizer.java b/src/java/org/apache/commons/math/analysis/minimization/BrentMinimizer.java index c50ae7f83..85de72e40 100644 --- a/src/java/org/apache/commons/math/analysis/minimization/BrentMinimizer.java +++ b/src/java/org/apache/commons/math/analysis/minimization/BrentMinimizer.java @@ -16,7 +16,6 @@ */ package org.apache.commons.math.analysis.minimization; -import org.apache.commons.math.ConvergenceException; import org.apache.commons.math.FunctionEvaluationException; import org.apache.commons.math.MaxIterationsExceededException; import org.apache.commons.math.analysis.UnivariateRealFunction; @@ -56,7 +55,7 @@ public class BrentMinimizer extends UnivariateRealMinimizerImpl { * @param max the upper bound for the interval. * @param startValue this parameter is not used at all * @return a value where the function is minimum - * @throws ConvergenceException if the maximum iteration count is exceeded + * @throws MaxIterationsExceededException if the maximum iteration count is exceeded * or the minimizer detects convergence problems otherwise. * @throws FunctionEvaluationException if an error occurs evaluating the * function @@ -75,7 +74,7 @@ public class BrentMinimizer extends UnivariateRealMinimizerImpl { throws MaxIterationsExceededException, FunctionEvaluationException { clearResult(); - return localmin(min, max, relativeAccuracy, absoluteAccuracy, f); + return localMin(min, max, relativeAccuracy, absoluteAccuracy, f); } /** @@ -101,7 +100,7 @@ public class BrentMinimizer extends UnivariateRealMinimizerImpl { * @throws FunctionEvaluationException if an error occurs evaluating * the function. */ - private double localmin(double a, double b, final double eps, + private double localMin(double a, double b, final double eps, final double t, final UnivariateRealFunction f) throws MaxIterationsExceededException, FunctionEvaluationException { double x = a + c * (b - a); diff --git a/src/java/org/apache/commons/math/analysis/minimization/UnivariateRealMinimizerImpl.java b/src/java/org/apache/commons/math/analysis/minimization/UnivariateRealMinimizerImpl.java index 67e50c021..cc5588125 100644 --- a/src/java/org/apache/commons/math/analysis/minimization/UnivariateRealMinimizerImpl.java +++ b/src/java/org/apache/commons/math/analysis/minimization/UnivariateRealMinimizerImpl.java @@ -33,12 +33,6 @@ public abstract class UnivariateRealMinimizerImpl /** Serializable version identifier. */ private static final long serialVersionUID = 4543031162377070699L; -// /** Maximum error of function. */ -// protected double functionValueAccuracy; -// -// /** Default maximum error of function. */ -// protected double defaultFunctionValueAccuracy; - /** Indicates where a root has been computed. */ protected boolean resultComputed = false; @@ -59,13 +53,12 @@ public abstract class UnivariateRealMinimizerImpl protected UnivariateRealMinimizerImpl(int defaultMaximalIterationCount, double defaultAbsoluteAccuracy) { super(defaultMaximalIterationCount, defaultAbsoluteAccuracy); -// this.functionValueAccuracy = defaultFunctionValueAccuracy; } /** Check if a result has been computed. * @exception IllegalStateException if no result has been computed */ - protected void checkResultComputed() throws IllegalArgumentException { + protected void checkResultComputed() throws IllegalStateException { if (!resultComputed) { throw MathRuntimeException.createIllegalStateException("no result available", null); } @@ -83,21 +76,6 @@ public abstract class UnivariateRealMinimizerImpl return functionValue; } -// /** {@inheritDoc} */ -// public void setFunctionValueAccuracy(double accuracy) { -// functionValueAccuracy = accuracy; -// } -// -// /** {@inheritDoc} */ -// public double getFunctionValueAccuracy() { -// return functionValueAccuracy; -// } -// -// /** {@inheritDoc} */ -// public void resetFunctionValueAccuracy() { -// functionValueAccuracy = defaultFunctionValueAccuracy; -// } - /** * Convenience function for implementations. * diff --git a/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolver.java b/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolver.java index f7936cd1d..f74b510a7 100644 --- a/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolver.java +++ b/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolver.java @@ -117,7 +117,7 @@ public interface UnivariateRealSolver extends ConvergingAlgorithm { */ @Deprecated double solve(double min, double max, double startValue) - throws ConvergenceException, FunctionEvaluationException; + throws ConvergenceException, FunctionEvaluationException, IllegalArgumentException; /** * Solve for a zero in the given interval, start at startValue. @@ -137,7 +137,7 @@ public interface UnivariateRealSolver extends ConvergingAlgorithm { * @since 2.0 */ double solve(UnivariateRealFunction f, double min, double max, double startValue) - throws ConvergenceException, FunctionEvaluationException; + throws ConvergenceException, FunctionEvaluationException, IllegalArgumentException; /** * Get the result of the last run of the solver. diff --git a/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverImpl.java b/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverImpl.java index 4fffb5d3e..feef7cef8 100644 --- a/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverImpl.java +++ b/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverImpl.java @@ -102,7 +102,7 @@ public abstract class UnivariateRealSolverImpl /** Check if a result has been computed. * @exception IllegalStateException if no result has been computed */ - protected void checkResultComputed() throws IllegalArgumentException { + protected void checkResultComputed() throws IllegalStateException { if (!resultComputed) { throw MathRuntimeException.createIllegalStateException("no result available", null); } diff --git a/src/java/org/apache/commons/math/ode/SecondOrderDifferentialEquations.java b/src/java/org/apache/commons/math/ode/SecondOrderDifferentialEquations.java index e813df1f3..10a5d4ca3 100644 --- a/src/java/org/apache/commons/math/ode/SecondOrderDifferentialEquations.java +++ b/src/java/org/apache/commons/math/ode/SecondOrderDifferentialEquations.java @@ -17,6 +17,8 @@ package org.apache.commons.math.ode; +import java.io.Serializable; + /** This interface represents a second order differential equations set. *

This interface should be implemented by all real second order @@ -44,7 +46,7 @@ package org.apache.commons.math.ode; * @since 1.2 */ -public interface SecondOrderDifferentialEquations { +public interface SecondOrderDifferentialEquations extends Serializable { /** Get the dimension of the problem. * @return dimension of the problem diff --git a/src/java/org/apache/commons/math/transform/FastFourierTransformer.java b/src/java/org/apache/commons/math/transform/FastFourierTransformer.java index 1e0626b90..710944cff 100644 --- a/src/java/org/apache/commons/math/transform/FastFourierTransformer.java +++ b/src/java/org/apache/commons/math/transform/FastFourierTransformer.java @@ -722,9 +722,12 @@ public class FastFourierTransformer implements Serializable { */ public Complex set(Complex magnitude, int... vector) throws IllegalArgumentException { - if (vector == null && dimensionSize.length > 1) { - throw MathRuntimeException.createIllegalArgumentException("some dimensions don't math: {0} != {1}", - new Object[] { 0, dimensionSize.length }); + if (vector == null) { + if (dimensionSize.length > 1) { + throw MathRuntimeException.createIllegalArgumentException("some dimensions don't math: {0} != {1}", + new Object[] { 0, dimensionSize.length }); + } + return null; } if (vector != null && vector.length != dimensionSize.length) { throw MathRuntimeException.createIllegalArgumentException("some dimensions don't math: {0} != {1}", @@ -733,17 +736,15 @@ public class FastFourierTransformer implements Serializable { dimensionSize.length }); } - - Object lastDimension = multiDimensionalComplexArray; - + + Object[] lastDimension = (Object[]) multiDimensionalComplexArray; for (int i = 0; i < dimensionSize.length - 1; i++) { - lastDimension = ((Object[]) lastDimension)[vector[i]]; + lastDimension = (Object[]) lastDimension[vector[i]]; } - - Complex lastValue = (Complex) ((Object[]) - lastDimension)[vector[dimensionSize.length - 1]]; - ((Object[]) lastDimension)[vector[dimensionSize.length - 1]] = - magnitude; + + Complex lastValue = (Complex) lastDimension[vector[dimensionSize.length - 1]]; + lastDimension[vector[dimensionSize.length - 1]] = magnitude; + return lastValue; } diff --git a/src/java/org/apache/commons/math/util/OpenIntToDoubleHashMap.java b/src/java/org/apache/commons/math/util/OpenIntToDoubleHashMap.java index 3a6fd87fb..adb1060bb 100644 --- a/src/java/org/apache/commons/math/util/OpenIntToDoubleHashMap.java +++ b/src/java/org/apache/commons/math/util/OpenIntToDoubleHashMap.java @@ -17,6 +17,8 @@ package org.apache.commons.math.util; +import java.io.IOException; +import java.io.ObjectInputStream; import java.io.Serializable; import java.util.ConcurrentModificationException; import java.util.NoSuchElementException; @@ -579,4 +581,17 @@ public class OpenIntToDoubleHashMap implements Serializable { } + /** + * Read a serialized object. + * @param stream input stream + * @throws IOException if object cannot be read + * @throws ClassNotFoundException if the class corresponding + * to the serialized object cannot be found + */ + private void readObject(final ObjectInputStream stream) + throws IOException, ClassNotFoundException { + stream.defaultReadObject(); + count = 0; + } + } diff --git a/src/java/org/apache/commons/math/util/ResizableDoubleArray.java b/src/java/org/apache/commons/math/util/ResizableDoubleArray.java index 5aa3c2ec2..67ce445fe 100644 --- a/src/java/org/apache/commons/math/util/ResizableDoubleArray.java +++ b/src/java/org/apache/commons/math/util/ResizableDoubleArray.java @@ -873,13 +873,15 @@ public class ResizableDoubleArray implements DoubleArray, Serializable { */ public int hashCode() { int[] hashData = new int[7]; - hashData[0] = Arrays.hashCode(internalArray); - hashData[1] = new Float(expansionFactor).hashCode(); - hashData[2] = new Float(contractionCriteria).hashCode(); - hashData[3] = initialCapacity; - hashData[4] = expansionMode; - hashData[5] = numElements; - hashData[6] = startIndex; + hashData[0] = new Float(expansionFactor).hashCode(); + hashData[1] = new Float(contractionCriteria).hashCode(); + hashData[2] = expansionMode; + synchronized(this) { + hashData[3] = Arrays.hashCode(internalArray); + hashData[4] = initialCapacity; + hashData[5] = numElements; + hashData[6] = startIndex; + } return Arrays.hashCode(hashData); } diff --git a/src/site/xdoc/userguide/index.xml b/src/site/xdoc/userguide/index.xml index c9b87adb2..e043609f3 100644 --- a/src/site/xdoc/userguide/index.xml +++ b/src/site/xdoc/userguide/index.xml @@ -30,107 +30,108 @@