MATH-1362: Use "IntegerSequence.Incrementor".
Also removed spurious "throws" clauses.
diff --git a/src/main/java/org/apache/commons/math4/analysis/integration/BaseAbstractUnivariateIntegrator.java b/src/main/java/org/apache/commons/math4/analysis/integration/BaseAbstractUnivariateIntegrator.java
index 690615f..1f89468 100644
--- a/src/main/java/org/apache/commons/math4/analysis/integration/BaseAbstractUnivariateIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/analysis/integration/BaseAbstractUnivariateIntegrator.java
@@ -221,8 +221,7 @@
/**
* Prepare for computation.
- * Subclasses must call this method if they override any of the
- * {@code solve} methods.
+ * Subclasses must call this method if they the {@code integrate} method.
*
* @param maxEval Maximum number of evaluations.
* @param f the integrand function
diff --git a/src/main/java/org/apache/commons/math4/analysis/solvers/BaseAbstractUnivariateSolver.java b/src/main/java/org/apache/commons/math4/analysis/solvers/BaseAbstractUnivariateSolver.java
index a65cd41..650a382 100644
--- a/src/main/java/org/apache/commons/math4/analysis/solvers/BaseAbstractUnivariateSolver.java
+++ b/src/main/java/org/apache/commons/math4/analysis/solvers/BaseAbstractUnivariateSolver.java
@@ -23,7 +23,7 @@
import org.apache.commons.math4.exception.NullArgumentException;
import org.apache.commons.math4.exception.NumberIsTooLargeException;
import org.apache.commons.math4.exception.TooManyEvaluationsException;
-import org.apache.commons.math4.util.Incrementor;
+import org.apache.commons.math4.util.IntegerSequence;
import org.apache.commons.math4.util.MathUtils;
/**
@@ -51,7 +51,7 @@
/** Relative accuracy. */
private final double relativeAccuracy;
/** Evaluations counter. */
- private final Incrementor evaluations = new Incrementor();
+ private IntegerSequence.Incrementor evaluations;
/** Lower end of search interval. */
private double searchMin;
/** Higher end of search interval. */
@@ -158,8 +158,7 @@
* @throws TooManyEvaluationsException if the maximal number of evaluations
* is exceeded.
*/
- protected double computeObjectiveValue(double point)
- throws TooManyEvaluationsException {
+ protected double computeObjectiveValue(double point) {
incrementEvaluationCount();
return function.value(point);
}
@@ -179,8 +178,7 @@
protected void setup(int maxEval,
FUNC f,
double min, double max,
- double startValue)
- throws NullArgumentException {
+ double startValue) {
// Checks.
MathUtils.checkNotNull(f);
@@ -189,15 +187,13 @@
searchMax = max;
searchStart = startValue;
function = f;
- evaluations.setMaximalCount(maxEval);
- evaluations.resetCount();
+ evaluations = IntegerSequence.Incrementor.create()
+ .withMaximalCount(maxEval);
}
/** {@inheritDoc} */
@Override
- public double solve(int maxEval, FUNC f, double min, double max, double startValue)
- throws TooManyEvaluationsException,
- NoBracketingException {
+ public double solve(int maxEval, FUNC f, double min, double max, double startValue) {
// Initialization.
setup(maxEval, f, min, max, startValue);
@@ -213,9 +209,7 @@
/** {@inheritDoc} */
@Override
- public double solve(int maxEval, FUNC f, double startValue)
- throws TooManyEvaluationsException,
- NoBracketingException {
+ public double solve(int maxEval, FUNC f, double startValue) {
return solve(maxEval, f, Double.NaN, Double.NaN, startValue);
}
@@ -229,8 +223,7 @@
* @throws NoBracketingException if the initial search interval does not bracket
* a root and the solver requires it.
*/
- protected abstract double doSolve()
- throws TooManyEvaluationsException, NoBracketingException;
+ protected abstract double doSolve();
/**
* Check whether the function takes opposite signs at the endpoints.
@@ -267,8 +260,7 @@
* @throws NumberIsTooLargeException if {@code lower >= upper}.
*/
protected void verifyInterval(final double lower,
- final double upper)
- throws NumberIsTooLargeException {
+ final double upper) {
UnivariateSolverUtils.verifyInterval(lower, upper);
}
@@ -283,8 +275,7 @@
*/
protected void verifySequence(final double lower,
final double initial,
- final double upper)
- throws NumberIsTooLargeException {
+ final double upper) {
UnivariateSolverUtils.verifySequence(lower, initial, upper);
}
@@ -299,9 +290,7 @@
* the endpoints.
*/
protected void verifyBracketing(final double lower,
- final double upper)
- throws NullArgumentException,
- NoBracketingException {
+ final double upper) {
UnivariateSolverUtils.verifyBracketing(function, lower, upper);
}
@@ -315,10 +304,9 @@
* @throws TooManyEvaluationsException when the allowed number of function
* evaluations has been exhausted.
*/
- protected void incrementEvaluationCount()
- throws TooManyEvaluationsException {
+ protected void incrementEvaluationCount() {
try {
- evaluations.incrementCount();
+ evaluations.increment();
} catch (MaxCountExceededException e) {
throw new TooManyEvaluationsException(e.getMax());
}
diff --git a/src/test/java/org/apache/commons/math4/analysis/solvers/BrentSolverTest.java b/src/test/java/org/apache/commons/math4/analysis/solvers/BrentSolverTest.java
index cc17d0c..79af777 100644
--- a/src/test/java/org/apache/commons/math4/analysis/solvers/BrentSolverTest.java
+++ b/src/test/java/org/apache/commons/math4/analysis/solvers/BrentSolverTest.java
@@ -264,7 +264,7 @@
};
BrentSolver solver = new BrentSolver();
- final double result = solver.solve(99, f, 1, 1e30, 1 + 1e-10);
+ final double result = solver.solve(100, f, 1, 1e30, 1 + 1e-10);
Assert.assertEquals(804.93558250, result, solver.getAbsoluteAccuracy());
}
}