improve StringSet argument compatibility

This commit is contained in:
Jonathan Shook 2020-06-17 15:29:31 -05:00
parent a123487935
commit 480db201fe
2 changed files with 14 additions and 1 deletions

View File

@ -8,6 +8,7 @@ import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
import java.util.HashSet;
import java.util.function.LongFunction;
import java.util.function.LongToIntFunction;
import java.util.function.LongUnaryOperator;
/**
* Create a {@code Set<String>} from a long
@ -35,6 +36,16 @@ public class StringSet implements LongFunction<java.util.Set<String>> {
this.valueFunc = valueFunc;
}
public StringSet(LongToIntFunction sizeFunc, LongUnaryOperator valueFunc) {
this.sizeFunc = sizeFunc;
this.valueFunc = valueFunc::applyAsLong;
}
public StringSet(LongToIntFunction sizeFunc, LongToIntFunction valueFunc) {
this.sizeFunc = sizeFunc;
this.valueFunc = valueFunc::applyAsInt;
}
@Override
public java.util.Set<String> apply(long value) {
int size = sizeFunc.applyAsInt(value);

View File

@ -2,6 +2,8 @@ package io.nosqlbench.virtdata.library.basics.shared.from_long.to_collection;
import org.junit.Test;
import java.util.function.LongToIntFunction;
import static org.assertj.core.api.Assertions.assertThat;
public class SetTest {
@ -15,7 +17,7 @@ public class SetTest {
@Test
public void testStringSet() {
StringSet set = new StringSet(s -> 3, e -> e);
StringSet set = new StringSet(s -> 3, (LongToIntFunction) (e -> (int)e));
java.util.Set<String> s1 = set.apply(15L);
assertThat(s1).containsOnly("15","16","17");
}