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
This commit is contained in:
Luc Maisonobe 2009-01-18 16:57:29 +00:00
parent e6e70980dd
commit 2e405f1724
11 changed files with 115 additions and 116 deletions

View File

@ -25,6 +25,11 @@
<!-- the following equality tests are part of the reference algorithms -->
<!-- which already know about limited precision of the double numbers -->
<Match>
<Class name="org.apache.commons.math.analysis.minimization.BrentMinimizer" />
<Method name="localMin" params="double,double,double,double,org.apache.commons.math.analysis.UnivariateRealFunction" returns="double" />
<Bug pattern="FE_FLOATING_POINT_EQUALITY" />
</Match>
<Match>
<Class name="org.apache.commons.math.analysis.solvers.BrentSolver" />
<Method name="solve" params="org.apache.commons.math.analysis.UnivariateRealFunction,double,double,double,double,double,double" returns="double" />

View File

@ -224,11 +224,10 @@
</descriptors>
</configuration>
</plugin>
<!--
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.0</version>
<version>2.2</version>
<executions>
<execution>
<goals>
@ -237,7 +236,6 @@
</execution>
</executions>
</plugin>
-->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>clirr-maven-plugin</artifactId>
@ -264,13 +262,11 @@
<excludeFilterFile>${basedir}/findbugs-exclude-filter.xml</excludeFilterFile>
</configuration>
</plugin>
<!--
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.0</version>
<version>2.2</version>
</plugin>
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-changes-plugin</artifactId>

View File

@ -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 <em>not</em> 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);

View File

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

View File

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

View File

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

View File

