Reorder distribution methods

Constructor

Parameter getters (in order used by the constructor)

Methods from the interface:

density/probability
probability(low, high)
logDensity/logProbability
cumulativeProbability
survivalProbability
inverseCumulativeProbability
getMean
getVariance
getSupportLowerBound
getSupportUpperBound
isSupportConnected
createSampler
diff --git a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/CauchyDistribution.java b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/CauchyDistribution.java
index 55cb0b2..1c7de30 100644
--- a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/CauchyDistribution.java
+++ b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/CauchyDistribution.java
@@ -47,27 +47,6 @@
         scale2 = scale * scale;
     }
 
-    /** {@inheritDoc} */
-    @Override
-    public double cumulativeProbability(double x) {
-        return cdf((x - median) / scale);
-    }
-
-    /** {@inheritDoc} */
-    @Override
-    public double survivalProbability(double x) {
-        return cdf(-(x - median) / scale);
-    }
-
-    /**
-     * Compute the CDF of the Cauchy distribution with location 0 and scale 1.
-     * @param x Point at which the CDF is evaluated
-     * @return CDF(x)
-     */
-    private static double cdf(double x) {
-        return 0.5 + (Math.atan(x) / Math.PI);
-    }
-
     /**
      * Access the median.
      *
@@ -93,6 +72,27 @@
         return scaleOverPi / (dev * dev + scale2);
     }
 
+    /** {@inheritDoc} */
+    @Override
+    public double cumulativeProbability(double x) {
+        return cdf((x - median) / scale);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public double survivalProbability(double x) {
+        return cdf(-(x - median) / scale);
+    }
+
+    /**
+     * Compute the CDF of the Cauchy distribution with location 0 and scale 1.
+     * @param x Point at which the CDF is evaluated
+     * @return CDF(x)
+     */
+    private static double cdf(double x) {
+        return 0.5 + (Math.atan(x) / Math.PI);
+    }
+
     /**
      * {@inheritDoc}
      *
diff --git a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/FDistribution.java b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/FDistribution.java
index 50baef9..1610478 100644
--- a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/FDistribution.java
+++ b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/FDistribution.java
@@ -75,6 +75,24 @@
     }
 
     /**
+     * Access the numerator degrees of freedom.
+     *
+     * @return the numerator degrees of freedom.
+     */
+    public double getNumeratorDegreesOfFreedom() {
+        return numeratorDegreesOfFreedom;
+    }
+
+    /**
+     * Access the denominator degrees of freedom.
+     *
+     * @return the denominator degrees of freedom.
+     */
+    public double getDenominatorDegreesOfFreedom() {
+        return denominatorDegreesOfFreedom;
+    }
+
+    /**
      * {@inheritDoc}
      */
     @Override
@@ -145,24 +163,6 @@
     }
 
     /**
-     * Access the numerator degrees of freedom.
-     *
-     * @return the numerator degrees of freedom.
-     */
-    public double getNumeratorDegreesOfFreedom() {
-        return numeratorDegreesOfFreedom;
-    }
-
-    /**
-     * Access the denominator degrees of freedom.
-     *
-     * @return the denominator degrees of freedom.
-     */
-    public double getDenominatorDegreesOfFreedom() {
-        return denominatorDegreesOfFreedom;
-    }
-
-    /**
      * {@inheritDoc}
      *
      * For denominator degrees of freedom parameter {@code b}, the mean is
diff --git a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/GeometricDistribution.java b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/GeometricDistribution.java
index 3c917c6..2e6dd3c 100644
--- a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/GeometricDistribution.java
+++ b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/GeometricDistribution.java
@@ -90,6 +90,22 @@
         return Math.exp(log1mProbabilityOfSuccess * (x + 1));
     }
 
+    /** {@inheritDoc} */
+    @Override
+    public int inverseCumulativeProbability(double p) {
+        if (p < 0 ||
+            p > 1) {
+            throw new DistributionException(DistributionException.INVALID_PROBABILITY, p);
+        }
+        if (p == 1) {
+            return Integer.MAX_VALUE;
+        }
+        if (p == 0) {
+            return 0;
+        }
+        return Math.max(0, (int) Math.ceil(Math.log1p(-p) / log1mProbabilityOfSuccess - 1));
+    }
+
     /**
      * {@inheritDoc}
      *
@@ -147,22 +163,4 @@
     public boolean isSupportConnected() {
         return true;
     }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public int inverseCumulativeProbability(double p) {
-        if (p < 0 ||
-            p > 1) {
-            throw new DistributionException(DistributionException.INVALID_PROBABILITY, p);
-        }
-        if (p == 1) {
-            return Integer.MAX_VALUE;
-        }
-        if (p == 0) {
-            return 0;
-        }
-        return Math.max(0, (int) Math.ceil(Math.log1p(-p) / log1mProbabilityOfSuccess - 1));
-    }
 }
diff --git a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/HypergeometricDistribution.java b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/HypergeometricDistribution.java
index ef43b0c..5a870ad 100644
--- a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/HypergeometricDistribution.java
+++ b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/HypergeometricDistribution.java
@@ -106,15 +106,6 @@
     }
 
     /**
-     * Access the number of successes.
-     *
-     * @return the number of successes.
-     */
-    public int getNumberOfSuccesses() {
-        return numberOfSuccesses;
-    }
-
-    /**
      * Access the population size.
      *
      * @return the population size.
@@ -124,6 +115,15 @@
     }
 
     /**
+     * Access the number of successes.
+     *
+     * @return the number of successes.
+     */
+    public int getNumberOfSuccesses() {
+        return numberOfSuccesses;
+    }
+
+    /**
      * Access the sample size.
      *
      * @return the sample size.
diff --git a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/LevyDistribution.java b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/LevyDistribution.java
index eafcbd5..e6eae34 100644
--- a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/LevyDistribution.java
+++ b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/LevyDistribution.java
@@ -45,6 +45,24 @@
         this.halfC = 0.5 * c;
     }
 
+    /**
+     * Gets the location parameter of the distribution.
+     *
+     * @return location parameter of the distribution
+     */
+    public double getLocation() {
+        return mu;
+    }
+
+    /**
+     * Gets the scale parameter of the distribution.
+     *
+     * @return scale parameter of the distribution
+     */
+    public double getScale() {
+        return c;
+    }
+
     /** {@inheritDoc}
     * <p>
     * From Wikipedia: The probability density function of the L&eacute;vy distribution
@@ -121,24 +139,6 @@
         return mu + halfC / (t * t);
     }
 
-    /**
-     * Gets the scale parameter of the distribution.
-     *
-     * @return scale parameter of the distribution
-     */
-    public double getScale() {
-        return c;
-    }
-
-    /**
-     * Gets the location parameter of the distribution.
-     *
-     * @return location parameter of the distribution
-     */
-    public double getLocation() {
-        return mu;
-    }
-
     /** {@inheritDoc} */
     @Override
     public double getMean() {
diff --git a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/LogNormalDistribution.java b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/LogNormalDistribution.java
index 211170b..e2b86af 100644
--- a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/LogNormalDistribution.java
+++ b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/LogNormalDistribution.java
@@ -112,6 +112,24 @@
         return Math.exp(-0.5 * x1 * x1) / (shape * SQRT2PI * x);
     }
 
