From 480db201fe334a0cd1083d11baeeebc5d22643b3 Mon Sep 17 00:00:00 2001 From: Jonathan Shook Date: Wed, 17 Jun 2020 15:29:31 -0500 Subject: [PATCH] improve StringSet argument compatibility --- .../shared/from_long/to_collection/StringSet.java | 11 +++++++++++ .../shared/from_long/to_collection/SetTest.java | 4 +++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/virtdata-lib-basics/src/main/java/io/nosqlbench/virtdata/library/basics/shared/from_long/to_collection/StringSet.java b/virtdata-lib-basics/src/main/java/io/nosqlbench/virtdata/library/basics/shared/from_long/to_collection/StringSet.java index be35bceab..8f88cf0a6 100644 --- a/virtdata-lib-basics/src/main/java/io/nosqlbench/virtdata/library/basics/shared/from_long/to_collection/StringSet.java +++ b/virtdata-lib-basics/src/main/java/io/nosqlbench/virtdata/library/basics/shared/from_long/to_collection/StringSet.java @@ -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} from a long @@ -35,6 +36,16 @@ public class StringSet implements LongFunction> { 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 apply(long value) { int size = sizeFunc.applyAsInt(value); diff --git a/virtdata-lib-basics/src/test/java/io/nosqlbench/virtdata/library/basics/shared/from_long/to_collection/SetTest.java b/virtdata-lib-basics/src/test/java/io/nosqlbench/virtdata/library/basics/shared/from_long/to_collection/SetTest.java index 1c01c54b2..ff0007597 100644 --- a/virtdata-lib-basics/src/test/java/io/nosqlbench/virtdata/library/basics/shared/from_long/to_collection/SetTest.java +++ b/virtdata-lib-basics/src/test/java/io/nosqlbench/virtdata/library/basics/shared/from_long/to_collection/SetTest.java @@ -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 s1 = set.apply(15L); assertThat(s1).containsOnly("15","16","17"); }