From 692c542c5e3038ec9edc5a05ca6ea7c4d2f070ff Mon Sep 17 00:00:00 2001 From: Sebastien Brisard Date: Mon, 25 Jun 2012 05:22:58 +0000 Subject: [PATCH] Reverted changes committed in r1353140. In o.a.c.m3.util.Incrementor, a NullPointerException is now thrown if the call-back function specified at construction is null. o.a.c.m3.util.IterationManager was updated accordingly (used to explicitely use the constructor with null argument). git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1353386 13f79535-47bb-0310-9956-ffa450edef68 --- .../commons/math3/util/Incrementor.java | 26 +++++++++---------- .../commons/math3/util/IterationManager.java | 9 +++++-- 2 files changed, 20 insertions(+), 15 deletions(-) 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 972b57928..f3c5227a0 100644 --- a/src/main/java/org/apache/commons/math3/util/Incrementor.java +++ b/src/main/java/org/apache/commons/math3/util/Incrementor.java @@ -58,7 +58,13 @@ public class Incrementor { * @param max Maximal count. */ public Incrementor(int max) { - this(max, null); + this(max, + new MaxCountExceededCallback() { + /** {@inheritDoc} */ + public void trigger(int max) { + throw new MaxCountExceededException(max); + } + }); } /** @@ -66,22 +72,16 @@ public class Incrementor { * counter exhaustion. * * @param max Maximal count. - * @param cb Function to be called when the maximal count has been reached - * (can be {@code null}). + * @param cb Function to be called when the maximal count has been reached. + * @throws NullPointerException if {@code cb} is {@code null} */ public Incrementor(int max, MaxCountExceededCallback cb) { - maximalCount = max; - if (cb != null) { - maxCountCallback = cb; - } else { - maxCountCallback = new MaxCountExceededCallback() { - /** {@inheritDoc} */ - public void trigger(int max) { - throw new MaxCountExceededException(max); - } - }; + if (cb == null){ + throw new NullPointerException(); } + maximalCount = max; + maxCountCallback = cb; } /** 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 dd10fe044..7ba99c209 100644 --- a/src/main/java/org/apache/commons/math3/util/IterationManager.java +++ b/src/main/java/org/apache/commons/math3/util/IterationManager.java @@ -43,7 +43,8 @@ public class IterationManager { * @param maxIterations the maximum number of iterations */ public IterationManager(final int maxIterations) { - this(maxIterations, null); + this.iterations = new Incrementor(maxIterations); + this.listeners = new CopyOnWriteArrayList(); } /** @@ -51,10 +52,14 @@ public class IterationManager { * * @param maxIterations the maximum number of iterations * @param callBack the function to be called when the maximum number of - * iterations has been reached (can be {@code null}) + * iterations has been reached + * @throws NullPointerException if {@code callBack} is {@code null} */ public IterationManager(final int maxIterations, final Incrementor.MaxCountExceededCallback callBack) { + if (callBack == null) { + throw new NullPointerException(); + } this.iterations = new Incrementor(maxIterations, callBack); this.listeners = new CopyOnWriteArrayList(); }