Replaced deprecated Incrementor with IntegerSequence.Incrementor where possible.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/ee504b64
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/ee504b64
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/ee504b64

Branch: refs/heads/MATH_3_X
Commit: ee504b64afb1f7a0341c57aa7bd3c798e444c8c0
Parents: 6814a35
Author: Luc Maisonobe <l...@apache.org>
Authored: Fri Dec 25 14:59:41 2015 +0100
Committer: Luc Maisonobe <l...@apache.org>
Committed: Fri Dec 25 14:59:41 2015 +0100

----------------------------------------------------------------------
 .../BaseAbstractUnivariateIntegrator.java       | 41 +++++++++-----
 .../IterativeLegendreGaussIntegrator.java       |  4 +-
 .../integration/LegendreGaussIntegrator.java    |  4 +-
 .../integration/MidPointIntegrator.java         |  4 +-
 .../analysis/integration/RombergIntegrator.java |  8 +--
 .../analysis/integration/SimpsonIntegrator.java |  6 +--
 .../integration/TrapezoidIntegrator.java        |  6 +--
 .../solvers/BaseAbstractUnivariateSolver.java   | 14 ++---
 .../commons/math3/ode/AbstractIntegrator.java   | 19 +------
 .../math3/optim/univariate/BracketFinder.java   | 10 ++--
 .../apache/commons/math3/util/Incrementor.java  | 57 ++++++++++++++++++++
 .../commons/math3/util/IterationManager.java    | 32 +++++++++--
 12 files changed, 142 insertions(+), 63 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/ee504b64/src/main/java/org/apache/commons/math3/analysis/integration/BaseAbstractUnivariateIntegrator.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/commons/math3/analysis/integration/BaseAbstractUnivariateIntegrator.java
 
b/src/main/java/org/apache/commons/math3/analysis/integration/BaseAbstractUnivariateIntegrator.java
index 23c25b0..b2ca165 100644
--- 
a/src/main/java/org/apache/commons/math3/analysis/integration/BaseAbstractUnivariateIntegrator.java
+++ 
b/src/main/java/org/apache/commons/math3/analysis/integration/BaseAbstractUnivariateIntegrator.java
@@ -24,7 +24,7 @@ import 
org.apache.commons.math3.exception.NotStrictlyPositiveException;
 import org.apache.commons.math3.exception.NullArgumentException;
 import org.apache.commons.math3.exception.NumberIsTooSmallException;
 import org.apache.commons.math3.exception.TooManyEvaluationsException;
-import org.apache.commons.math3.util.Incrementor;
+import org.apache.commons.math3.util.IntegerSequence;
 import org.apache.commons.math3.util.MathUtils;
 
 /**
@@ -46,8 +46,14 @@ public abstract class BaseAbstractUnivariateIntegrator 
implements UnivariateInte
     /** Default maximal iteration count. */
     public static final int DEFAULT_MAX_ITERATIONS_COUNT = Integer.MAX_VALUE;
 
+    /** The iteration count.
+     * @deprecated as of 3.6, this field has been replaced with {@link 
#incrementCount()}
+     */
+    @Deprecated
+    protected org.apache.commons.math3.util.Incrementor iterations;
+
     /** The iteration count. */
-    protected final Incrementor iterations;
+    private IntegerSequence.Incrementor count;
 
     /** Maximum absolute error. */
     private final double absoluteAccuracy;
@@ -59,7 +65,7 @@ public abstract class BaseAbstractUnivariateIntegrator 
implements UnivariateInte
     private final int minimalIterationCount;
 
     /** The functions evaluation count. */
-    private final Incrementor evaluations;
+    private IntegerSequence.Incrementor evaluations;
 
     /** Function to integrate. */
     private UnivariateFunction function;
@@ -123,11 +129,15 @@ public abstract class BaseAbstractUnivariateIntegrator 
implements UnivariateInte
             throw new NumberIsTooSmallException(maximalIterationCount, 
minimalIterationCount, false);
         }
         this.minimalIterationCount = minimalIterationCount;
