diff --git a/src/main/java/org/apache/commons/math/optimization/univariate/MultiStartUnivariateRealOptimizer.java b/src/main/java/org/apache/commons/math/optimization/univariate/MultiStartUnivariateRealOptimizer.java index d732a548e..d06094867 100644 --- a/src/main/java/org/apache/commons/math/optimization/univariate/MultiStartUnivariateRealOptimizer.java +++ b/src/main/java/org/apache/commons/math/optimization/univariate/MultiStartUnivariateRealOptimizer.java @@ -23,6 +23,8 @@ import java.util.Comparator; import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.exception.MathUserException; import org.apache.commons.math.exception.MathIllegalStateException; +import org.apache.commons.math.exception.NotStrictlyPositiveException; +import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.exception.util.LocalizedFormats; import org.apache.commons.math.random.RandomGenerator; import org.apache.commons.math.optimization.GoalType; @@ -60,14 +62,24 @@ public class MultiStartUnivariateRealOptimizer=1. + * Multi-start is disabled if {@code starts == 1}. * @param generator Random generator to use for restarts. + * @throws NullArgumentException if {@code optimizer} or {@code generator} + * is {@code null}. + * @throws NotStrictlyPositiveException if {@code starts < 1}. */ public MultiStartUnivariateRealOptimizer(final BaseUnivariateRealOptimizer optimizer, final int starts, final RandomGenerator generator) { + if (optimizer == null || + generator == null) { + throw new NullArgumentException(); + } + if (starts < 1) { + throw new NotStrictlyPositiveException(starts); + } + this.optimizer = optimizer; this.starts = starts; this.generator = generator; @@ -163,7 +175,7 @@ public class MultiStartUnivariateRealOptimizer=1 } // Return the point with the best objective function value.