commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r506713 [1/4] - in /jakarta/commons/proper/math/trunk: ./ src/java/org/apache/commons/math/analysis/ src/java/org/apache/commons/math/distribution/ src/java/org/apache/commons/math/fraction/ src/test/org/apache/commons/math/analysis/ src/te...
Date Mon, 12 Feb 2007 22:35:10 GMT
Author: luc
Date: Mon Feb 12 14:35:08 2007
New Revision: 506713

URL: http://svn.apache.org/viewvc?view=rev&rev=506713
Log:
set eol-style property to native

Modified:
    jakarta/commons/proper/math/trunk/release-notes.jsl   (props changed)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/NevilleInterpolator.java   (contents, props changed)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/PolynomialFunctionNewtonForm.java   (contents, props changed)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/distribution/CauchyDistribution.java   (contents, props changed)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/distribution/CauchyDistributionImpl.java   (contents, props changed)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/distribution/WeibullDistribution.java   (contents, props changed)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/distribution/WeibullDistributionImpl.java   (contents, props changed)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/FractionFormat.java   (contents, props changed)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/ProperFractionFormat.java   (contents, props changed)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/package.html   (contents, props changed)
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/DividedDifferenceInterpolatorTest.java   (contents, props changed)
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/Expm1Function.java   (contents, props changed)
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/LaguerreSolverTest.java   (contents, props changed)
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/MullerSolverTest.java   (contents, props changed)
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/NevilleInterpolatorTest.java   (contents, props changed)
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/PolynomialFunctionLagrangeFormTest.java   (contents, props changed)
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/PolynomialFunctionNewtonFormTest.java   (contents, props changed)
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/RiddersSolverTest.java   (contents, props changed)
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/distribution/CauchyDistributionTest.java   (contents, props changed)
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/distribution/WeibullDistributionTest.java   (contents, props changed)
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/fraction/FractionFormatTest.java   (contents, props changed)
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/fraction/FractionTest.java   (contents, props changed)
    jakarta/commons/proper/math/trunk/test-jar.xml   (props changed)
    jakarta/commons/proper/math/trunk/xdocs/userguide/fraction.xml   (contents, props changed)

Propchange: jakarta/commons/proper/math/trunk/release-notes.jsl
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/NevilleInterpolator.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/NevilleInterpolator.java?view=diff&rev=506713&r1=506712&r2=506713
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/NevilleInterpolator.java (original)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/NevilleInterpolator.java Mon Feb 12 14:35:08 2007
@@ -1,54 +1,54 @@
-/*
- * 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.analysis;
-
-import java.io.Serializable;
-import org.apache.commons.math.MathException;
-
-/**
- * Implements the <a href="http://mathworld.wolfram.com/NevillesAlgorithm.html">
- * Neville's Algorithm</a> for interpolation of real univariate functions. For
- * reference, see <b>Introduction to Numerical Analysis</b>, ISBN 038795452X,
- * chapter 2.
- * <p>
- * The actual code of Neville's evalution is in PolynomialFunctionLagrangeForm,
- * this class provides an easy-to-use interface to it.
- *
- * @version $Revision$ $Date$
- */
-public class NevilleInterpolator implements UnivariateRealInterpolator,
-    Serializable {
-
-    /** serializable version identifier */
-    static final long serialVersionUID = 3003707660147873733L;
-
-    /**
-     * Computes an interpolating function for the data set.
-     *
-     * @param x the interpolating points array
-     * @param y the interpolating values array
-     * @return a function which interpolates the data set
-     * @throws MathException if arguments are invalid
-     */
-    public UnivariateRealFunction interpolate(double x[], double y[]) throws
-        MathException {
-
-        PolynomialFunctionLagrangeForm p;
-        p = new PolynomialFunctionLagrangeForm(x, y);
-        return p;
-    }
-}
+/*
+ * 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.analysis;
+
+import java.io.Serializable;
+import org.apache.commons.math.MathException;
+
+/**
+ * Implements the <a href="http://mathworld.wolfram.com/NevillesAlgorithm.html">
+ * Neville's Algorithm</a> for interpolation of real univariate functions. For
+ * reference, see <b>Introduction to Numerical Analysis</b>, ISBN 038795452X,
+ * chapter 2.
+ * <p>
+ * The actual code of Neville's evalution is in PolynomialFunctionLagrangeForm,
+ * this class provides an easy-to-use interface to it.
+ *
+ * @version $Revision$ $Date$
+ */
+public class NevilleInterpolator implements UnivariateRealInterpolator,
+    Serializable {
+
+    /** serializable version identifier */
+    static final long serialVersionUID = 3003707660147873733L;
+
+    /**
+     * Computes an interpolating function for the data set.
+     *
+     * @param x the interpolating points array
+     * @param y the interpolating values array
+     * @return a function which interpolates the data set
+     * @throws MathException if arguments are invalid
+     */
+    public UnivariateRealFunction interpolate(double x[], double y[]) throws
+        MathException {
+
+        PolynomialFunctionLagrangeForm p;
+        p = new PolynomialFunctionLagrangeForm(x, y);
+        return p;
+    }
+}

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

Propchange: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/NevilleInterpolator.java
            ('svn:executable' removed)