-        this.iterations            = new Incrementor();
-        iterations.setMaximalCount(maximalIterationCount);
+        this.count                 = 
IntegerSequence.Incrementor.create().withMaximalCount(maximalIterationCount);
+
+        @SuppressWarnings("deprecation")
+        org.apache.commons.math3.util.Incrementor wrapped =
+                        org.apache.commons.math3.util.Incrementor.wrap(count);
+        this.iterations = wrapped;
 
         // prepare evaluations counter, but do not set it yet
-        evaluations = new Incrementor();
+        evaluations = IntegerSequence.Incrementor.create();
 
     }
 
@@ -175,7 +185,7 @@ public abstract class BaseAbstractUnivariateIntegrator 
implements UnivariateInte
 
     /** {@inheritDoc} */
     public int getMaximalIterationCount() {
-        return iterations.getMaximalCount();
+        return count.getMaximalCount();
     }
 
     /** {@inheritDoc} */
@@ -185,7 +195,15 @@ public abstract class BaseAbstractUnivariateIntegrator 
implements UnivariateInte
 
     /** {@inheritDoc} */
     public int getIterations() {
-        return iterations.getCount();
+        return count.getCount();
+    }
+
+    /** Increment the number of iterations.
+     * @exception MaxCountExceededException if the number of iterations
+     * exceeds the allowed maximum number
+     */
+    protected void incrementCount() throws MaxCountExceededException {
+        count.increment();
     }
 
     /**
@@ -212,7 +230,7 @@ public abstract class BaseAbstractUnivariateIntegrator 
implements UnivariateInte
     protected double computeObjectiveValue(final double point)
         throws TooManyEvaluationsException {
         try {
-            evaluations.incrementCount();
+            evaluations.increment();
         } catch (MaxCountExceededException e) {
             throw new TooManyEvaluationsException(e.getMax());
         }
@@ -244,9 +262,8 @@ public abstract class BaseAbstractUnivariateIntegrator 
implements UnivariateInte
         min = lower;
         max = upper;
         function = f;
-        evaluations.setMaximalCount(maxEval);
-        evaluations.resetCount();
-        iterations.resetCount();
+        evaluations = evaluations.withMaximalCount(maxEval).withStart(0);
+        count       = count.withStart(0);
 
     }
 

http://git-wip-us.apache.org/repos/asf/commons-math/blob/ee504b64/src/main/java/org/apache/commons/math3/analysis/integration/IterativeLegendreGaussIntegrator.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/commons/math3/analysis/integration/IterativeLegendreGaussIntegrator.java
 
b/src/main/java/org/apache/commons/math3/analysis/integration/IterativeLegendreGaussIntegrator.java
index 86be02c..d08cf08 100644
--- 
a/src/main/java/org/apache/commons/math3/analysis/integration/IterativeLegendreGaussIntegrator.java
+++ 
b/src/main/java/org/apache/commons/math3/analysis/integration/IterativeLegendreGaussIntegrator.java
@@ -133,7 +133,7 @@ public class IterativeLegendreGaussIntegrator
                              getRelativeAccuracy() * (FastMath.abs(oldt) + 
FastMath.abs(t)) * 0.5);
 
             // check convergence
-            if (iterations.getCount() + 1 >= getMinimalIterationCount() &&
+            if (getIterations() + 1 >= getMinimalIterationCount() &&
                 delta <= limit) {
                 return t;
             }
@@ -142,7 +142,7 @@ public class IterativeLegendreGaussIntegrator
             final double ratio = FastMath.min(4, FastMath.pow(delta / limit, 
0.5 / numberOfPoints));
             n = FastMath.max((int) (ratio * n), n + 1);
             oldt = t;
-            iterations.incrementCount();
+            incrementCount();;
         }
     }
 

http://git-wip-us.apache.org/repos/asf/commons-math/blob/ee504b64/src/main/java/org/apache/commons/math3/analysis/integration/LegendreGaussIntegrator.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/commons/math3/analysis/integration/LegendreGaussIntegrator.java
 
b/src/main/java/org/apache/commons/math3/analysis/integration/LegendreGaussIntegrator.java
index 08f4794..bfb24a1 100644
--- 
a/src/main/java/org/apache/commons/math3/analysis/integration/LegendreGaussIntegrator.java
+++ 
b/src/main/java/org/apache/commons/math3/analysis/integration/LegendreGaussIntegrator.java
@@ -220,7 +220,7 @@ public class LegendreGaussIntegrator extends 
BaseAbstractUnivariateIntegrator {
                              getRelativeAccuracy() * (FastMath.abs(oldt) + 
FastMath.abs(t)) * 0.5);
 
             // check convergence
-            if ((iterations.getCount() + 1 >= getMinimalIterationCount()) && 
(delta <= limit)) {
+            if ((getIterations() + 1 >= getMinimalIterationCount()) && (delta 
<= limit)) {
                 return t;
             }
 
@@ -228,7 +228,7 @@ public class LegendreGaussIntegrator extends 
BaseAbstractUnivariateIntegrator {
             double ratio = FastMath.min(4, FastMath.pow(delta / limit, 0.5 / 
abscissas.length));
             n = FastMath.max((int) (ratio * n), n + 1);
             oldt = t;
-            iterations.incrementCount();
+            incrementCount();
 
         }
 

http://git-wip-us.apache.org/repos/asf/commons-math/blob/ee504b64/src/main/java/org/apache/commons/math3/analysis/integration/MidPointIntegrator.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/commons/math3/analysis/integration/MidPointIntegrator.java
 
b/src/main/java/org/apache/commons/math3/analysis/integration/MidPointIntegrator.java
index aaea286..766a917 100644
--- 
a/src/main/java/org/apache/commons/math3/analysis/integration/MidPointIntegrator.java
+++ 
b/src/main/java/org/apache/commons/math3/analysis/integration/MidPointIntegrator.java
@@ -150,8 +150,8 @@ public class MidPointIntegrator extends 
BaseAbstractUnivariateIntegrator {
         double oldt = diff * computeObjectiveValue(midPoint);
 
         while (true) {
-            iterations.incrementCount();
-            final int i = iterations.getCount();
+            incrementCount();
+            final int i = getIterations();
             final double t = stage(i, oldt, min, diff);
             if (i >= getMinimalIterationCount()) {
                 final double delta = FastMath.abs(t - oldt);

http://git-wip-us.apache.org/repos/asf/commons-math/blob/ee504b64/src/main/java/org/apache/commons/math3/analysis/integration/RombergIntegrator.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/commons/math3/analysis/integration/RombergIntegrator.java
 
b/src/main/java/org/apache/commons/math3/analysis/integration/RombergIntegrator.java
index 430cd6e..125d251 100644
--- 
a/src/main/java/org/apache/commons/math3/analysis/integration/RombergIntegrator.java
+++ 
b/src/main/java/org/apache/commons/math3/analysis/integration/RombergIntegrator.java
@@ -101,17 +101,17 @@ public class RombergIntegrator extends 
BaseAbstractUnivariateIntegrator {
     protected double doIntegrate()
         throws TooManyEvaluationsException, MaxCountExceededException {
 
-        final int m = iterations.getMaximalCount() + 1;
+        final int m = getMaximalIterationCount() + 1;
         double previousRow[] = new double[m];
         double currentRow[]  = new double[m];
 
         TrapezoidIntegrator qtrap = new TrapezoidIntegrator();
         currentRow[0] = qtrap.stage(this, 0);
-        iterations.incrementCount();
+        incrementCount();
         double olds = currentRow[0];
         while (true) {
 
-            final int i = iterations.getCount();
+            final int i = getIterations();
 
             // switch rows
             final double[] tmpRow = previousRow;
@@ -119,7 +119,7 @@ public class RombergIntegrator extends 
BaseAbstractUnivariateIntegrator {
             currentRow = tmpRow;
 
             currentRow[0] = qtrap.stage(this, i);
-            iterations.incrementCount();
+            incrementCount();
             for (int j = 1; j <= i; j++) {
                 // Richardson extrapolation coefficient
                 final double r = (1L << (2 * j)) - 1;

http://git-wip-us.apache.org/repos/asf/commons-math/blob/ee504b64/src/main/java/org/apache/commons/math3/analysis/integration/SimpsonIntegrator.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/commons/math3/analysis/integration/SimpsonIntegrator.java
 
b/src/main/java/org/apache/commons/math3/analysis/integration/SimpsonIntegrator.java
index b13ff5f..527bb82 100644
--- 
a/src/main/java/org/apache/commons/math3/analysis/integration/SimpsonIntegrator.java
+++ 
b/src/main/java/org/apache/commons/math3/analysis/integration/SimpsonIntegrator.java
@@ -109,10 +109,10 @@ public class SimpsonIntegrator extends 
BaseAbstractUnivariateIntegrator {
         double olds = 0;
         double oldt = qtrap.stage(this, 0);
         while (true) {
-            final double t = qtrap.stage(this, iterations.getCount());
-            iterations.incrementCount();
+            final double t = qtrap.stage(this, getIterations());
+            incrementCount();
             final double s = (4 * t - oldt) / 3.0;
-            if (iterations.getCount() >= getMinimalIterationCount()) {
+            if (getIterations() >= getMinimalIterationCount()) {
                 final double delta = FastMath.abs(s - olds);
                 final double rLimit =
                     getRelativeAccuracy() * (FastMath.abs(olds) + 
FastMath.abs(s)) * 0.5;

http://git-wip-us.apache.org/repos/asf/commons-math/blob/ee504b64/src/main/java/org/apache/commons/math3/analysis/integration/TrapezoidIntegrator.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/commons/math3/analysis/integration/TrapezoidIntegrator.java
 
b/src/main/java/org/apache/commons/math3/analysis/integration/TrapezoidIntegrator.java
index d22d12d..8a737f1 100644
--- 
a/src/main/java/org/apache/commons/math3/analysis/integration/TrapezoidIntegrator.java
+++ 
b/src/main/java/org/apache/commons/math3/analysis/integration/TrapezoidIntegrator.java
@@ -147,9 +147,9 @@ public class TrapezoidIntegrator extends 
BaseAbstractUnivariateIntegrator {
         throws MathIllegalArgumentException, TooManyEvaluationsException, 
MaxCountExceededException {
 
         double oldt = stage(this, 0);
-        iterations.incrementCount();
+        incrementCount();
         while (true) {
-            final int i = iterations.getCount();
+            final int i = getIterations();
             final double t = stage(this, i);
             if (i >= getMinimalIterationCount()) {
                 final double delta = FastMath.abs(t - oldt);
@@ -160,7 +160,7 @@ public class TrapezoidIntegrator extends 
BaseAbstractUnivariateIntegrator {
                 }
             }
             oldt = t;
-            iterations.incrementCount();
+            incrementCount();
         }
 
     }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/ee504b64/src/main/java/org/apache/commons/math3/analysis/solvers/BaseAbstractUnivariateSolver.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/commons/math3/analysis/solvers/BaseAbstractUnivariateSolver.java
 
b/src/main/java/org/apache/commons/math3/analysis/solvers/BaseAbstractUnivariateSolver.java
index 4fb9ecf..12b30c6 100644
--- 
a/src/main/java/org/apache/commons/math3/analysis/solvers/BaseAbstractUnivariateSolver.java
+++ 
b/src/main/java/org/apache/commons/math3/analysis/solvers/BaseAbstractUnivariateSolver.java
@@ -23,7 +23,7 @@ import 
org.apache.commons.math3.exception.NoBracketingException;
 import org.apache.commons.math3.exception.TooManyEvaluationsException;
 import org.apache.commons.math3.exception.NumberIsTooLargeException;
 import org.apache.commons.math3.exception.NullArgumentException;
-import org.apache.commons.math3.util.Incrementor;
+import org.apache.commons.math3.util.IntegerSequence;
 import org.apache.commons.math3.util.MathUtils;
 
 /**
@@ -51,7 +51,7 @@ public abstract class BaseAbstractUnivariateSolver<FUNC 
extends UnivariateFuncti
     /** 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. */
