Author: luc
Date: Mon Feb 12 11:28:57 2007
New Revision: 506595

URL: http://svn.apache.org/viewvc?view=rev&rev=506595
Log:
Added and used a specialized exception for arguments outside domains

Added:
    
jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ArgumentOutsideDomainException.java
   (with props)
    
jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ArgumentOutsideDomainExceptionTest.java
   (with props)
Modified:
    
jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/PolynomialSplineFunction.java

Added: 
jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ArgumentOutsideDomainException.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ArgumentOutsideDomainException.java?view=auto&rev=506595
==============================================================================
--- 
jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ArgumentOutsideDomainException.java
 (added)
+++ 
jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ArgumentOutsideDomainException.java
 Mon Feb 12 11:28:57 2007
@@ -0,0 +1,21 @@
+package org.apache.commons.math;
+
+public class ArgumentOutsideDomainException extends 
FunctionEvaluationException {
+
+    /** Serializable version identifier. */
+    private static final long serialVersionUID = -4965972841162580234L;
+
+    /**
+     * Constructs an exception with specified formatted detail message.
+     * Message formatting is delegated to [EMAIL PROTECTED] 
java.text.MessageFormat}.
+     * @param argument  the failing function argument 
+     * @param lower lower bound of the domain
+     * @param upper upper bound of the domain
+     */
+    public ArgumentOutsideDomainException(double argument, double lower, 
double upper) {
+        super(argument,
+              "Argument {0} outside domain [{1} ; {2}]",
+              new Object[] { new Double(argument), new Double(lower), new 
Double(upper) });
+    }
+
+}

Propchange: 
jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ArgumentOutsideDomainException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/PolynomialSplineFunction.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/PolynomialSplineFunction.java?view=diff&rev=506595&r1=506594&r2=506595
==============================================================================
--- 
jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/PolynomialSplineFunction.java
 (original)
+++ 
jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/PolynomialSplineFunction.java
 Mon Feb 12 11:28:57 2007
@@ -19,7 +19,7 @@
 import java.io.Serializable;
 import java.util.Arrays;
 
-import org.apache.commons.math.FunctionEvaluationException;
+import org.apache.commons.math.ArgumentOutsideDomainException;
 
 /**
  * Represents a polynomial spline function.
@@ -55,10 +55,10 @@
  */
 public class PolynomialSplineFunction 
     implements DifferentiableUnivariateRealFunction, Serializable {
-   
+
     /** Serializable version identifier */
-    private static final long serialVersionUID = 7011031166416885789L;
-    
+    private static final long serialVersionUID = 1619940313389547244L;
+
     /** Spline segment interval delimiters (knots).   Size is n+1 for n 
segments. */
     private double knots[];
 
@@ -125,13 +125,13 @@
      * 
      * @param v the point for which the function value should be computed
      * @return the value
-     * @throws FunctionEvaluationException if v is outside of the domain of
+     * @throws ArgumentOutsideDomainException if v is outside of the domain of
      * of the spline function (less than the smallest knot point or greater
      * than the largest knot point)
      */
-    public double value(double v) throws FunctionEvaluationException {
+    public double value(double v) throws ArgumentOutsideDomainException {
         if (v < knots[0] || v > knots[n]) {
-            throw new FunctionEvaluationException(v,"Argument outside domain");
+            throw new ArgumentOutsideDomainException(v, knots[0], knots[n]);
         }
         int i = Arrays.binarySearch(knots, v);
         if (i < 0) {

Added: 
jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ArgumentOutsideDomainExceptionTest.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ArgumentOutsideDomainExceptionTest.java?view=auto&rev=506595
==============================================================================
--- 
jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ArgumentOutsideDomainExceptionTest.java
 (added)
+++ 
jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ArgumentOutsideDomainExceptionTest.java
 Mon Feb 12 11:28:57 2007
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.math;
+
+import java.util.Locale;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Revision:$
+ */
+public class ArgumentOutsideDomainExceptionTest extends TestCase {
+    
+    public void testConstructor(){
+        ArgumentOutsideDomainException ex = new 
ArgumentOutsideDomainException(Math.PI, 10.0, 20.0);
+        assertNull(ex.getCause());
+        assertNotNull(ex.getMessage());
+        assertTrue(ex.getMessage().indexOf("3.14") > 0);
+        assertEquals(Math.PI, ex.getArgument(), 0);
+        assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH)));
+    }
+    
+}

Propchange: 
jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ArgumentOutsideDomainExceptionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to