Modified: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/PolynomialFunctionNewtonForm.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/PolynomialFunctionNewtonForm.java?view=diff&rev=506713&r1=506712&r2=506713
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/PolynomialFunctionNewtonForm.java (original)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/PolynomialFunctionNewtonForm.java Mon Feb 12 14:35:08 2007
@@ -1,215 +1,215 @@
-/*
- * 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.analysis;
-
-import java.io.Serializable;
-import org.apache.commons.math.FunctionEvaluationException;
-
-/**
- * Implements the representation of a real polynomial function in
- * Newton Form. For reference, see <b>Elementary Numerical Analysis</b>,
- * ISBN 0070124477, chapter 2.
- * <p>
- * The formula of polynomial in Newton form is
- *     p(x) = a[0] + a[1](x-c[0]) + a[2](x-c[0])(x-c[1]) + ... +
- *            a[n](x-c[0])(x-c[1])...(x-c[n-1])
- * Note that the length of a[] is one more than the length of c[]
- *
- * @version $Revision$ $Date$
- */
-public class PolynomialFunctionNewtonForm implements UnivariateRealFunction,
-    Serializable {
-
-    /** serializable version identifier */
-    static final long serialVersionUID = -3353896576191389897L;
-
-    /**
-     * The coefficients of the polynomial, ordered by degree -- i.e.
-     * coefficients[0] is the constant term and coefficients[n] is the 
-     * coefficient of x^n where n is the degree of the polynomial.
-     */
-    private double coefficients[];
-
-    /**
-     * Members of c[] are called centers of the Newton polynomial.
-     * When all c[i] = 0, a[] becomes normal polynomial coefficients,
-     * i.e. a[i] = coefficients[i].
-     */
-    private double a[], c[];
-
-    /**
-     * Whether the polynomial coefficients are available.
-     */
-    private boolean coefficientsComputed;
-
-    /**
-     * Construct a Newton polynomial with the given a[] and c[]. The order of
-     * centers are important in that if c[] shuffle, then values of a[] would
-     * completely change, not just a permutation of old a[].
-     * <p>
-     * The constructor makes copy of the input arrays and assigns them.
-     * 
-     * @param a the coefficients in Newton form formula
-     * @param c the centers
-     * @throws IllegalArgumentException if input arrays are not valid
-     */
-    PolynomialFunctionNewtonForm(double a[], double c[]) throws
-        IllegalArgumentException {
-
-        verifyInputArray(a, c);
-        this.a = new double[a.length];
-        this.c = new double[c.length];
-        System.arraycopy(a, 0, this.a, 0, a.length);
-        System.arraycopy(c, 0, this.c, 0, c.length);
-        coefficientsComputed = false;
-    }
-
-    /**
-     * Calculate the function value at the given point.
-     *
-     * @param z the point at which the function value is to be computed
-     * @return the function value
-     * @throws FunctionEvaluationException if a runtime error occurs
-     * @see UnivariateRealFunction#value(double)
-     */
-    public double value(double z) throws FunctionEvaluationException {
-       return evaluate(a, c, z);
-    }
-
-    /**
-     * Returns the degree of the polynomial.
-     * 
-     * @return the degree of the polynomial
-     */
-    public int degree() {
-        return c.length;
-    }
-
-    /**
-     * Returns a copy of coefficients in Newton form formula.
-     * <p>
-     * Changes made to the returned copy will not affect the polynomial.
-     * 
-     * @return a fresh copy of coefficients in Newton form formula
-     */
-    public double[] getNewtonCoefficients() {
-        double[] out = new double[a.length];
-        System.arraycopy(a, 0, out, 0, a.length);
-        return out;
-    }
-
-    /**
-     * Returns a copy of the centers array.
-     * <p>
-     * Changes made to the returned copy will not affect the polynomial.
-     * 
-     * @return a fresh copy of the centers array
-     */
-    public double[] getCenters() {
-        double[] out = new double[c.length];
-        System.arraycopy(c, 0, out, 0, c.length);
-        return out;
-    }
-
-    /**
-     * Returns a copy of the coefficients array.
-     * <p>
-     * Changes made to the returned copy will not affect the polynomial.
-     * 
-     * @return a fresh copy of the coefficients array
-     */
-    public double[] getCoefficients() {
-        if (!coefficientsComputed) {
-            computeCoefficients();
-        }
-        double[] out = new double[coefficients.length];
-        System.arraycopy(coefficients, 0, out, 0, coefficients.length);
-        return out;
-    }
-
-    /**
-     * Evaluate the Newton polynomial using nested multiplication. It is
-     * also called <a href="http://mathworld.wolfram.com/HornersRule.html">
-     * Horner's Rule</a> and takes O(N) time.
-     *
-     * @param a the coefficients in Newton form formula
-     * @param c the centers
-     * @param z the point at which the function value is to be computed
-     * @return the function value
-     * @throws FunctionEvaluationException if a runtime error occurs
-     * @throws IllegalArgumentException if inputs are not valid
-     */
-    public static double evaluate(double a[], double c[], double z) throws
-        FunctionEvaluationException, IllegalArgumentException {
-
-        verifyInputArray(a, c);
-
-        int n = c.length;
-        double value = a[n];
-        for (int i = n-1; i >= 0; i--) {
-            value = a[i] + (z - c[i]) * value;
-        }
-
-        return value;
-    }
-
-    /**
-     * Calculate the normal polynomial coefficients given the Newton form.
-     * It also uses nested multiplication but takes O(N^2) time.
-     */
-    protected void computeCoefficients() {
-        int i, j, n = degree();
-
-        coefficients = new double[n+1];
-        for (i = 0; i <= n; i++) {
-            coefficients[i] = 0.0;
-        }
-
-        coefficients[0] = a[n];
-        for (i = n-1; i >= 0; i--) {
-            for (j = n-i; j > 0; j--) {
-                coefficients[j] = coefficients[j-1] - c[i] * coefficients[j];
-            }
-            coefficients[0] = a[i] - c[i] * coefficients[0];
-        }
-
-        coefficientsComputed = true;
-    }
-
-    /**
-     * Verifies that the input arrays are valid.
-     * <p>
-     * The centers must be distinct for interpolation purposes, but not
-     * for general use. Thus it is not verified here.
-     * 
-     * @throws IllegalArgumentException if not valid
-     * @see DividedDifferenceInterpolator#computeDividedDifference(double[],
-     * double[])
-     */
-    protected static void verifyInputArray(double a[], double c[]) throws
-        IllegalArgumentException {
-
-        if (a.length < 1 || c.length < 1) {
-            throw new IllegalArgumentException
-                ("Input arrays must not be empty.");
-        }
-        if (a.length != c.length + 1) {
-            throw new IllegalArgumentException
-                ("Bad input array sizes, should have difference 1.");
-        }
-    }
-}
+/*
+ * 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.analysis;
+
+import java.io.Serializable;
+import org.apache.commons.math.FunctionEvaluationException;
+
+/**
+ * Implements the representation of a real polynomial function in
+ * Newton Form. For reference, see <b>Elementary Numerical Analysis</b>,
+ * ISBN 0070124477, chapter 2.
+ * <p>
+ * The formula of polynomial in Newton form is
+ *     p(x) = a[0] + a[1](x-c[0]) + a[2](x-c[0])(x-c[1]) + ... +
+ *            a[n](x-c[0])(x-c[1])...(x-c[n-1])
+ * Note that the length of a[] is one more than the length of c[]
+ *
+ * @version $Revision$ $Date$
+ */
+public class PolynomialFunctionNewtonForm implements UnivariateRealFunction,
+    Serializable {
+
+    /** serializable version identifier */
+    static final long serialVersionUID = -3353896576191389897L;
+
+    /**
+     * The coefficients of the polynomial, ordered by degree -- i.e.
+     * coefficients[0] is the constant term and coefficients[n] is the 
+     * coefficient of x^n where n is the degree of the polynomial.
+     */
+    private double coefficients[];
+
+    /**
+     * Members of c[] are called centers of the Newton polynomial.
+     * When all c[i] = 0, a[] becomes normal polynomial coefficients,
+     * i.e. a[i] = coefficients[i].
+     */
+    private double a[], c[];
+
+    /**
+     * Whether the polynomial coefficients are available.
+     */
+    private boolean coefficientsComputed;
+
+    /**
+     * Construct a Newton polynomial with the given a[] and c[]. The order of
+     * centers are important in that if c[] shuffle, then values of a[] would
+     * completely change, not just a permutation of old a[].
+     * <p>
+     * The constructor makes copy of the input arrays and assigns them.
+     * 
+     * @param a the coefficients in Newton form formula
+     * @param c the centers
+     * @throws IllegalArgumentException if input arrays are not valid
+     */
+    PolynomialFunctionNewtonForm(double a[], double c[]) throws
+        IllegalArgumentException {
+
+        verifyInputArray(a, c);
+        this.a = new double[a.length];
+        this.c = new double[c.length];
+        System.arraycopy(a, 0, this.a, 0, a.length);
+        System.arraycopy(c, 0, this.c, 0, c.length);
+        coefficientsComputed = false;
+    }
+
+    /**
+     * Calculate the function value at the given point.
+     *
+     * @param z the point at which the function value is to be computed
+     * @return the function value
+     * @throws FunctionEvaluationException if a runtime error occurs
+     * @see UnivariateRealFunction#value(double)
+     */
+    public double value(double z) throws FunctionEvaluationException {
+       return evaluate(a, c, z);
+    }
+
+    /**
+     * Returns the degree of the polynomial.
+     * 
+     * @return the degree of the polynomial
+     */
+    public int degree() {
+        return c.length;
+    }
+
+    /**
+     * Returns a copy of coefficients in Newton form formula.
+     * <p>
+     * Changes made to the returned copy will not affect the polynomial.
+     * 
+     * @return a fresh copy of coefficients in Newton form formula
+     */
+    public double[] getNewtonCoefficients() {
+        double[] out = new double[a.length];
+        System.arraycopy(a, 0, out, 0, a.length);
+        return out;
+    }
+
+    /**
+     * Returns a copy of the centers array.
+     * <p>
+     * Changes made to the returned copy will not affect the polynomial.
+     * 
+     * @return a fresh copy of the centers array
+     */
+    public double[] getCenters() {
+        double[] out = new double[c.length];
+        System.arraycopy(c, 0, out, 0, c.length);
+        return out;
+    }
+
+    /**
+     * Returns a copy of the coefficients array.
+     * <p>
+     * Changes made to the returned copy will not affect the polynomial.
+     * 
+     * @return a fresh copy of the coefficients array
+     */
+    public double[] getCoefficients() {
+        if (!coefficientsComputed) {
+            computeCoefficients();
+        }
+        double[] out = new double[coefficients.length];
+        System.arraycopy(coefficients, 0, out, 0, coefficients.length);
+        return out;
+    }
+
+    /**
+     * Evaluate the Newton polynomial using nested multiplication. It is
+     * also called <a href="http://mathworld.wolfram.com/HornersRule.html">
+     * Horner's Rule</a> and takes O(N) time.
+     *
+     * @param a the coefficients in Newton form formula
+     * @param c the centers
+     * @param z the point at which the function value is to be computed
+     * @return the function value
+     * @throws FunctionEvaluationException if a runtime error occurs
+     * @throws IllegalArgumentException if inputs are not valid
+     */
+    public static double evaluate(double a[], double c[], double z) throws
+        FunctionEvaluationException, IllegalArgumentException {
+
+        verifyInputArray(a, c);
+
+        int n = c.length;
+        double value = a[n];
+        for (int i = n-1; i >= 0; i--) {
+            value = a[i] + (z - c[i]) * value;
+        }
+
+        return value;
+    }
+
+    /**
+     * Calculate the normal polynomial coefficients given the Newton form.
+     * It also uses nested multiplication but takes O(N^2) time.
+     */
+    protected void computeCoefficients() {
+        int i, j, n = degree();
+
+        coefficients = new double[n+1];
+        for (i = 0; i <= n; i++) {
+            coefficients[i] = 0.0;
+        }
+
+        coefficients[0] = a[n];
+        for (i = n-1; i >= 0; i--) {
+            for (j = n-i; j > 0; j--) {
+                coefficients[j] = coefficients[j-1] - c[i] * coefficients[j];
+            }
+            coefficients[0] = a[i] - c[i] * coefficients[0];
+        }
+
+        coefficientsComputed = true;
+    }
+
+    /**
+     * Verifies that the input arrays are valid.
+     * <p>
+     * The centers must be distinct for interpolation purposes, but not
+     * for general use. Thus it is not verified here.
+     * 
+     * @throws IllegalArgumentException if not valid
+     * @see DividedDifferenceInterpolator#computeDividedDifference(double[],
+     * double[])
+     */
+    protected static void verifyInputArray(double a[], double c[]) throws
+        IllegalArgumentException {
+
+        if (a.length < 1 || c.length < 1) {
+            throw new IllegalArgumentException
+                ("Input arrays must not be empty.");
+        }
+        if (a.length != c.length + 1) {
+            throw new IllegalArgumentException
+                ("Bad input array sizes, should have difference 1.");
+        }
+    }
+}

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

