You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2022/11/04 16:23:01 UTC

[commons-collections] branch master updated: Make Hasher test classes package-private

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

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-collections.git


The following commit(s) were added to refs/heads/master by this push:
     new 958200712 Make Hasher test classes package-private
958200712 is described below

commit 9582007123799dab2f1ddb38aa8654c26867da3f
Author: aherbert <a....@sussex.ac.uk>
AuthorDate: Fri Nov 4 15:40:26 2022 +0000

    Make Hasher test classes package-private
---
 .../commons/collections4/bloomfilter/ArrayHasher.java      | 11 +++++++----
 .../collections4/bloomfilter/IncrementingHasher.java       |  4 +---
 .../commons/collections4/bloomfilter/NullHasher.java       | 14 +++++++++++---
 3 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/ArrayHasher.java b/src/test/java/org/apache/commons/collections4/bloomfilter/ArrayHasher.java
index babd13d2c..32a421eb0 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/ArrayHasher.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/ArrayHasher.java
@@ -22,10 +22,10 @@ import java.util.function.IntPredicate;
 /**
  * A Testing Hasher that returns the array values % shape.getNumberOfBits().
  *
- * @since 4.5
+ * <p>To be used for testing only.</p>
  */
-public final class ArrayHasher implements Hasher {
-    final int[] values;
+final class ArrayHasher implements Hasher {
+    private final int[] values;
 
     ArrayHasher(final int... values) {
         this.values = values;
@@ -39,6 +39,7 @@ public final class ArrayHasher implements Hasher {
 
     @Override
     public IndexProducer uniqueIndices(Shape shape) {
+        Objects.requireNonNull(shape, "shape");
         return new Producer(shape);
     }
 
@@ -51,8 +52,10 @@ public final class ArrayHasher implements Hasher {
 
         @Override
         public boolean forEachIndex(IntPredicate consumer) {
+            Objects.requireNonNull(consumer, "consumer");
+
             int pos = 0;
-            for (int i=0; i<shape.getNumberOfHashFunctions(); i++) {
+            for (int i = 0; i < shape.getNumberOfHashFunctions(); i++) {
                 int result = values[pos++] % shape.getNumberOfBits();
                 pos = pos % values.length;
                 if (!consumer.test(result)) {
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/IncrementingHasher.java b/src/test/java/org/apache/commons/collections4/bloomfilter/IncrementingHasher.java
index bc4003f18..3e08c5e28 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/IncrementingHasher.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/IncrementingHasher.java
@@ -24,10 +24,8 @@ import java.util.function.IntPredicate;
  * <a href="https://www.eecs.harvard.edu/~michaelm/postscripts/tr-02-05.pdf">Krisch and Mitzenmacher</a>.
  *
  * <p>To be used for testing only.</p>
- *
- * @since 4.5
  */
-class IncrementingHasher implements Hasher {
+final class IncrementingHasher implements Hasher {
 
     /**
      * The initial hash value.
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/NullHasher.java b/src/test/java/org/apache/commons/collections4/bloomfilter/NullHasher.java
index 537c60d28..ba49f04e9 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/NullHasher.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/NullHasher.java
@@ -22,23 +22,30 @@ import java.util.function.IntPredicate;
 /**
  * A Hasher that returns no values.
  *
- * @since 4.5
+ * <p>To be used for testing only.</p>
  */
-public final class NullHasher implements Hasher {
+final class NullHasher implements Hasher {
 
     /**
      * The instance of the Null Hasher.
      */
-    public static final NullHasher INSTANCE = new NullHasher();
+    static final NullHasher INSTANCE = new NullHasher();
 
     private static final IndexProducer PRODUCER = new IndexProducer() {
         @Override
         public boolean forEachIndex(IntPredicate consumer) {
+            Objects.requireNonNull(consumer, "consumer");
             return true;
         }
+
+        @Override
+        public int[] asIndexArray() {
+            return new int[0];
+        }
     };
 
     private NullHasher() {
+        // No instances
     }
 
     @Override
@@ -49,6 +56,7 @@ public final class NullHasher implements Hasher {
 
     @Override
     public IndexProducer uniqueIndices(Shape shape) {
+        Objects.requireNonNull(shape, "shape");
         return PRODUCER;
     }
 }