+    /** {@inheritDoc} */
+    @Override
+    public double probability(double x0,
+                              double x1) {
+        if (x0 > x1) {
+            throw new DistributionException(DistributionException.INVALID_RANGE_LOW_GT_HIGH,
+                                            x0, x1);
+        }
+        if (x0 <= 0) {
+            return super.probability(x0, x1);
+        }
+        // Assumes x1 >= x0 && x0 > 0
+        final double denom = shape * SQRT2;
+        final double v0 = (Math.log(x0) - scale) / denom;
+        final double v1 = (Math.log(x1) - scale) / denom;
+        return 0.5 * ErfDifference.value(v0, v1);
+    }
+
     /** {@inheritDoc}
      *
      * See documentation of {@link #density(double)} for computation details.
@@ -167,24 +185,6 @@
         return 0.5 * Erfc.value(dev / (shape * SQRT2));
     }
 
-    /** {@inheritDoc} */
-    @Override
-    public double probability(double x0,
-                              double x1) {
-        if (x0 > x1) {
-            throw new DistributionException(DistributionException.INVALID_RANGE_LOW_GT_HIGH,
-                                            x0, x1);
-        }
-        if (x0 <= 0) {
-            return super.probability(x0, x1);
-        }
-        // Assumes x1 >= x0 && x0 > 0
-        final double denom = shape * SQRT2;
-        final double v0 = (Math.log(x0) - scale) / denom;
-        final double v1 = (Math.log(x1) - scale) / denom;
-        return 0.5 * ErfDifference.value(v0, v1);
-    }
-
     /**
      * {@inheritDoc}
      *
diff --git a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/NormalDistribution.java b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/NormalDistribution.java
index 81345e4..d2cee06 100644
--- a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/NormalDistribution.java
+++ b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/NormalDistribution.java
@@ -75,6 +75,19 @@
 
     /** {@inheritDoc} */
     @Override