Propchange: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/PolynomialFunctionNewtonForm.java
            ('svn:executable' removed)

Modified: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/distribution/CauchyDistribution.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/distribution/CauchyDistribution.java?view=diff&rev=506713&r1=506712&r2=506713
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/distribution/CauchyDistribution.java (original)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/distribution/CauchyDistribution.java Mon Feb 12 14:35:08 2007
@@ -1,61 +1,61 @@
-/*
- * 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.distribution;
-
-/**
- * Cauchy Distribution.
- * Instances of CauchyDistribution objects should be created using
- * {@link DistributionFactory#createCauchyDistribution(double, double)}.<p>
- *
- * <p>
- * References:<p>
- * <ul>
- * <li><a href="http://mathworld.wolfram.com/CauchyDistribution.html">
- * Cauchy Distribution</a></li>
- * </ul>
- * </p>
- *
- * @since 1.1
- * @version $Revision$ $Date$
- */
-public interface CauchyDistribution extends ContinuousDistribution {
-    
-    /**
-     * Access the median.
-     * @return median for this distribution
-     */
-    double getMedian();
-    
-    /**
-     * Access the scale parameter.
-     * @return scale parameter for this distribution
-     */
-    double getScale();
-    
-    /**
-     * Modify the median.
-     * @param median for this distribution
-     */
-    void setMedian(double median);
-    
-    /**
-     * Modify the scale parameter.
-     * @param s scale parameter for this distribution
-     */
-    void setScale(double s);
-}
+/*
+ * 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.distribution;
+
+/**
+ * Cauchy Distribution.
+ * Instances of CauchyDistribution objects should be created using
+ * {@link DistributionFactory#createCauchyDistribution(double, double)}.<p>
+ *
+ * <p>
+ * References:<p>
+ * <ul>
+ * <li><a href="http://mathworld.wolfram.com/CauchyDistribution.html">
+ * Cauchy Distribution</a></li>
+ * </ul>
+ * </p>
+ *
+ * @since 1.1
+ * @version $Revision$ $Date$
+ */
+public interface CauchyDistribution extends ContinuousDistribution {
+    
+    /**
+     * Access the median.
+     * @return median for this distribution
+     */
+    double getMedian();
+    
+    /**
+     * Access the scale parameter.
+     * @return scale parameter for this distribution
+     */
+    double getScale();
+    
+    /**
+     * Modify the median.
+     * @param median for this distribution
+     */
+    void setMedian(double median);
+    
+    /**
+     * Modify the scale parameter.
+     * @param s scale parameter for this distribution
+     */
+    void setScale(double s);
+}

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