@@ -95,9 +95,10 @@ public abstract class BaseAbstractUnivariateSolver<FUNC 
extends UnivariateFuncti
     protected BaseAbstractUnivariateSolver(final double relativeAccuracy,
                                            final double absoluteAccuracy,
                                            final double functionValueAccuracy) 
{
-        this.absoluteAccuracy = absoluteAccuracy;
-        this.relativeAccuracy = relativeAccuracy;
+        this.absoluteAccuracy      = absoluteAccuracy;
+        this.relativeAccuracy      = relativeAccuracy;
         this.functionValueAccuracy = functionValueAccuracy;
+        this.evaluations           = IntegerSequence.Incrementor.create();
     }
 
     /** {@inheritDoc} */
@@ -184,8 +185,7 @@ public abstract class BaseAbstractUnivariateSolver<FUNC 
extends UnivariateFuncti
         searchMax = max;
         searchStart = startValue;
         function = f;
-        evaluations.setMaximalCount(maxEval);
-        evaluations.resetCount();
+        evaluations = evaluations.withMaximalCount(maxEval).withStart(0);
     }
 
     /** {@inheritDoc} */
@@ -310,7 +310,7 @@ public abstract class BaseAbstractUnivariateSolver<FUNC 
extends UnivariateFuncti
     protected void incrementEvaluationCount()
         throws TooManyEvaluationsException {
         try {
-            evaluations.incrementCount();
+            evaluations.increment();
         } catch (MaxCountExceededException e) {
             throw new TooManyEvaluationsException(e.getMax());
         }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/ee504b64/src/main/java/org/apache/commons/math3/ode/AbstractIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math3/ode/AbstractIntegrator.java 
b/src/main/java/org/apache/commons/math3/ode/AbstractIntegrator.java
index 835689b..e080722 100644
--- a/src/main/java/org/apache/commons/math3/ode/AbstractIntegrator.java
+++ b/src/main/java/org/apache/commons/math3/ode/AbstractIntegrator.java
@@ -219,24 +219,7 @@ public abstract class AbstractIntegrator implements 
FirstOrderIntegrator {
      */
     @Deprecated
     protected org.apache.commons.math3.util.Incrementor 
getEvaluationsCounter() {
-        final org.apache.commons.math3.util.Incrementor incrementor =
-            new org.apache.commons.math3.util.Incrementor() {
-
-            {
-                // set up matching values at initialization
-                super.setMaximalCount(evaluations.getMaximalCount());
-                super.incrementCount(evaluations.getCount());
-            }
-
-            /** {@inheritDoc} */
-            @Override
-            public void incrementCount() {
-                super.incrementCount();
-                evaluations.increment();
-            }
-
-        };
-        return incrementor;
+        return org.apache.commons.math3.util.Incrementor.wrap(evaluations);
     }
 
     /** Get the evaluations counter.

http://git-wip-us.apache.org/repos/asf/commons-math/blob/ee504b64/src/main/java/org/apache/commons/math3/optim/univariate/BracketFinder.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/commons/math3/optim/univariate/BracketFinder.java 
b/src/main/java/org/apache/commons/math3/optim/univariate/BracketFinder.java
index 414a1bb..6d42c0d 100644
--- a/src/main/java/org/apache/commons/math3/optim/univariate/BracketFinder.java
+++ b/src/main/java/org/apache/commons/math3/optim/univariate/BracketFinder.java
@@ -17,7 +17,7 @@
 package org.apache.commons.math3.optim.univariate;
 
 import org.apache.commons.math3.util.FastMath;
-import org.apache.commons.math3.util.Incrementor;
+import org.apache.commons.math3.util.IntegerSequence;
 import org.apache.commons.math3.exception.NotStrictlyPositiveException;
 import org.apache.commons.math3.exception.TooManyEvaluationsException;
 import org.apache.commons.math3.exception.MaxCountExceededException;
@@ -45,7 +45,7 @@ public class BracketFinder {
     /**
      * Counter for function evaluations.
      */
-    private final Incrementor evaluations = new Incrementor();
+    private IntegerSequence.Incrementor evaluations;
     /**
      * Lower bound of the bracket.
      */
@@ -96,7 +96,7 @@ public class BracketFinder {
         }
 
         this.growLimit = growLimit;
-        evaluations.setMaximalCount(maxEvaluations);
+        evaluations = 
IntegerSequence.Incrementor.create().withMaximalCount(maxEvaluations);
     }
 
     /**
@@ -113,7 +113,7 @@ public class BracketFinder {
                        GoalType goal,
                        double xA,
                        double xB) {
-        evaluations.resetCount();
+        evaluations = evaluations.withStart(0);
         final boolean isMinim = goal == GoalType.MINIMIZE;
 
         double fA = eval(func, xA);
@@ -281,7 +281,7 @@ public class BracketFinder {
      */
     private double eval(UnivariateFunction f, double x) {
         try {
-            evaluations.incrementCount();
+            evaluations.increment();
         } catch (MaxCountExceededException e) {
             throw new TooManyEvaluationsException(e.getMax());
         }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/ee504b64/src/main/java/org/apache/commons/math3/util/Incrementor.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math3/util/Incrementor.java 
b/src/main/java/org/apache/commons/math3/util/Incrementor.java
index 3d11954..70995c5 100644
--- a/src/main/java/org/apache/commons/math3/util/Incrementor.java
+++ b/src/main/java/org/apache/commons/math3/util/Incrementor.java
@@ -178,4 +178,61 @@ public class Incrementor {
          */
         void trigger(int maximalCount) throws MaxCountExceededException;
     }
+
+    /** Create an instance that delegates everything to a {@link 
IntegerSequence.Incrementor}.
+     * <p>
+     * This factory method is intended only as a temporary hack for internal 
use in
+     * Apache Commons Math 3.X series, when {@code Incrementor} is required in
+     * interface (as a return value or in protected fields). It should 
<em>not</em>
+     * be used in other cases. The {@link IntegerSequence.Incrementor} class 
should
+     * be used instead of {@code Incrementor}.
+     * </p>
+     * <p>
+     * All methods are mirrored to the underlying {@link 
IntegerSequence.Incrementor},
+     * as long as neither {@link #setMaximalCount(int)} nor {@link 
#resetCount()} are called.
+     * If one of these two methods is called, the created instance becomes 
independent
+     * of the {@link IntegerSequence.Incrementor} used at creation. The 
rationale is that
+     * {@link IntegerSequence.Incrementor} cannot change their maximal count 
and cannot be reset.
+     * </p>
+     * @param incrementor wrapped {@link IntegerSequence.Incrementor}
+     * @return an incrementor wrapping an {@link IntegerSequence.Incrementor}
+     * @since 3.6
+     */
+    public static Incrementor wrap(final IntegerSequence.Incrementor 
incrementor) {
+        return new Incrementor() {
+
+            /** Underlying incrementor. */
+            private IntegerSequence.Incrementor delegate;
+
+            {
+                // set up matching values at initialization
+                delegate = incrementor;
+                super.setMaximalCount(delegate.getMaximalCount());
+                super.incrementCount(delegate.getCount());
+            }
+
+            /** {@inheritDoc} */
+            @Override
+            public void setMaximalCount(int max) {
+                super.setMaximalCount(max);
+                delegate = delegate.withMaximalCount(max);
+            }
+
+            /** {@inheritDoc} */
+            @Override
+            public void resetCount() {
+                super.resetCount();
+                delegate = delegate.withStart(0);
+            }
+
+            /** {@inheritDoc} */
+            @Override
+            public void incrementCount() {
+                super.incrementCount();
+                delegate.increment();
+            }
+
+        };
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/ee504b64/src/main/java/org/apache/commons/math3/util/IterationManager.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math3/util/IterationManager.java 
b/src/main/java/org/apache/commons/math3/util/IterationManager.java
index 1a80d3a..ffda23e 100644
--- a/src/main/java/org/apache/commons/math3/util/IterationManager.java
+++ b/src/main/java/org/apache/commons/math3/util/IterationManager.java
@@ -31,7 +31,7 @@ import 
org.apache.commons.math3.exception.MaxCountExceededException;
 public class IterationManager {
 
     /** Keeps a count of the number of iterations. */
-    private final Incrementor iterations;
+    private IntegerSequence.Incrementor iterations;
 
     /** The collection of all listeners attached to this iterative algorithm. 
*/
     private final Collection<IterationListener> listeners;
@@ -42,7 +42,7 @@ public class IterationManager {
      * @param maxIterations the maximum number of iterations
      */
     public IterationManager(final int maxIterations) {
-        this.iterations = new Incrementor(maxIterations);
+        this.iterations = 
IntegerSequence.Incrementor.create().withMaximalCount(maxIterations);
         this.listeners = new CopyOnWriteArrayList<IterationListener>();
     }
 
@@ -54,10 +54,32 @@ public class IterationManager {
      * iterations has been reached
      * @throws org.apache.commons.math3.exception.NullArgumentException if 
{@code callBack} is {@code null}
      * @since 3.1
+     * @deprecated as of 3.6, replaced with {@link #IterationManager(int,
+     * 
org.apache.commons.math3.util.IntegerSequence.Incrementor.MaxCountExceededCallback)}
      */
+    @Deprecated
     public IterationManager(final int maxIterations,
                             final Incrementor.MaxCountExceededCallback 
callBack) {
-        this.iterations = new Incrementor(maxIterations, callBack);
+        this(maxIterations, new 
IntegerSequence.Incrementor.MaxCountExceededCallback() {
+            @Override
+            public void trigger(final int maximalCount) throws 
MaxCountExceededException {
+                callBack.trigger(maximalCount);
+            }
+        });
+    }
+
+    /**
+     * Creates a new instance of this class.
+     *
+     * @param maxIterations the maximum number of iterations
+     * @param callBack the function to be called when the maximum number of
+     * iterations has been reached
+     * @throws org.apache.commons.math3.exception.NullArgumentException if 
{@code callBack} is {@code null}
+     * @since 3.6
+     */
+    public IterationManager(final int maxIterations,
+                            final 
IntegerSequence.Incrementor.MaxCountExceededCallback callBack) {
+        this.iterations = 
IntegerSequence.Incrementor.create().withMaximalCount(maxIterations).withCallback(callBack);
         this.listeners = new CopyOnWriteArrayList<IterationListener>();
     }
 
@@ -147,7 +169,7 @@ public class IterationManager {
      */
     public void incrementIterationCount()
         throws MaxCountExceededException {
-        iterations.incrementCount();
+        iterations.increment();
     }
 
     /**
@@ -167,6 +189,6 @@ public class IterationManager {
      * initial phase.
      */
     public void resetIterationCount() {
-        iterations.resetCount();
+        iterations = iterations.withStart(0);
     }
 }

Reply via email to