Make Hasher test classes package-private
This commit is contained in:
parent
d7343b729c
commit
9582007123
|
@ -22,10 +22,10 @@ import java.util.function.IntPredicate;
|
||||||
/**
|
/**
|
||||||
* A Testing Hasher that returns the array values % shape.getNumberOfBits().
|
* 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 class ArrayHasher implements Hasher {
|
||||||
final int[] values;
|
private final int[] values;
|
||||||
|
|
||||||
ArrayHasher(final int... values) {
|
ArrayHasher(final int... values) {
|
||||||
this.values = values;
|
this.values = values;
|
||||||
|
@ -39,6 +39,7 @@ public final class ArrayHasher implements Hasher {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IndexProducer uniqueIndices(Shape shape) {
|
public IndexProducer uniqueIndices(Shape shape) {
|
||||||
|
Objects.requireNonNull(shape, "shape");
|
||||||
return new Producer(shape);
|
return new Producer(shape);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,8 +52,10 @@ public final class ArrayHasher implements Hasher {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean forEachIndex(IntPredicate consumer) {
|
public boolean forEachIndex(IntPredicate consumer) {
|
||||||
|
Objects.requireNonNull(consumer, "consumer");
|
||||||
|
|
||||||
int pos = 0;
|
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();
|
int result = values[pos++] % shape.getNumberOfBits();
|
||||||
pos = pos % values.length;
|
pos = pos % values.length;
|
||||||
if (!consumer.test(result)) {
|
if (!consumer.test(result)) {
|
||||||
|
|
|
@ -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>.
|
* <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>
|
* <p>To be used for testing only.</p>
|
||||||
*
|
|
||||||
* @since 4.5
|
|
||||||
*/
|
*/
|
||||||
class IncrementingHasher implements Hasher {
|
final class IncrementingHasher implements Hasher {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The initial hash value.
|
* The initial hash value.
|
||||||
|
|
|
@ -22,23 +22,30 @@ import java.util.function.IntPredicate;
|
||||||
/**
|
/**
|
||||||
* A Hasher that returns no values.
|
* 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.
|
* 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() {
|
private static final IndexProducer PRODUCER = new IndexProducer() {
|
||||||
@Override
|
@Override
|
||||||
public boolean forEachIndex(IntPredicate consumer) {
|
public boolean forEachIndex(IntPredicate consumer) {
|
||||||
|
Objects.requireNonNull(consumer, "consumer");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int[] asIndexArray() {
|
||||||
|
return new int[0];
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private NullHasher() {
|
private NullHasher() {
|
||||||
|
// No instances
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -49,6 +56,7 @@ public final class NullHasher implements Hasher {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IndexProducer uniqueIndices(Shape shape) {
|
public IndexProducer uniqueIndices(Shape shape) {
|
||||||
|
Objects.requireNonNull(shape, "shape");
|
||||||
return PRODUCER;
|
return PRODUCER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue