You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2021/05/28 17:21:54 UTC

[commons-math] 04/05: Renamed "PivotingStrategyInterface" to "PivotingStrategy".

This is an automated email from the ASF dual-hosted git repository.

erans pushed a commit to branch modularized_master
in repository https://gitbox.apache.org/repos/asf/commons-math.git

commit 2977d26a0f4f67fcf377ecef4111ee30c3d9a75e
Author: Gilles Sadowski <gi...@gmail.com>
AuthorDate: Fri May 28 18:27:53 2021 +0200

    Renamed "PivotingStrategyInterface" to "PivotingStrategy".
    
    Removed a few spurious "throws" clauses (cf. MATH-1589).
---
 .../stat/descriptive/rank/CentralPivotingStrategy.java    | 11 +++--------
 .../math4/legacy/stat/descriptive/rank/KthSelector.java   | 11 ++++-------
 .../stat/descriptive/rank/MedianOf3PivotingStrategy.java  |  8 +++-----
 .../math4/legacy/stat/descriptive/rank/Percentile.java    |  4 ++--
 ...votingStrategyInterface.java => PivotingStrategy.java} | 15 +++++----------
 .../stat/descriptive/rank/RandomPivotingStrategy.java     |  8 +++-----
 .../legacy/stat/descriptive/rank/PercentileTest.java      |  2 +-
 7 files changed, 21 insertions(+), 38 deletions(-)

diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/CentralPivotingStrategy.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/CentralPivotingStrategy.java
index d579b8e..7632e32 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/CentralPivotingStrategy.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/CentralPivotingStrategy.java
@@ -19,16 +19,13 @@ package org.apache.commons.math4.legacy.stat.descriptive.rank;
 import java.io.Serializable;
 
 import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException;
-import org.apache.commons.math4.legacy.stat.descriptive.rank.PivotingStrategyInterface;
 import org.apache.commons.math4.legacy.util.MathArrays;
 
-
 /**
  * A mid point strategy based on the average of begin and end indices.
  * @since 3.4
  */