Modified: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/distribution/CauchyDistributionImpl.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/distribution/CauchyDistributionImpl.java?view=diff&rev=506713&r1=506712&r2=506713
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/distribution/CauchyDistributionImpl.java (original)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/distribution/CauchyDistributionImpl.java Mon Feb 12 14:35:08 2007
@@ -1,196 +1,196 @@
-/*
- * 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.distribution;
-
-import java.io.Serializable;
-
-/**
- * Default implementation of
- * {@link org.apache.commons.math.distribution.CauchyDistribution}.
- *
- * @since 1.1
- * @version $Revision$ $Date$
- */
-public class CauchyDistributionImpl extends AbstractContinuousDistribution 
-        implements CauchyDistribution, Serializable {
-    
-    /** Serializable version identifier */
-    private static final long serialVersionUID = 8589540077390120676L;
-
-    /** The median of this distribution. */
-    private double median = 0;
-    
-    /** The scale of this distribution. */
-    private double scale = 1;
-    
-    /**
-     * Creates cauchy distribution with the medain equal to zero and scale
-     * equal to one. 
-     */
-    public CauchyDistributionImpl(){
-        this(0.0, 1.0);
-    }
-    
-    /**
-     * Create a cauchy distribution using the given median and scale.
-     * @param median median for this distribution
-     * @param s scale parameter for this distribution
-     */
-    public CauchyDistributionImpl(double median, double s){
-        super();
-        setMedian(median);
-        setScale(s);
-    }
-
-    /**
-     * For this disbution, X, this method returns P(X &lt; <code>x</code>).
-     * @param x the value at which the CDF is evaluated.
-     * @return CDF evaluted at <code>x</code>. 
-     */
-    public double cumulativeProbability(double x) {
-        return 0.5 + (Math.atan((x - median) / scale) / Math.PI);
-    }
-    
-    /**
-     * Access the median.
-     * @return median for this distribution
-     */ 
-    public double getMedian() {
-        return median;
-    }
-
-    /**
-     * Access the scale parameter.
-     * @return scale parameter for this distribution
-     */
-    public double getScale() {
-        return scale;
-    }
-    
-    /**
-     * For this distribution, X, this method returns the critical point x, such
-     * that P(X &lt; x) = <code>p</code>.
-     * <p>
-     * Returns <code>Double.NEGATIVE_INFINITY</code> for p=0 and 
-     * <code>Double.POSITIVE_INFINITY</code> for p=1.
-     *
-     * @param p the desired probability
-     * @return x, such that P(X &lt; x) = <code>p</code>
-     * @throws IllegalArgumentException if <code>p</code> is not a valid
-     *         probability.
-     */
-    public double inverseCumulativeProbability(double p) {
-        double ret;
-        if (p < 0.0 || p > 1.0) {
-            throw new IllegalArgumentException
-                ("probability argument must be between 0 and 1 (inclusive)");
-        } else if (p == 0) {
-            ret = Double.NEGATIVE_INFINITY;
-        } else  if (p == 1) {
-            ret = Double.POSITIVE_INFINITY;
-        } else {
-            ret = median + scale * Math.tan(Math.PI * (p - .5));
-        }
-        return ret;
-    }
-    
-    /**
-     * Modify the median.
-     * @param median for this distribution
-     */
-    public void setMedian(double median) {
-        this.median = median;
-    }
-
-    /**
-     * Modify the scale parameter.
-     * @param s scale parameter for this distribution
-     * @throws IllegalArgumentException if <code>sd</code> is not positive.
-     */
-    public void setScale(double s) {
-        if (s <= 0.0) {
-            throw new IllegalArgumentException(
-                "Scale must be positive.");
-        }       
-        scale = s;
-    }
-    
-    /**
-     * Access the domain value lower bound, based on <code>p</code>, used to
-     * bracket a CDF root.  This method is used by
-     * {@link #inverseCumulativeProbability(double)} to find critical values.
-     * 
-     * @param p the desired probability for the critical value
-     * @return domain value lower bound, i.e.
-     *         P(X &lt; <i>lower bound</i>) &lt; <code>p</code> 
-     */
-    protected double getDomainLowerBound(double p) {
-        double ret;
-
-        if (p < .5) {
-            ret = -Double.MAX_VALUE;
-        } else {
-            ret = getMedian();
-        }
-        
-        return ret;
-    }
-
-    /**
-     * Access the domain value upper bound, based on <code>p</code>, used to
-     * bracket a CDF root.  This method is used by
-     * {@link #inverseCumulativeProbability(double)} to find critical values.
-     * 
-     * @param p the desired probability for the critical value
-     * @return domain value upper bound, i.e.
-     *         P(X &lt; <i>upper bound</i>) &gt; <code>p</code> 
-     */
-    protected double getDomainUpperBound(double p) {
-        double ret;
-
-        if (p < .5) {
-            ret = getMedian();
-        } else {
-            ret = Double.MAX_VALUE;
-        }
-        
-        return ret;
-    }
-
-    /**
-     * Access the initial domain value, based on <code>p</code>, used to
-     * bracket a CDF root.  This method is used by
-     * {@link #inverseCumulativeProbability(double)} to find critical values.
-     * 
-     * @param p the desired probability for the critical value
-     * @return initial domain value
-     */
-    protected double getInitialDomain(double p) {
-        double ret;
-
-        if (p < .5) {
-            ret = getMedian() - getScale();
-        } else if (p > .5) {
-            ret = getMedian() + getScale();
-        } else {
-            ret = getMedian();
-        }
-        
-        return ret;
-    }
-}
+/*
+ * 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.distribution;
+
+import java.io.Serializable;
+
+/**
+ * Default implementation of
+ * {@link org.apache.commons.math.distribution.CauchyDistribution}.
+ *
+ * @since 1.1
+ * @version $Revision$ $Date$
+ */
+public class CauchyDistributionImpl extends AbstractContinuousDistribution 
+        implements CauchyDistribution, Serializable {
+    
+    /** Serializable version identifier */
+    private static final long serialVersionUID = 8589540077390120676L;
+
+    /** The median of this distribution. */
+    private double median = 0;
+    
+    /** The scale of this distribution. */
+    private double scale = 1;
+    
+    /**
+     * Creates cauchy distribution with the medain equal to zero and scale
+     * equal to one. 
+     */
+    public CauchyDistributionImpl(){
+        this(0.0, 1.0);
+    }
+    
+    /**
+     * Create a cauchy distribution using the given median and scale.
+     * @param median median for this distribution
+     * @param s scale parameter for this distribution
+     */
+    public CauchyDistributionImpl(double median, double s){
+        super();
+        setMedian(median);
+        setScale(s);
+    }
+
+    /**
+     * For this disbution, X, this method returns P(X &lt; <code>x</code>).
+     * @param x the value at which the CDF is evaluated.
+     * @return CDF evaluted at <code>x</code>. 
+     */
+    public double cumulativeProbability(double x) {
+        return 0.5 + (Math.atan((x - median) / scale) / Math.PI);
+    }
+    
+    /**
+     * Access the median.
+     * @return median for this distribution
+     */ 
+    public double getMedian() {
+        return median;
+    }
+
+    /**
+     * Access the scale parameter.
+     * @return scale parameter for this distribution
+     */
+    public double getScale() {
+        return scale;
+    }
+    
+    /**
+     * For this distribution, X, this method returns the critical point x, such
+     * that P(X &lt; x) = <code>p</code>.
+     * <p>
+     * Returns <code>Double.NEGATIVE_INFINITY</code> for p=0 and 
+     * <code>Double.POSITIVE_INFINITY</code> for p=1.
+     *
+     * @param p the desired probability
+     * @return x, such that P(X &lt; x) = <code>p</code>
+     * @throws IllegalArgumentException if <code>p</code> is not a valid
+     *         probability.
+     */
+    public double inverseCumulativeProbability(double p) {
+        double ret;
+        if (p < 0.0 || p > 1.0) {
+            throw new IllegalArgumentException
+                ("probability argument must be between 0 and 1 (inclusive)");
+        } else if (p == 0) {
+            ret = Double.NEGATIVE_INFINITY;
+        } else  if (p == 1) {
+            ret = Double.POSITIVE_INFINITY;
+        } else {
+            ret = median + scale * Math.tan(Math.PI * (p - .5));
+        }
+        return ret;
+    }
+    
+    /**
+     * Modify the median.
+     * @param median for this distribution
+     */
+    public void setMedian(double median) {
+        this.median = median;
+    }
+
+    /**
+     * Modify the scale parameter.
+     * @param s scale parameter for this distribution
+     * @throws IllegalArgumentException if <code>sd</code> is not positive.
+     */
+    public void setScale(double s) {
+        if (s <= 0.0) {
+            throw new IllegalArgumentException(
+                "Scale must be positive.");
+        }       
+        scale = s;
+    }
+    
+    /**
+     * Access the domain value lower bound, based on <code>p</code>, used to
+     * bracket a CDF root.  This method is used by
+     * {@link #inverseCumulativeProbability(double)} to find critical values.
+     * 
+     * @param p the desired probability for the critical value
+     * @return domain value lower bound, i.e.
+     *         P(X &lt; <i>lower bound</i>) &lt; <code>p</code> 
+     */
+    protected double getDomainLowerBound(double p) {
+        double ret;
+
+        if (p < .5) {
+            ret = -Double.MAX_VALUE;
+        } else {
+            ret = getMedian();
+        }
+        
+        return ret;
+    }
+
+    /**
+     * Access the domain value upper bound, based on <code>p</code>, used to
+     * bracket a CDF root.  This method is used by
+     * {@link #inverseCumulativeProbability(double)} to find critical values.
+     * 
+     * @param p the desired probability for the critical value
+     * @return domain value upper bound, i.e.
+     *         P(X &lt; <i>upper bound</i>) &gt; <code>p</code> 
+     */
+    protected double getDomainUpperBound(double p) {
+        double ret;
+
+        if (p < .5) {
+            ret = getMedian();
+        } else {
+            ret = Double.MAX_VALUE;
+        }
+        
+        return ret;
+    }
+
+    /**
+     * Access the initial domain value, based on <code>p</code>, used to
+     * bracket a CDF root.  This method is used by
+     * {@link #inverseCumulativeProbability(double)} to find critical values.
+     * 
+     * @param p the desired probability for the critical value
+     * @return initial domain value
+     */
+    protected double getInitialDomain(double p) {
+        double ret;
+
+        if (p < .5) {
+            ret = getMedian() - getScale();
+        } else if (p > .5) {
+            ret = getMedian() + getScale();
+        } else {
+            ret = getMedian();
+        }
+        
+        return ret;
+    }
+}

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

Modified: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/distribution/WeibullDistribution.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/distribution/WeibullDistribution.java?view=diff&rev=506713&r1=506712&r2=506713
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/distribution/WeibullDistribution.java (original)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/distribution/WeibullDistribution.java Mon Feb 12 14:35:08 2007
@@ -1,65 +1,65 @@
-/*
- * 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.distribution;
-
-/**
- * Weibull Distribution.  This interface defines the two parameter form of the
- * distribution as defined by
- * <a href="http://mathworld.wolfram.com/WeibullDistribution.html">
- * Weibull Distribution</a>, equations (1) and (2).
- *
- * Instances of WeibullDistribution objects should be created using
- * {@link DistributionFactory#createWeibullDistribution(double, double)}
- *
- * <p>
- * References:
- * <ul>
- * <li><a href="http://mathworld.wolfram.com/WeibullDistribution.html">
- * Weibull Distribution</a></li>
- * </ul>
- * </p>
- *
- * @since 1.1
- * @version $Revision: 1.12 $ $Date: 2004-06-23 11:26:18 -0500 (Wed, 23 Jun 2004) $
- */
-public interface WeibullDistribution extends ContinuousDistribution {
-
-    /**
-     * Access the shape parameter.
-     * @return the shape parameter.
-     */
-    double getShape();
-    
-    /**
-     * Access the scale parameter.
-     * @return the scale parameter.
-     */
-    double getScale();
-    
-    /**
-     * Modify the shape parameter.
-     * @param alpha The new shape parameter value.
-     */
-    void setShape(double alpha);
-    
-    /**
-     * Modify the scale parameter.
-     * @param beta The new scale parameter value.
-     */
-    void setScale(double beta);
-}
+/*
+ * 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.distribution;
+
+/**
+ * Weibull Distribution.  This interface defines the two parameter form of the
+ * distribution as defined by
+ * <a href="http://mathworld.wolfram.com/WeibullDistribution.html">
+ * Weibull Distribution</a>, equations (1) and (2).
+ *
+ * Instances of WeibullDistribution objects should be created using
+ * {@link DistributionFactory#createWeibullDistribution(double, double)}
+ *
+ * <p>
+ * References:
+ * <ul>
+ * <li><a href="http://mathworld.wolfram.com/WeibullDistribution.html">
+ * Weibull Distribution</a></li>
+ * </ul>
+ * </p>
+ *
+ * @since 1.1
+ * @version $Revision: 1.12 $ $Date: 2004-06-23 11:26:18 -0500 (Wed, 23 Jun 2004) $
+ */
+public interface WeibullDistribution extends ContinuousDistribution {
+
+    /**
+     * Access the shape parameter.
+     * @return the shape parameter.
+     */
+    double getShape();
+    
+    /**
+     * Access the scale parameter.
+     * @return the scale parameter.
+     */
+    double getScale();
+    
+    /**
+     * Modify the shape parameter.
+     * @param alpha The new shape parameter value.
+     */
+    void setShape(double alpha);
+    
+    /**
+     * Modify the scale parameter.
+     * @param beta The new scale parameter value.
+     */
+    void setScale(double beta);
+}

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