+    public double probability(double x0,
+                              double x1) {
+        if (x0 > x1) {
+            throw new DistributionException(DistributionException.INVALID_RANGE_LOW_GT_HIGH,
+                                            x0, x1);
+        }
+        final double v0 = (x0 - mean) / sdSqrt2;
+        final double v1 = (x1 - mean) / sdSqrt2;
+        return 0.5 * ErfDifference.value(v0, v1);
+    }
+
+    /** {@inheritDoc} */
+    @Override
     public double logDensity(double x) {
         final double x0 = x - mean;
         final double x1 = x0 / standardDeviation;
@@ -119,19 +132,6 @@
 
     /** {@inheritDoc} */
     @Override
-    public double probability(double x0,
-                              double x1) {
-        if (x0 > x1) {
-            throw new DistributionException(DistributionException.INVALID_RANGE_LOW_GT_HIGH,
-                                            x0, x1);
-        }
-        final double v0 = (x0 - mean) / sdSqrt2;
-        final double v1 = (x1 - mean) / sdSqrt2;
-        return 0.5 * ErfDifference.value(v0, v1);
-    }
-
-    /** {@inheritDoc} */
-    @Override
     public double getMean() {
         return mean;
     }
diff --git a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/TriangularDistribution.java b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/TriangularDistribution.java
index 1a6a5f7..4500f01 100644
--- a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/TriangularDistribution.java
+++ b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/TriangularDistribution.java
@@ -142,6 +142,25 @@
         return 1;
     }
 
+    /** {@inheritDoc} */
+    @Override
+    public double inverseCumulativeProbability(double p) {
+        if (p < 0 ||
+            p > 1) {
+            throw new DistributionException(DistributionException.INVALID_PROBABILITY, p);
+        }
+        if (p == 0) {
+            return a;
+        }
+        if (p == 1) {
+            return b;
+        }
+        if (p < cdfMode) {
+            return a + Math.sqrt(p * divisor1);
+        }
+        return b - Math.sqrt((1 - p) * divisor2);
+    }
+
     /**
      * {@inheritDoc}
      *
@@ -201,23 +220,4 @@
     public boolean isSupportConnected() {
         return true;
     }
-
-    /** {@inheritDoc} */
-    @Override
-    public double inverseCumulativeProbability(double p) {
-        if (p < 0 ||
-            p > 1) {
-            throw new DistributionException(DistributionException.INVALID_PROBABILITY, p);
-        }
-        if (p == 0) {
-            return a;
-        }
-        if (p == 1) {
-            return b;
-        }
-        if (p < cdfMode) {
-            return a + Math.sqrt(p * divisor1);
-        }
-        return b - Math.sqrt((1 - p) * divisor2);
-    }
 }