@ -17,6 +17,8 @@
package org.apache.commons.math.ode;
import java.io.Serializable;
/** This interface represents a second order differential equations set.
* <p>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

View File

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

View File

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

View File

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

View File

@ -30,107 +30,108 @@
<ul>
<li><a href="overview.html">0. Overview</a>
<ul>
<li><a href="overview.html#0.1 About the User Guide">0.1 About the User Guide</a></li>
<li><a href="overview.html#0.2 What&amp;apos;s in commons-math">0.2 What's in commons-math</a></li>
<li><a href="overview.html#0.3 How commons-math is organized">0.3 How commons-math is organized</a></li>
<li><a href="overview.html#0.4 How interface contracts are specified in commons-math javadoc">0.4 How interface contracts are specified in commons-math javadoc</a></li>
<li><a href="overview.html#0.5 Dependencies">0.5 Dependencies</a></li>
<li><a href="overview.html#a0.1_About_the_User_Guide">0.1 About the User Guide</a></li>
<li><a href="overview.html#a0.2_Whats_in_commons-math">0.2 What's in commons-math</a></li>
<li><a href="overview.html#a0.3_How_commons-math_is_organized">0.3 How commons-math is organized</a></li>
<li><a href="overview.html#a0.4_How_interface_contracts_are_specified_in_commons-math_javadoc">0.4 How interface contracts are specified in commons-math javadoc</a></li>
<li><a href="overview.html#a0.5_Dependencies">0.5 Dependencies</a></li>
</ul></li>
<li><a href="stat.html">1. Statistics</a>
<ul>
<li><a href="stat.html#1.1 Overview">1.1 Overview</a></li>
<li><a href="stat.html#1.2 Descriptive statistics">1.2 Descriptive statistics</a></li>
<li><a href="stat.html#1.3 Frequency distributions">1.3 Frequency distributions</a></li>
<li><a href="stat.html#1.4 Simple regression">1.4 Simple regression</a></li>
<li><a href="stat.html#1.5 Statistical tests">1.5 Statistical tests</a></li>
<li><a href="stat.html#a1.1_Overview">1.1 Overview</a></li>
<li><a href="stat.html#a1.2_Descriptive_statistics">1.2 Descriptive statistics</a></li>
<li><a href="stat.html#a1.3_Frequency_distributions">1.3 Frequency distributions</a></li>
<li><a href="stat.html#a1.4_Simple_regression">1.4 Simple regression</a></li>
<li><a href="stat.html#a1.5_Statistical_tests">1.5 Statistical tests</a></li>
</ul></li>
<li><a href="random.html">2. Data Generation</a>
<ul>
<li><a href="random.html#2.1 Overview">2.1 Overview</a></li>
<li><a href="random.html#2.2 Random numbers">2.2 Random numbers</a></li>
<li><a href="random.html#2.3 Random Strings">2.3 Random Strings</a></li>
<li><a href="random.html#2.4 Random permutations, combinations, sampling">2.4 Random permutations, combinations, sampling</a></li>
<li><a href="random.html#2.5 Generating data 'like' an input file">2.5 Generating data 'like' an input file</a></li>
<li><a href="random.html#2.6 PRNG Pluggability">2.6 PRNG Pluggability</a></li>
<li><a href="random.html#a2.1_Overview">2.1 Overview</a></li>
<li><a href="random.html#a2.2_Random_numbers">2.2 Random numbers</a></li>
<li><a href="random.html#a2.3_Random_Vectors">2.3 Random Vectors</a></li>
<li><a href="random.html#a2.4_Random_Strings">2.4 Random Strings</a></li>
<li><a href="random.html#a2.5_Random_permutations_combinations_sampling">2.5 Random permutations, combinations, sampling</a></li>
<li><a href="random.html#a2.6_Generating_data_like_an_input_file">2.6 Generating data 'like' an input file</a></li>
<li><a href="random.html#a2.7_PRNG_Pluggability">2.7 PRNG Pluggability</a></li>
</ul></li>
<li><a href="linear.html">3. Linear Algebra</a>
<ul>
<li><a href="linear.html#3.1 Overview">3.1 Overview</a></li>
<li><a href="linear.html#3.2 Real matrices">3.2 Real matrices</a></li>
<li><a href="linear.html#3.3 Real vectors">3.3 Real vectors</a></li>
<li><a href="linear.html#3.4 Solving linear systems">3.4 Solving linear systems</a></li>
<li><a href="linear.html#3.5 Eigenvalues/eigenvectors and singular values/singular vectors">3.5 Eigenvalues/eigenvectors and singular values/singular vectors</a></li>
<li><a href="linear.html#a3.1_Overview">3.1 Overview</a></li>
<li><a href="linear.html#a3.2_Real_matrices">3.2 Real matrices</a></li>
<li><a href="linear.html#a3.3_Real_vectors">3.3 Real vectors</a></li>
<li><a href="linear.html#a3.4_Solving_linear_systems">3.4 Solving linear systems</a></li>
<li><a href="linear.html#a3.5_Eigenvalueseigenvectors_and_singular_valuessingular_vectors">3.5 Eigenvalues/eigenvectors and singular values/singular vectors</a></li>
</ul></li>
<li><a href="analysis.html">4. Numerical Analysis</a>
<ul>
<li><a href="analysis.html#4.1 Overview">4.1 Overview</a></li>
<li><a href="analysis.html#4.2 Root-finding">4.2 Root-finding</a></li>
<li><a href="analysis.html#4.3 Minimization">4.3 Minimization</a></li>
<li><a href="analysis.html#4.4 Interpolation">4.4 Interpolation</a></li>
<li><a href="analysis.html#4.5 Integration">4.5 Integration</a></li>
<li><a href="analysis.html#4.6 Polynomials">4.6 Polynomials</a></li>
<li><a href="analysis.html#a4.1_Overview">4.1 Overview</a></li>
<li><a href="analysis.html#a4.2_Root-finding">4.2 Root-finding</a></li>
<li><a href="analysis.html#a4.3_Minimization">4.3 Minimization</a></li>
<li><a href="analysis.html#a4.4_Interpolation">4.4 Interpolation</a></li>
<li><a href="analysis.html#a4.5_Integration">4.5 Integration</a></li>
<li><a href="analysis.html#a4.6_Polynomials">4.6 Polynomials</a></li>
</ul></li>
<li><a href="special.html">5. Special Functions</a>
<ul>
<li><a href="special.html#5.1 Overview">5.1 Overview</a></li>
<li><a href="special.html#5.2 Erf functions">5.2 Erf functions</a></li>
<li><a href="special.html#5.3 Gamma functions">5.3 Gamma functions</a></li>
<li><a href="special.html#5.4 Beta funtions">5.4 Beta funtions</a></li>
<li><a href="special.html#a5.1_Overview">5.1 Overview</a></li>
<li><a href="special.html#a5.2_Erf_functions">5.2 Erf functions</a></li>
<li><a href="special.html#a5.3_Gamma_functions">5.3 Gamma functions</a></li>
<li><a href="special.html#a5.4_Beta_funtions">5.4 Beta funtions</a></li>
</ul></li>
<li><a href="utilities.html">6. Utilities</a>
<ul>
<li><a href="utilities.html#6.1 Overview">6.1 Overview</a></li>
<li><a href="utilities.html#6.2 Double array utilities">6.2 Double array utilities</a></li>
<li><a href="utilities.html#6.3 int/double hash map">6.3 int/double hash map</a></li>
<li><a href="utilities.html#6.4 Continued Fractions">6.4 Continued Fractions</a></li>
<li><a href="utilities.html#6.5 binomial coefficients, factorials and other common math functions">6.5 binomial coefficients, factorials and other common math functions</a></li>
<li><a href="utilities.html#a6.1_Overview">6.1 Overview</a></li>
<li><a href="utilities.html#a6.2_Double_array_utilities">6.2 Double array utilities</a></li>
<li><a href="utilities.html#a6.3_intdouble_hash_map">6.3 int/double hash map</a></li>
<li><a href="utilities.html#a6.4_Continued_Fractions">6.4 Continued Fractions</a></li>
<li><a href="utilities.html#a6.5_binomial_coefficients,_factorials_and_other_common_math_functions">6.5 binomial coefficients, factorials and other common math functions</a></li>
</ul></li>
<li><a href="complex.html">7. Complex Numbers</a>
<ul>
<li><a href="complex.html#7.1 Overview">7.1 Overview</a></li>
<li><a href="complex.html#7.2 Complex Numbers">7.2 Complex Numbers</a></li>
<li><a href="complex.html#7.3 Complex Transcendental Functions">7.3 Complex Transcendental Functions</a></li>
<li><a href="complex.html#7.4 Complex Formatting and Parsing">7.4 Complex Formatting and Parsing</a></li>
<li><a href="complex.html#a7.1_Overview">7.1 Overview</a></li>
<li><a href="complex.html#a7.2_Complex_Numbers">7.2 Complex Numbers</a></li>
<li><a href="complex.html#a7.3_Complex_Transcendental_Functions">7.3 Complex Transcendental Functions</a></li>
<li><a href="complex.html#a7.4_Complex_Formatting_and_Parsing">7.4 Complex Formatting and Parsing</a></li>
</ul></li>
<li><a href="distribution.html">8. Probability Distributions</a>
<ul>
<li><a href="distribution.html#8.1 Overview">8.1 Overview</a></li>
<li><a href="distribution.html#8.2 Distribution Framework">8.2 Distribution Framework</a></li>
<li><a href="distribution.html#8.3 User Defined Distributions">8.3 User Defined Distributions</a></li>
<li><a href="distribution.html#a8.1_Overview">8.1 Overview</a></li>
<li><a href="distribution.html#a8.2_Distribution_Framework">8.2 Distribution Framework</a></li>
<li><a href="distribution.html#a8.3_User_Defined_Distributions">8.3 User Defined Distributions</a></li>
</ul></li>
<li><a href="fraction.html">9. Fractions</a>
<ul>
<li><a href="fraction.html#9.1 Overview">9.1 Overview</a></li>
<li><a href="fraction.html#9.2 Fraction Numbers">9.2 Fraction Numbers</a></li>
<li><a href="fraction.html#9.3 Fraction Formatting and Parsing">9.3 Fraction Formatting and Parsing</a></li>
<li><a href="fraction.html#a9.1_Overview">9.1 Overview</a></li>
<li><a href="fraction.html#a9.2_Fraction_Numbers">9.2 Fraction Numbers</a></li>
<li><a href="fraction.html#a9.3_Fraction_Formatting_and_Parsing">9.3 Fraction Formatting and Parsing</a></li>
</ul></li>
<li><a href="transform.html">10. Transform methods</a></li>
<li><a href="geometry.html">11. Geometry</a>
<ul>
<li><a href="geometry.html#11.1 Overview">11.1 Overview</a></li>
<li><a href="geometry.html#11.2 Vectors">11.2 Vectors</a></li>
<li><a href="geometry.html#11.3 Rotations">11.3 Rotations</a></li>
<li><a href="geometry.html#a11.1_Overview">11.1 Overview</a></li>
<li><a href="geometry.html#a11.2_Vectors">11.2 Vectors</a></li>
<li><a href="geometry.html#a11.3_Rotations">11.3 Rotations</a></li>
</ul></li>
<li><a href="estimation.html">12. Parametric Estimation</a>
<ul>
<li><a href="estimation.html#12.1 Overview">12.1 Overview</a></li>
<li><a href="estimation.html#12.2 Models">12.2 Models</a></li>
<li><a href="estimation.html#12.3 Parameters">12.3 Parameters</a></li>
<li><a href="estimation.html#12.4 Measurements">12.4 Measurements</a></li>
<li><a href="estimation.html#12.5 Solvers">12.5 Solvers</a></li>
<li><a href="estimation.html#a12.1_Overview">12.1 Overview</a></li>
<li><a href="estimation.html#a12.2_Models">12.2 Models</a></li>
<li><a href="estimation.html#a12.3_Parameters">12.3 Parameters</a></li>
<li><a href="estimation.html#a12.4_Measurements">12.4 Measurements</a></li>
<li><a href="estimation.html#a12.5_Solvers">12.5 Solvers</a></li>
</ul></li>
<li><a href="optimization.html">13. Optimization</a>
<ul>
<li><a href="optimization.html#13.1 Overview">13.1 Overview</a></li>
<li><a href="optimization.html#13.2 Direct Methods">13.2 Direct Methods</a></li>
<li><a href="optimization.html#a13.1_Overview">13.1 Overview</a></li>
<li><a href="optimization.html#a13.2_Direct_Methods">13.2 Direct Methods</a></li>
</ul></li>
<li><a href="ode.html">14. Ordinary Differential Equations Integration</a>
<ul>
<li><a href="ode.html#14.1 Overview">14.1 Overview</a></li>
<li><a href="ode.html#14.2 Discrete Events Handling">14.2 Discrete Events Handling</a></li>
<li><a href="ode.html#14.3 ODE Problems">14.3 ODE Problems</a></li>
<li><a href="ode.html#14.4 Integrators">14.4 Integrators</a></li>
<li><a href="ode.html#a14.1_Overview">14.1 Overview</a></li>
<li><a href="ode.html#a14.2_Discrete_Events_Handling">14.2 Discrete Events Handling</a></li>
<li><a href="ode.html#a14.3_ODE_Problems">14.3 ODE Problems</a></li>
<li><a href="ode.html#a14.4_Integrators">14.4 Integrators</a></li>
</ul></li>
</ul>
</section>