Modified: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/distribution/WeibullDistributionImpl.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/distribution/WeibullDistributionImpl.java?view=diff&rev=506713&r1=506712&r2=506713
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/distribution/WeibullDistributionImpl.java (original)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/distribution/WeibullDistributionImpl.java Mon Feb 12 14:35:08 2007
@@ -1,173 +1,173 @@
-/*
- * 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.distribution;
-
-import java.io.Serializable;
-
-/**
- * Default implementation of
- * {@link org.apache.commons.math.distribution.WeibullDistribution}.
- *
- * @since 1.1
- * @version $Revision: 1.13 $ $Date: 2004-07-24 16:41:37 -0500 (Sat, 24 Jul 2004) $
- */
-public class WeibullDistributionImpl extends AbstractContinuousDistribution
-        implements WeibullDistribution, Serializable {
-    
-    /** Serializable version identifier */
-    private static final long serialVersionUID = 8589540077390120676L;
-    
-    /** The shape parameter. */
-    private double alpha;
-    
-    /** The scale parameter. */
-    private double beta;
-    
-    /**
-     * Creates weibull distribution with the given shape and scale and a
-     * location equal to zero.
-     * @param alpha the shape parameter.
-     * @param beta the scale parameter.
-     */
-    public WeibullDistributionImpl(double alpha, double beta){
-        super();
-        setShape(alpha);
-        setScale(beta);
-    }
-
-    /**
-     * For this disbution, X, this method returns P(X &lt; <code>x</code>).
-     * @param x the value at which the CDF is evaluated.
-     * @return CDF evaluted at <code>x</code>. 
-     */
-    public double cumulativeProbability(double x) {
-        double ret;
-        if (x <= 0.0) {
-            ret = 0.0;
-        } else {
-            ret = 1.0 - Math.exp(-Math.pow(x / getScale(), getShape()));
-        }
-        return ret;
-    }
-
-    /**
-     * Access the shape parameter.
-     * @return the shape parameter.
-     */
-    public double getShape() {
-        return alpha;
-    }
-    
-    /**
-     * Access the scale parameter.
-     * @return the scale parameter.
-     */
-    public double getScale() {
-        return beta;
-    }
-    
-    /**
-     * For this distribution, X, this method returns the critical point x, such
-     * that P(X &lt; x) = <code>p</code>.
-     * <p>
-     * Returns <code>Double.NEGATIVE_INFINITY</code> for p=0 and 
-     * <code>Double.POSITIVE_INFINITY</code> for p=1.
-     *
-     * @param p the desired probability
-     * @return x, such that P(X &lt; x) = <code>p</code>
-     * @throws IllegalArgumentException if <code>p</code> is not a valid
-     *         probability.
-     */
-    public double inverseCumulativeProbability(double p) {
-        double ret;
-        if (p < 0.0 || p > 1.0) {
-            throw new IllegalArgumentException
-                ("probability argument must be between 0 and 1 (inclusive)");
-        } else if (p == 0) {
-            ret = 0.0;
-        } else  if (p == 1) {
-            ret = Double.POSITIVE_INFINITY;
-        } else {
-            ret = getScale() * Math.pow(-Math.log(1.0 - p), 1.0 / getShape());
-        }
-        return ret;
-    }
-    
-    /**
-     * Modify the shape parameter.
-     * @param alpha the new shape parameter value.
-     */
-    public void setShape(double alpha) {
-        if (alpha <= 0.0) {
-            throw new IllegalArgumentException(
-                "Shape must be positive.");
-        }       
-        this.alpha = alpha;
-    }
-    
-    /**
-     * Modify the scale parameter.
-     * @param beta the new scale parameter value.
-     */
-    public void setScale(double beta) {
-        if (beta <= 0.0) {
-            throw new IllegalArgumentException(
-                "Scale must be positive.");
-        }       
-        this.beta = beta;
-    }
-
-    /**
-     * Access the domain value lower bound, based on <code>p</code>, used to
-     * bracket a CDF root.  This method is used by
-     * {@link #inverseCumulativeProbability(double)} to find critical values.
-     * 
-     * @param p the desired probability for the critical value
-     * @return domain value lower bound, i.e.
-     *         P(X &lt; <i>lower bound</i>) &lt; <code>p</code> 
-     */
-    protected double getDomainLowerBound(double p) {
-        return 0.0;
-    }
-
-    /**
-     * Access the domain value upper bound, based on <code>p</code>, used to
-     * bracket a CDF root.  This method is used by
-     * {@link #inverseCumulativeProbability(double)} to find critical values.
-     * 
-     * @param p the desired probability for the critical value
-     * @return domain value upper bound, i.e.
-     *         P(X &lt; <i>upper bound</i>) &gt; <code>p</code> 
-     */
-    protected double getDomainUpperBound(double p) {
-        return Double.MAX_VALUE;
-    }
-
-    /**
-     * Access the initial domain value, based on <code>p</code>, used to
-     * bracket a CDF root.  This method is used by
-     * {@link #inverseCumulativeProbability(double)} to find critical values.
-     * 
-     * @param p the desired probability for the critical value
-     * @return initial domain value
-     */
-    protected double getInitialDomain(double p) {
-        // use median
-        return Math.pow(getScale() * Math.log(2.0), 1.0 / getShape());
-    }
-}
+/*
+ * 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.distribution;
+
+import java.io.Serializable;
+
+/**
+ * Default implementation of
+ * {@link org.apache.commons.math.distribution.WeibullDistribution}.
+ *
+ * @since 1.1
+ * @version $Revision: 1.13 $ $Date: 2004-07-24 16:41:37 -0500 (Sat, 24 Jul 2004) $
+ */
+public class WeibullDistributionImpl extends AbstractContinuousDistribution
+        implements WeibullDistribution, Serializable {
+    
+    /** Serializable version identifier */
+    private static final long serialVersionUID = 8589540077390120676L;
+    
+    /** The shape parameter. */
+    private double alpha;
+    
+    /** The scale parameter. */
+    private double beta;
+    
+    /**
+     * Creates weibull distribution with the given shape and scale and a
+     * location equal to zero.
+     * @param alpha the shape parameter.
+     * @param beta the scale parameter.
+     */
+    public WeibullDistributionImpl(double alpha, double beta){
+        super();
+        setShape(alpha);
+        setScale(beta);
+    }
+
+    /**
+     * For this disbution, X, this method returns P(X &lt; <code>x</code>).
+     * @param x the value at which the CDF is evaluated.
+     * @return CDF evaluted at <code>x</code>. 
+     */
+    public double cumulativeProbability(double x) {
+        double ret;
+        if (x <= 0.0) {
+            ret = 0.0;
+        } else {
+            ret = 1.0 - Math.exp(-Math.pow(x / getScale(), getShape()));
+        }
+        return ret;
+    }
+
+    /**
+     * Access the shape parameter.
+     * @return the shape parameter.
+     */
+    public double getShape() {
+        return alpha;
+    }
+    
+    /**
+     * Access the scale parameter.
+     * @return the scale parameter.
+     */
+    public double getScale() {
+        return beta;
+    }
+    
+    /**
+     * For this distribution, X, this method returns the critical point x, such
+     * that P(X &lt; x) = <code>p</code>.
+     * <p>
+     * Returns <code>Double.NEGATIVE_INFINITY</code> for p=0 and 
+     * <code>Double.POSITIVE_INFINITY</code> for p=1.
+     *
+     * @param p the desired probability
+     * @return x, such that P(X &lt; x) = <code>p</code>
+     * @throws IllegalArgumentException if <code>p</code> is not a valid
+     *         probability.
+     */
+    public double inverseCumulativeProbability(double p) {
+        double ret;
+        if (p < 0.0 || p > 1.0) {
+            throw new IllegalArgumentException
+                ("probability argument must be between 0 and 1 (inclusive)");
+        } else if (p == 0) {
+            ret = 0.0;
+        } else  if (p == 1) {
+            ret = Double.POSITIVE_INFINITY;
+        } else {
+            ret = getScale() * Math.pow(-Math.log(1.0 - p), 1.0 / getShape());
+        }
+        return ret;
+    }
+    
+    /**
+     * Modify the shape parameter.
+     * @param alpha the new shape parameter value.
+     */
+    public void setShape(double alpha) {
+        if (alpha <= 0.0) {
+            throw new IllegalArgumentException(
+                "Shape must be positive.");
+        }       
+        this.alpha = alpha;
+    }
+    
+    /**
+     * Modify the scale parameter.
+     * @param beta the new scale parameter value.
+     */
+    public void setScale(double beta) {
+        if (beta <= 0.0) {
+            throw new IllegalArgumentException(
+                "Scale must be positive.");
+        }       
+        this.beta = beta;
+    }
+
+    /**
+     * Access the domain value lower bound, based on <code>p</code>, used to
+     * bracket a CDF root.  This method is used by
+     * {@link #inverseCumulativeProbability(double)} to find critical values.
+     * 
+     * @param p the desired probability for the critical value
+     * @return domain value lower bound, i.e.
+     *         P(X &lt; <i>lower bound</i>) &lt; <code>p</code> 
+     */
+    protected double getDomainLowerBound(double p) {
+        return 0.0;
+    }
+
+    /**
+     * Access the domain value upper bound, based on <code>p</code>, used to
+     * bracket a CDF root.  This method is used by
+     * {@link #inverseCumulativeProbability(double)} to find critical values.
+     * 
+     * @param p the desired probability for the critical value
+     * @return domain value upper bound, i.e.
+     *         P(X &lt; <i>upper bound</i>) &gt; <code>p</code> 
+     */
+    protected double getDomainUpperBound(double p) {
+        return Double.MAX_VALUE;
+    }
+
+    /**
+     * Access the initial domain value, based on <code>p</code>, used to
+     * bracket a CDF root.  This method is used by
+     * {@link #inverseCumulativeProbability(double)} to find critical values.
+     * 
+     * @param p the desired probability for the critical value
+     * @return initial domain value
+     */
+    protected double getInitialDomain(double p) {
+        // use median
+        return Math.pow(getScale() * Math.log(2.0), 1.0 / getShape());
+    }
+}

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