-public class CentralPivotingStrategy implements PivotingStrategyInterface, Serializable {
-
+public class CentralPivotingStrategy implements PivotingStrategy, Serializable {
     /** Serializable UID. */
     private static final long serialVersionUID = 20140713L;
 
@@ -40,10 +37,8 @@ public class CentralPivotingStrategy implements PivotingStrategyInterface, Seria
      * @throws MathIllegalArgumentException when indices exceeds range
      */
     @Override
-    public int pivotIndex(final double[] work, final int begin, final int end)
-        throws MathIllegalArgumentException {
-        MathArrays.verifyValues(work, begin, end-begin);
+    public int pivotIndex(final double[] work, final int begin, final int end) {
+        MathArrays.verifyValues(work, begin, end - begin);
         return begin + (end - begin)/2;
     }
-
 }
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/KthSelector.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/KthSelector.java
index 7c01406..3b764a7 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/KthSelector.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/KthSelector.java
@@ -22,7 +22,6 @@ import java.util.Arrays;
 import org.apache.commons.math4.legacy.exception.NullArgumentException;
 import org.apache.commons.math4.legacy.util.FastMath;
 
-
 /**
  * A Simple K<sup>th</sup> selector implementation to pick up the
  * K<sup>th</sup> ordered element from a work array containing the input
@@ -30,15 +29,14 @@ import org.apache.commons.math4.legacy.util.FastMath;
  * @since 3.4
  */
 public class KthSelector implements Serializable {
-
     /** Serializable UID. */
     private static final long serialVersionUID = 20140713L;
 
     /** Minimum selection size for insertion sort rather than selection. */
     private static final int MIN_SELECT_SIZE = 15;
 
-    /** A {@link PivotingStrategyInterface} used for pivoting  */
-    private final PivotingStrategyInterface pivotingStrategy;
+    /** A {@link PivotingStrategy} used for pivoting  */
+    private final PivotingStrategy pivotingStrategy;
 
     /**
      * Constructor with default {@link MedianOf3PivotingStrategy median of 3} pivoting strategy
@@ -56,8 +54,7 @@ public class KthSelector implements Serializable {
      * @see RandomPivotingStrategy
      * @see CentralPivotingStrategy
      */
-    public KthSelector(final PivotingStrategyInterface pivotingStrategy)
-        throws NullArgumentException {
+    public KthSelector(final PivotingStrategy pivotingStrategy) {
         NullArgumentException.check(pivotingStrategy);
         this.pivotingStrategy = pivotingStrategy;
     }
@@ -65,7 +62,7 @@ public class KthSelector implements Serializable {
     /** Get the pivoting strategy.
      * @return pivoting strategy
      */
-    public PivotingStrategyInterface getPivotingStrategy() {
+    public PivotingStrategy getPivotingStrategy() {
         return pivotingStrategy;
     }
 
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/MedianOf3PivotingStrategy.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/MedianOf3PivotingStrategy.java
index 9d6338e..7d2842f 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/MedianOf3PivotingStrategy.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/MedianOf3PivotingStrategy.java
@@ -26,8 +26,7 @@ import org.apache.commons.math4.legacy.util.MathArrays;
  * Classic median of 3 strategy given begin and end indices.
  * @since 3.4
  */
-public class MedianOf3PivotingStrategy implements PivotingStrategyInterface, Serializable {
-
+public class MedianOf3PivotingStrategy implements PivotingStrategy, Serializable {
     /** Serializable UID. */
     private static final long serialVersionUID = 20140713L;
 
@@ -38,9 +37,8 @@ public class MedianOf3PivotingStrategy implements PivotingStrategyInterface, Ser
      * @throws MathIllegalArgumentException when indices exceeds range
      */
     @Override
-    public int pivotIndex(final double[] work, final int begin, final int end)
-        throws MathIllegalArgumentException {
-        MathArrays.verifyValues(work, begin, end-begin);
+    public int pivotIndex(final double[] work, final int begin, final int end) {
+        MathArrays.verifyValues(work, begin, end - begin);
         final int inclusiveEnd = end - 1;
         final int middle = begin + (inclusiveEnd - begin) / 2;
         final double wBegin = work[begin];
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/Percentile.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/Percentile.java
index 4063dbe..8fe9c51 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/Percentile.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/Percentile.java
@@ -843,10 +843,10 @@ public class Percentile extends AbstractUnivariateStatistic implements Serializa
     }
 
     /**
-     * Get the {@link PivotingStrategyInterface} used in KthSelector for computation.
+     * Get the {@link PivotingStrategy} used in KthSelector for computation.
      * @return the pivoting strategy set
      */
-    public PivotingStrategyInterface getPivotingStrategy() {
+    public PivotingStrategy getPivotingStrategy() {
         return kthSelector.getPivotingStrategy();
     }
 
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/PivotingStrategyInterface.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/PivotingStrategy.java
similarity index 82%
rename from commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/PivotingStrategyInterface.java
rename to commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/PivotingStrategy.java
index c1cb83c..ef1e319 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/PivotingStrategyInterface.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/PivotingStrategy.java
@@ -16,18 +16,15 @@
  */
 package org.apache.commons.math4.legacy.stat.descriptive.rank;
 
-import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException;
-
-
 /**
  * A strategy to pick a pivoting index of an array for doing partitioning.
+ *
  * @see MedianOf3PivotingStrategy
  * @see RandomPivotingStrategy
  * @see CentralPivotingStrategy
- * @since 3.4
+ * @since 4.0
  */
-public interface PivotingStrategyInterface {
-
+public interface PivotingStrategy {
     /**
      * Find pivot index of the array so that partition and K<sup>th</sup>
      * element selection can be made
@@ -36,9 +33,7 @@ public interface PivotingStrategyInterface {
      * @param end index after the last element of the slice
      * @return the index of the pivot element chosen between the
      * first and the last element of the array slice
-     * @throws MathIllegalArgumentException when indices exceeds range
+     * @throws IllegalArgumentException when indices exceeds range
      */
-    int pivotIndex(double[] work, int begin, int end)
-        throws MathIllegalArgumentException;
-
+    int pivotIndex(double[] work, int begin, int end);
 }
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/RandomPivotingStrategy.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/RandomPivotingStrategy.java
index fa0def1..279738f 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/RandomPivotingStrategy.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/descriptive/rank/RandomPivotingStrategy.java
@@ -21,7 +21,6 @@ import java.io.IOException;
 import java.io.ObjectOutputStream;
 import java.io.ObjectInputStream;
 import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException;
-import org.apache.commons.math4.legacy.stat.descriptive.rank.PivotingStrategyInterface;
 import org.apache.commons.math4.legacy.util.MathArrays;
 import org.apache.commons.rng.RestorableUniformRandomProvider;
 import org.apache.commons.rng.simple.RandomSource;
@@ -32,7 +31,7 @@ import org.apache.commons.rng.core.RandomProviderDefaultState;
  *
  * @since 3.4
  */
-public class RandomPivotingStrategy implements PivotingStrategyInterface, Serializable {
+public class RandomPivotingStrategy implements PivotingStrategy, Serializable {
     /** Serializable UID. */
     private static final long serialVersionUID = 20160517L;
     /** Source of randomness. */
@@ -64,9 +63,8 @@ public class RandomPivotingStrategy implements PivotingStrategyInterface, Serial
      * @throws MathIllegalArgumentException when indices exceeds range
      */
     @Override
-    public int pivotIndex(final double[] work, final int begin, final int end)
-        throws MathIllegalArgumentException {
-        MathArrays.verifyValues(work, begin, end-begin);
+    public int pivotIndex(final double[] work, final int begin, final int end) {
+        MathArrays.verifyValues(work, begin, end - begin);
         return begin + random.nextInt(end - begin - 1);
     }
 
diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/stat/descriptive/rank/PercentileTest.java b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/stat/descriptive/rank/PercentileTest.java
index a430409..846c03a 100644
--- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/stat/descriptive/rank/PercentileTest.java
+++ b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/stat/descriptive/rank/PercentileTest.java
@@ -688,7 +688,7 @@ public class PercentileTest extends UnivariateStatisticAbstractTest{
 
         Assert.assertEquals("Legacy Apache Commons Math",Percentile.EstimationType.LEGACY.getName());
 
-        for (final PivotingStrategyInterface strategy : new PivotingStrategyInterface[] {
+        for (final PivotingStrategy strategy : new PivotingStrategy[] {
             new MedianOf3PivotingStrategy(),
             new CentralPivotingStrategy(),
             new RandomPivotingStrategy(RandomSource.WELL_1024_A, 0xf097c734e4740053l)