From b1741d1b461795f7de1b2ebccd24405fb875dddd Mon Sep 17 00:00:00 2001 From: Gilles Sadowski Date: Thu, 16 Aug 2012 21:00:39 +0000 Subject: [PATCH] Precondition check. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1374054 13f79535-47bb-0310-9956-ffa450edef68 --- .../gauss/LegendreHighPrecisionRuleFactory.java | 7 +++++++ .../analysis/integration/gauss/LegendreRuleFactory.java | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/main/java/org/apache/commons/math3/analysis/integration/gauss/LegendreHighPrecisionRuleFactory.java b/src/main/java/org/apache/commons/math3/analysis/integration/gauss/LegendreHighPrecisionRuleFactory.java index cf17713b5..09c580044 100644 --- a/src/main/java/org/apache/commons/math3/analysis/integration/gauss/LegendreHighPrecisionRuleFactory.java +++ b/src/main/java/org/apache/commons/math3/analysis/integration/gauss/LegendreHighPrecisionRuleFactory.java @@ -19,6 +19,8 @@ package org.apache.commons.math3.analysis.integration.gauss; import java.math.MathContext; import java.math.BigDecimal; import org.apache.commons.math3.util.Pair; +import org.apache.commons.math3.exception.NotStrictlyPositiveException; +import org.apache.commons.math3.exception.util.LocalizedFormats; /** * Factory that creates Gauss-type quadrature rule using Legendre polynomials. @@ -63,6 +65,11 @@ public class LegendreHighPrecisionRuleFactory extends BaseRuleFactory computeRule(int numberOfPoints) { + if (numberOfPoints <= 0) { + throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_POINTS, + numberOfPoints); + } + if (numberOfPoints == 1) { // Break recursion. return new Pair(new BigDecimal[] { BigDecimal.ZERO }, diff --git a/src/main/java/org/apache/commons/math3/analysis/integration/gauss/LegendreRuleFactory.java b/src/main/java/org/apache/commons/math3/analysis/integration/gauss/LegendreRuleFactory.java index e3471ede5..a794acce9 100644 --- a/src/main/java/org/apache/commons/math3/analysis/integration/gauss/LegendreRuleFactory.java +++ b/src/main/java/org/apache/commons/math3/analysis/integration/gauss/LegendreRuleFactory.java @@ -17,6 +17,8 @@ package org.apache.commons.math3.analysis.integration.gauss; import org.apache.commons.math3.util.Pair; +import org.apache.commons.math3.exception.NotStrictlyPositiveException; +import org.apache.commons.math3.exception.util.LocalizedFormats; /** * Factory that creates Gauss-type quadrature rule using Legendre polynomials. @@ -35,6 +37,11 @@ public class LegendreRuleFactory extends BaseRuleFactory { */ @Override protected Pair computeRule(int numberOfPoints) { + if (numberOfPoints <= 0) { + throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_POINTS, + numberOfPoints); + } + if (numberOfPoints == 1) { // Break recursion. return new Pair(new Double[] { 0d },