Modified: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/FractionFormat.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/FractionFormat.java?view=diff&rev=506713&r1=506712&r2=506713
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/FractionFormat.java (original)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/FractionFormat.java Mon Feb 12 14:35:08 2007
@@ -1,389 +1,389 @@
-/*
- * 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.fraction;
-
-import java.io.Serializable;
-import java.text.FieldPosition;
-import java.text.Format;
-import java.text.NumberFormat;
-import java.text.ParseException;
-import java.text.ParsePosition;
-import java.util.Locale;
-
-import org.apache.commons.math.ConvergenceException;
-
-/**
- * Formats a Fraction number in proper format or improper format.  The number
- * format for each of the whole number, numerator and, denominator can be
- * configured.
- *
- * @since 1.1
- * @version $Revision$ $Date$
- */
-public class FractionFormat extends Format implements Serializable {
-    
-    /** Serializable version identifier */
-    private static final long serialVersionUID = -6337346779577272306L;
-
-    /** The format used for the denominator. */
-    private NumberFormat denominatorFormat;
-
-    /** The format used for the numerator. */
-    private NumberFormat numeratorFormat;
-    
-    /**
-     * Create an improper formatting instance with the default number format
-     * for the numerator and denominator.  
-     */
-    public FractionFormat() {
-        this(getDefaultNumberFormat());
-    }
-
-    /**
-     * Create an improper formatting instance with a custom number format for
-     * both the numerator and denominator.
-     * @param format the custom format for both the numerator and denominator.
-     */
-    public FractionFormat(NumberFormat format) {
-        this(format, (NumberFormat)format.clone());
-    }
-
-    /**
-     * Create an improper formatting instance with a custom number format for
-     * the numerator and a custom number format for the denominator.
-     * @param numeratorFormat the custom format for the numerator.
-     * @param denominatorFormat the custom format for the denominator.
-     */
-    public FractionFormat(NumberFormat numeratorFormat,
-            NumberFormat denominatorFormat)
-    {
-        super();
-        this.numeratorFormat = numeratorFormat;
-        this.denominatorFormat = denominatorFormat;
-    }
-
-    /**
-     * This static method calls formatFraction() on a default instance of
-     * FractionFormat.
-     *
-     * @param f Fraction object to format
-     * @return A formatted fraction in proper form.
-     */
-    public static String formatFraction(Fraction f) {
-        return getImproperInstance().format(f);
-    }
-    
-    /**
-     * Get the set of locales for which complex formats are available.  This
-     * is the same set as the {@link NumberFormat} set. 
-     * @return available complex format locales.
-     */
-    public static Locale[] getAvailableLocales() {
-        return NumberFormat.getAvailableLocales();
-    }
-    
-    /**
-     * Returns the default complex format for the current locale.
-     * @return the default complex format.
-     */
-    public static FractionFormat getImproperInstance() {
-        return getImproperInstance(Locale.getDefault());
-    }
-    
-    /**
-     * Returns the default complex format for the given locale.
-     * @param locale the specific locale used by the format.
-     * @return the complex format specific to the given locale.
-     */
-    public static FractionFormat getImproperInstance(Locale locale) {
-        NumberFormat f = getDefaultNumberFormat(locale);
-        return new FractionFormat(f);
-    }
-    
-    /**
-     * Returns the default complex format for the current locale.
-     * @return the default complex format.
-     */
-    public static FractionFormat getProperInstance() {
-        return getProperInstance(Locale.getDefault());
-    }
-    
-    /**
-     * Returns the default complex format for the given locale.
-     * @param locale the specific locale used by the format.
-     * @return the complex format specific to the given locale.
-     */
-    public static FractionFormat getProperInstance(Locale locale) {
-        NumberFormat f = getDefaultNumberFormat(locale);
-        return new ProperFractionFormat(f);
-    }
-    
-    /**
-     * Create a default number format.  The default number format is based on
-     * {@link NumberFormat#getNumberInstance(java.util.Locale)} with the only
-     * customizing is the maximum number of fraction digits, which is set to 0.  
-     * @return the default number format.
-     */
-    protected static NumberFormat getDefaultNumberFormat() {
-        return getDefaultNumberFormat(Locale.getDefault());
-    }
-    
-    /**
-     * Create a default number format.  The default number format is based on
-     * {@link NumberFormat#getNumberInstance(java.util.Locale)} with the only
-     * customizing is the maximum number of fraction digits, which is set to 0.  
-     * @param locale the specific locale used by the format.
-     * @return the default number format specific to the given locale.
-     */
-    private static NumberFormat getDefaultNumberFormat(Locale locale) {
-        NumberFormat nf = NumberFormat.getNumberInstance(locale);
-        nf.setMaximumFractionDigits(0);
-        nf.setParseIntegerOnly(true);
-        return nf;
-    }
-    
-    /**
-     * Formats a {@link Fraction} object to produce a string.  The fraction is
-     * output in improper format.
-     *
-     * @param fraction the object to format.
-     * @param toAppendTo where the text is to be appended
-     * @param pos On input: an alignment field, if desired. On output: the
-     *            offsets of the alignment field
-     * @return the value passed in as toAppendTo.
-     */
-    public StringBuffer format(Fraction fraction, StringBuffer toAppendTo,
-            FieldPosition pos) {
-        
-        pos.setBeginIndex(0);
-        pos.setEndIndex(0);
-
-        getNumeratorFormat().format(fraction.getNumerator(), toAppendTo, pos);
-        toAppendTo.append(" / ");
-        getDenominatorFormat().format(fraction.getDenominator(), toAppendTo,
-            pos);
-        
-        return toAppendTo;
-    }
-    
-    /**
-     * Formats a object to produce a string.  <code>obj</code> must be either a 
-     * {@link Fraction} object or a {@link Number} object.  Any other type of
-     * object will result in an {@link IllegalArgumentException} being thrown.
-     *
-     * @param obj the object to format.
-     * @param toAppendTo where the text is to be appended
-     * @param pos On input: an alignment field, if desired. On output: the
-     *            offsets of the alignment field
-     * @return the value passed in as toAppendTo.
-     * @see java.text.Format#format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition)
-     * @throws IllegalArgumentException is <code>obj</code> is not a valid type.
-     */
-    public StringBuffer format(Object obj, StringBuffer toAppendTo,
-            FieldPosition pos)
-    {
-        StringBuffer ret = null;
-        
-        if (obj instanceof Fraction) {
-            ret = format( (Fraction)obj, toAppendTo, pos);
-        } else if (obj instanceof Number) {
-            try {
-                ret = format( new Fraction(((Number)obj).doubleValue()),
-                    toAppendTo, pos);
-            } catch (ConvergenceException ex) {
-                throw new IllegalArgumentException(
-                    "Cannot convert given object to a fraction.");
-            }
-        } else { 
-            throw new IllegalArgumentException(
-                "Cannot format given object as a fraction");
-        }
-        
-        return ret;
-    }
-
-    /**
-     * Access the denominator format.
-     * @return the denominator format.
-     */
-    public NumberFormat getDenominatorFormat() {
-        return denominatorFormat;
-    }
-    
-    /**
-     * Access the numerator format.
-     * @return the numerator format.
-     */
-    public NumberFormat getNumeratorFormat() {
-        return numeratorFormat;
-    }
-
-    /**
-     * Parses a string to produce a {@link Fraction} object.
-     * @param source the string to parse
-     * @return the parsed {@link Fraction} object.
-     * @exception ParseException if the beginning of the specified string
-     *            cannot be parsed.
-     */
-    public Fraction parse(String source) throws ParseException {
-        ParsePosition parsePosition = new ParsePosition(0);
-        Fraction result = parse(source, parsePosition);
-        if (parsePosition.getIndex() == 0) {
-            throw new ParseException("Unparseable fraction number: \"" +
-                source + "\"", parsePosition.getErrorIndex());
-        }
-        return result;
-    }
-    
-    /**
-     * Parses a string to produce a {@link Fraction} object.  This method
-     * expects the string to be formatted as an improper fraction.  
-     * @param source the string to parse
-     * @param pos input/ouput parsing parameter.
-     * @return the parsed {@link Fraction} object.
-     */
-    public Fraction parse(String source, ParsePosition pos) {
-        int initialIndex = pos.getIndex();
-
-        // parse whitespace
-        parseAndIgnoreWhitespace(source, pos);
-
-        // parse numerator
-        Number num = getNumeratorFormat().parse(source, pos);
-        if (num == null) {
-            // invalid integer number
-            // set index back to initial, error index should already be set
-            // character examined.
-            pos.setIndex(initialIndex);
-            return null;
-        }
-
-        // parse '/'
-        int startIndex = pos.getIndex();
-        char c = parseNextCharacter(source, pos);
-        switch (c) {
-        case 0 :
-            // no '/'
-            // return num as a fraction
-            return new Fraction(num.intValue(), 1);
-        case '/' :
-            // found '/', continue parsing denominator
-            break;
-        default :
-            // invalid '/'
-            // set index back to initial, error index should be the last
-            // character examined.
-            pos.setIndex(initialIndex);
-            pos.setErrorIndex(startIndex);
-            return null;
-        }
-
-        // parse whitespace
-        parseAndIgnoreWhitespace(source, pos);
-
-        // parse denominator
-        Number den = getDenominatorFormat().parse(source, pos);
-        if (den == null) {
-            // invalid integer number
-            // set index back to initial, error index should already be set
-            // character examined.
-            pos.setIndex(initialIndex);
-            return null;
-        }
-
-        return new Fraction(num.intValue(), den.intValue());
-    }
-
-    /**
-     * Parses a string to produce a object.
-     * @param source the string to parse
-     * @param pos input/ouput parsing parameter.
-     * @return the parsed object.
-     * @see java.text.Format#parseObject(java.lang.String, java.text.ParsePosition)
-     */
-    public Object parseObject(String source, ParsePosition pos) {
-        return parse(source, pos);
-    }
-    
-    /**
-     * Modify the denominator format.
-     * @param format the new denominator format value.
-     * @throws IllegalArgumentException if <code>format</code> is
-     *         <code>null</code>.
-     */
-    public void setDenominatorFormat(NumberFormat format) {
-        if (format == null) {
-            throw new IllegalArgumentException(
-                "denominator format can not be null.");
-        }
-        this.denominatorFormat = format;
-    }
-    
-    /**
-     * Modify the numerator format.
-     * @param format the new numerator format value.
-     * @throws IllegalArgumentException if <code>format</code> is
-     *         <code>null</code>.
-     */
-    public void setNumeratorFormat(NumberFormat format) {
-        if (format == null) {
-            throw new IllegalArgumentException(
-                "numerator format can not be null.");
-        }
-        this.numeratorFormat = format;
-    }
-     
-    /**
-     * Parses <code>source</code> until a non-whitespace character is found.
-     * @param source the string to parse
-     * @param pos input/ouput parsing parameter.  On output, <code>pos</code>
-     *        holds the index of the next non-whitespace character.
-     */
-    protected static void parseAndIgnoreWhitespace(
-        String source, ParsePosition pos)
-    {
-        parseNextCharacter(source, pos);
-        pos.setIndex(pos.getIndex() - 1);
-    }
-
-    /**
-     * Parses <code>source</code> until a non-whitespace character is found.
-     * @param source the string to parse
-     * @param pos input/ouput parsing parameter.
-     * @return the first non-whitespace character.
-     */
-    protected static char parseNextCharacter(String source, ParsePosition pos) {
-         int index = pos.getIndex();
-         int n = source.length();
-         char ret = 0;
-
-         if (index < n) {
-             char c;
-             do {
-                 c = source.charAt(index++);
-             } while (Character.isWhitespace(c) && index < n);
-             pos.setIndex(index);
-         
-             if (index < n) {
-                 ret = c;
-             }
-         }
-         
-         return ret;
-    }
-}
+/*
+ * 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.fraction;
+
+import java.io.Serializable;
+import java.text.FieldPosition;
+import java.text.Format;
+import java.text.NumberFormat;
+import java.text.ParseException;
+import java.text.ParsePosition;
+import java.util.Locale;
+
+import org.apache.commons.math.ConvergenceException;
+
+/**
+ * Formats a Fraction number in proper format or improper format.  The number
+ * format for each of the whole number, numerator and, denominator can be
+ * configured.
+ *
+ * @since 1.1
+ * @version $Revision$ $Date$
+ */
+public class FractionFormat extends Format implements Serializable {
+    
+    /** Serializable version identifier */
+    private static final long serialVersionUID = -6337346779577272306L;
+
+    /** The format used for the denominator. */
+    private NumberFormat denominatorFormat;
+
+    /** The format used for the numerator. */
+    private NumberFormat numeratorFormat;
+    
+    /**
+     * Create an improper formatting instance with the default number format
+     * for the numerator and denominator.  
+     */
+    public FractionFormat() {
+        this(getDefaultNumberFormat());
+    }
+
+    /**
+     * Create an improper formatting instance with a custom number format for
+     * both the numerator and denominator.
+     * @param format the custom format for both the numerator and denominator.
+     */
+    public FractionFormat(NumberFormat format) {
+        this(format, (NumberFormat)format.clone());
+    }
+
+    /**
+     * Create an improper formatting instance with a custom number format for
+     * the numerator and a custom number format for the denominator.
+     * @param numeratorFormat the custom format for the numerator.
+     * @param denominatorFormat the custom format for the denominator.
+     */
+    public FractionFormat(NumberFormat numeratorFormat,
+            NumberFormat denominatorFormat)
+    {
+        super();
+        this.numeratorFormat = numeratorFormat;
+        this.denominatorFormat = denominatorFormat;
+    }
+
+    /**
+     * This static method calls formatFraction() on a default instance of
+     * FractionFormat.
+     *
+     * @param f Fraction object to format
+     * @return A formatted fraction in proper form.
+     */
+    public static String formatFraction(Fraction f) {
+        return getImproperInstance().format(f);
+    }
+    
+    /**
+     * Get the set of locales for which complex formats are available.  This
+     * is the same set as the {@link NumberFormat} set. 
+     * @return available complex format locales.
+     */
+    public static Locale[] getAvailableLocales() {
+        return NumberFormat.getAvailableLocales();
+    }
+    
+    /**
+     * Returns the default complex format for the current locale.
+     * @return the default complex format.
+     */
+    public static FractionFormat getImproperInstance() {
+        return getImproperInstance(Locale.getDefault());
+    }
+    
+    /**
+     * Returns the default complex format for the given locale.
+     * @param locale the specific locale used by the format.
+     * @return the complex format specific to the given locale.
+     */
+    public static FractionFormat getImproperInstance(Locale locale) {
+        NumberFormat f = getDefaultNumberFormat(locale);
+        return new FractionFormat(f);
+    }
+    
+    /**
+     * Returns the default complex format for the current locale.
+     * @return the default complex format.
+     */
+    public static FractionFormat getProperInstance() {
+        return getProperInstance(Locale.getDefault());
+    }
+    
+    /**
+     * Returns the default complex format for the given locale.
+     * @param locale the specific locale used by the format.
+     * @return the complex format specific to the given locale.
+     */
+    public static FractionFormat getProperInstance(Locale locale) {
+        NumberFormat f = getDefaultNumberFormat(locale);
+        return new ProperFractionFormat(f);
+    }
+    
+    /**
+     * Create a default number format.  The default number format is based on
+     * {@link NumberFormat#getNumberInstance(java.util.Locale)} with the only
+     * customizing is the maximum number of fraction digits, which is set to 0.  
+     * @return the default number format.
+     */
+    protected static NumberFormat getDefaultNumberFormat() {
+        return getDefaultNumberFormat(Locale.getDefault());
+    }
+    
+    /**
+     * Create a default number format.  The default number format is based on
+     * {@link NumberFormat#getNumberInstance(java.util.Locale)} with the only
+     * customizing is the maximum number of fraction digits, which is set to 0.  
+     * @param locale the specific locale used by the format.
+     * @return the default number format specific to the given locale.
+     */
+    private static NumberFormat getDefaultNumberFormat(Locale locale) {
+        NumberFormat nf = NumberFormat.getNumberInstance(locale);
+        nf.setMaximumFractionDigits(0);
+        nf.setParseIntegerOnly(true);
+        return nf;
+    }
+    
+    /**
+     * Formats a {@link Fraction} object to produce a string.  The fraction is
+     * output in improper format.
+     *
+     * @param fraction the object to format.
+     * @param toAppendTo where the text is to be appended
+     * @param pos On input: an alignment field, if desired. On output: the
+     *            offsets of the alignment field
+     * @return the value passed in as toAppendTo.
+     */
+    public StringBuffer format(Fraction fraction, StringBuffer toAppendTo,
+            FieldPosition pos) {
+        
+        pos.setBeginIndex(0);
+        pos.setEndIndex(0);
+
+        getNumeratorFormat().format(fraction.getNumerator(), toAppendTo, pos);
+        toAppendTo.append(" / ");
+        getDenominatorFormat().format(fraction.getDenominator(), toAppendTo,
+            pos);
+        
+        return toAppendTo;
+    }
+    
+    /**
+     * Formats a object to produce a string.  <code>obj</code> must be either a 
+     * {@link Fraction} object or a {@link Number} object.  Any other type of
+     * object will result in an {@link IllegalArgumentException} being thrown.
+     *
+     * @param obj the object to format.
+     * @param toAppendTo where the text is to be appended
+     * @param pos On input: an alignment field, if desired. On output: the
+     *            offsets of the alignment field
+     * @return the value passed in as toAppendTo.
+     * @see java.text.Format#format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition)
+     * @throws IllegalArgumentException is <code>obj</code> is not a valid type.
+     */
+    public StringBuffer format(Object obj, StringBuffer toAppendTo,
+            FieldPosition pos)
+    {
+        StringBuffer ret = null;
+        
+        if (obj instanceof Fraction) {
+            ret = format( (Fraction)obj, toAppendTo, pos);
+        } else if (obj instanceof Number) {
+            try {
+                ret = format( new Fraction(((Number)obj).doubleValue()),
+                    toAppendTo, pos);
+            } catch (ConvergenceException ex) {
+                throw new IllegalArgumentException(
+                    "Cannot convert given object to a fraction.");
+            }
+        } else { 
+            throw new IllegalArgumentException(
+                "Cannot format given object as a fraction");
+        }
+        
+        return ret;
+    }
+
+    /**
+     * Access the denominator format.
+     * @return the denominator format.
+     */
+    public NumberFormat getDenominatorFormat() {
+        return denominatorFormat;
+    }
+    
+    /**
+     * Access the numerator format.
+     * @return the numerator format.
+     */
+    public NumberFormat getNumeratorFormat() {
+        return numeratorFormat;
+    }
+
+    /**
+     * Parses a string to produce a {@link Fraction} object.
+     * @param source the string to parse
+     * @return the parsed {@link Fraction} object.
+     * @exception ParseException if the beginning of the specified string
+     *            cannot be parsed.
+     */
+    public Fraction parse(String source) throws ParseException {
+        ParsePosition parsePosition = new ParsePosition(0);
+        Fraction result = parse(source, parsePosition);
+        if (parsePosition.getIndex() == 0) {
+            throw new ParseException("Unparseable fraction number: \"" +
+                source + "\"", parsePosition.getErrorIndex());
+        }
+        return result;
+    }
+    
+    /**
+     * Parses a string to produce a {@link Fraction} object.  This method
+     * expects the string to be formatted as an improper fraction.  
+     * @param source the string to parse
+     * @param pos input/ouput parsing parameter.
+     * @return the parsed {@link Fraction} object.
+     */
+    public Fraction parse(String source, ParsePosition pos) {
+        int initialIndex = pos.getIndex();
+
+        // parse whitespace
+        parseAndIgnoreWhitespace(source, pos);
+
+        // parse numerator
+        Number num = getNumeratorFormat().parse(source, pos);
+        if (num == null) {
+            // invalid integer number
+            // set index back to initial, error index should already be set
+            // character examined.
+            pos.setIndex(initialIndex);
+            return null;
+        }
+
+        // parse '/'
+        int startIndex = pos.getIndex();
+        char c = parseNextCharacter(source, pos);
+        switch (c) {
+        case 0 :
+            // no '/'
+            // return num as a fraction
+            return new Fraction(num.intValue(), 1);
+        case '/' :
+            // found '/', continue parsing denominator
+            break;
+        default :
+            // invalid '/'
+            // set index back to initial, error index should be the last
+            // character examined.
+            pos.setIndex(initialIndex);
+            pos.setErrorIndex(startIndex);
+            return null;
+        }
+
+        // parse whitespace
+        parseAndIgnoreWhitespace(source, pos);
+
+        // parse denominator
+        Number den = getDenominatorFormat().parse(source, pos);
+        if (den == null) {
+            // invalid integer number
+            // set index back to initial, error index should already be set
+            // character examined.
+            pos.setIndex(initialIndex);
+            return null;
+        }
+
+        return new Fraction(num.intValue(), den.intValue());
+    }
+
+    /**
+     * Parses a string to produce a object.
+     * @param source the string to parse
+     * @param pos input/ouput parsing parameter.
+     * @return the parsed object.
+     * @see java.text.Format#parseObject(java.lang.String, java.text.ParsePosition)
+     */
+    public Object parseObject(String source, ParsePosition pos) {
+        return parse(source, pos);
+    }
+    
+    /**
+     * Modify the denominator format.
+     * @param format the new denominator format value.
+     * @throws IllegalArgumentException if <code>format</code> is
+     *         <code>null</code>.
+     */
+    public void setDenominatorFormat(NumberFormat format) {
+        if (format == null) {
+            throw new IllegalArgumentException(
+                "denominator format can not be null.");
+        }
+        this.denominatorFormat = format;
+    }
+    
+    /**
+     * Modify the numerator format.
+     * @param format the new numerator format value.
+     * @throws IllegalArgumentException if <code>format</code> is
+     *         <code>null</code>.
+     */
+    public void setNumeratorFormat(NumberFormat format) {
+        if (format == null) {
+            throw new IllegalArgumentException(
+                "numerator format can not be null.");
+        }
+        this.numeratorFormat = format;
+    }
+     
+    /**
+     * Parses <code>source</code> until a non-whitespace character is found.
+     * @param source the string to parse
+     * @param pos input/ouput parsing parameter.  On output, <code>pos</code>
+     *        holds the index of the next non-whitespace character.
+     */
+    protected static void parseAndIgnoreWhitespace(
+        String source, ParsePosition pos)
+    {
+        parseNextCharacter(source, pos);
+        pos.setIndex(pos.getIndex() - 1);
+    }
+
+    /**
+     * Parses <code>source</code> until a non-whitespace character is found.
+     * @param source the string to parse
+     * @param pos input/ouput parsing parameter.
+     * @return the first non-whitespace character.
+     */
+    protected static char parseNextCharacter(String source, ParsePosition pos) {
+         int index = pos.getIndex();
+         int n = source.length();
+         char ret = 0;
+
+         if (index < n) {
+             char c;
+             do {
+                 c = source.charAt(index++);
+             } while (Character.isWhitespace(c) && index < n);
+             pos.setIndex(index);
+         
+             if (index < n) {
+                 ret = c;
+             }
+         }
+         
+         return ret;
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message