mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
listfuncs started, needs docs, examples, unit tests
This commit is contained in:
parent
477af8c7bc
commit
6b89da98bb
@ -1,9 +1,6 @@
|
||||
package io.nosqlbench.virtdata.library.basics.shared.from_long.to_collection;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
||||
import io.nosqlbench.virtdata.api.annotations.Example;
|
||||
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
|
||||
import io.nosqlbench.virtdata.api.annotations.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.LongFunction;
|
||||
@ -21,6 +18,7 @@ import java.util.function.LongToIntFunction;
|
||||
*/
|
||||
@Categories({Category.collections})
|
||||
@ThreadSafeMapper
|
||||
@DeprecatedFunction("Use ListSizedStepped")
|
||||
public class List implements LongFunction<java.util.List<Object>> {
|
||||
|
||||
private final LongToIntFunction sizeFunc;
|
||||
|
@ -0,0 +1,75 @@
|
||||
package io.nosqlbench.virtdata.library.basics.shared.from_long.to_collection;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
||||
import io.nosqlbench.virtdata.api.annotations.Example;
|
||||
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.LongFunction;
|
||||
import java.util.function.LongUnaryOperator;
|
||||
|
||||
/**
|
||||
* Create a {@code List} from a long input
|
||||
* based on two functions, the first to
|
||||
* determine the list size, and the second to populate the list with
|
||||
* object values. The input fed to the second function is incremented
|
||||
* between elements.
|
||||
*
|
||||
* To directly create Lists of Strings from the String version of the same
|
||||
* mapping functions, simply use {@link StringList} instead.
|
||||
*/
|
||||
@Categories({Category.collections})
|
||||
@ThreadSafeMapper
|
||||
public class ListFunctions implements LongFunction<java.util.List<Object>> {
|
||||
|
||||
private final java.util.List<LongFunction<? extends Object>> valueFuncs;
|
||||
private final int size;
|
||||
|
||||
@Example({
|
||||
"ListFunctions(NumberNameToString(),NumberNameToString())",
|
||||
"Create a list of ['one','one']"
|
||||
})
|
||||
public ListFunctions(LongFunction<? extends Object>... funcs) {
|
||||
this.valueFuncs = Arrays.asList(funcs);
|
||||
this.size = valueFuncs.size();
|
||||
}
|
||||
|
||||
@Example({
|
||||
"ListFunctions(NumberNameToString(),NumberNameToString())",
|
||||
"Create a list of ['one','one']"
|
||||
})
|
||||
public ListFunctions(LongUnaryOperator... funcs) {
|
||||
List<LongFunction<?>> building = new ArrayList<>(funcs.length);
|
||||
for (LongUnaryOperator func : funcs) {
|
||||
building.add(func::applyAsLong);
|
||||
}
|
||||
this.valueFuncs = building;
|
||||
this.size = building.size();
|
||||
}
|
||||
|
||||
@Example({
|
||||
"ListFunctions(NumberNameToString(),NumberNameToString())",
|
||||
"Create a list of ['one','one']"
|
||||
})
|
||||
public ListFunctions(Function<Long,Object>... funcs) {
|
||||
List<LongFunction<?>> building = new ArrayList<>(funcs.length);
|
||||
for (Function<Long,Object> func : funcs) {
|
||||
building.add(func::apply);
|
||||
}
|
||||
this.valueFuncs = building;
|
||||
this.size = building.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.List<Object> apply(long value) {
|
||||
java.util.List<Object> list = new ArrayList<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
list.add(valueFuncs.get(i).apply(value));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
package io.nosqlbench.virtdata.library.basics.shared.from_long.to_collection;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
||||
import io.nosqlbench.virtdata.api.annotations.Example;
|
||||
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
|
||||
import io.nosqlbench.virtdata.library.basics.shared.from_long.to_long.Hash;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.LongFunction;
|
||||
import java.util.function.LongToIntFunction;
|
||||
import java.util.function.LongUnaryOperator;
|
||||
|
||||
/**
|
||||
* Create a {@code List} from a long input
|
||||
* based on two functions, the first to
|
||||
* determine the list size, and the second to populate the list with
|
||||
* object values. The input fed to the second function is incremented
|
||||
* between elements.
|
||||
*
|
||||
* To directly create Lists of Strings from the String version of the same
|
||||
* mapping functions, simply use {@link StringList} instead.
|
||||
*/
|
||||
@Categories({Category.collections})
|
||||
@ThreadSafeMapper
|
||||
public class ListHashed implements LongFunction<List<Object>> {
|
||||
|
||||
private final List<LongFunction<? extends Object>> valueFuncs;
|
||||
private final int size;
|
||||
private final LongToIntFunction sizeFunc;
|
||||
private final Hash hasher = new Hash();
|
||||
|
||||
@Example({
|
||||
"ListFunctions(NumberNameToString(),NumberNameToString())",
|
||||
"Create a list of ['one','one']"
|
||||
})
|
||||
public ListHashed(LongToIntFunction sizeFunc, LongFunction<? extends Object>... funcs) {
|
||||
this.sizeFunc = sizeFunc;
|
||||
this.valueFuncs = Arrays.asList(funcs);
|
||||
this.size = valueFuncs.size();
|
||||
}
|
||||
|
||||
@Example({
|
||||
"ListFunctions(NumberNameToString(),NumberNameToString())",
|
||||
"Create a list of ['one','one']"
|
||||
})
|
||||
public ListHashed(LongToIntFunction sizeFunc, LongUnaryOperator... funcs) {
|
||||
List<LongFunction<?>> building = new ArrayList<>(funcs.length);
|
||||
for (LongUnaryOperator func : funcs) {
|
||||
building.add(func::applyAsLong);
|
||||
}
|
||||
this.sizeFunc = sizeFunc;
|
||||
this.valueFuncs = building;
|
||||
this.size = building.size();
|
||||
}
|
||||
|
||||
@Example({
|
||||
"ListFunctions(NumberNameToString(),NumberNameToString())",
|
||||
"Create a list of ['one','one']"
|
||||
})
|
||||
public ListHashed(LongToIntFunction sizeFunc, Function<Long,Object>... funcs) {
|
||||
List<LongFunction<?>> building = new ArrayList<>(funcs.length);
|
||||
for (Function<Long,Object> func : funcs) {
|
||||
building.add(func::apply);
|
||||
}
|
||||
this.sizeFunc = sizeFunc;
|
||||
this.valueFuncs = building;
|
||||
this.size = building.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Object> apply(long value) {
|
||||
long hash = value;
|
||||
int size = sizeFunc.applyAsInt(value);
|
||||
List<Object> list = new ArrayList<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
int selector = Math.min(i, valueFuncs.size() - 1);
|
||||
LongFunction<?> func = valueFuncs.get(selector);
|
||||
hash = hasher.applyAsLong(value);
|
||||
list.add(func.apply(hash));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
package io.nosqlbench.virtdata.library.basics.shared.from_long.to_collection;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
||||
import io.nosqlbench.virtdata.api.annotations.Example;
|
||||
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.LongFunction;
|
||||
import java.util.function.LongToIntFunction;
|
||||
import java.util.function.LongUnaryOperator;
|
||||
|
||||
/**
|
||||
* Create a {@code List} from a long input
|
||||
* based on two functions, the first to
|
||||
* determine the list size, and the second to populate the list with
|
||||
* object values. The input fed to the second function is incremented
|
||||
* between elements.
|
||||
*
|
||||
* To directly create Lists of Strings from the String version of the same
|
||||
* mapping functions, simply use {@link StringList} instead.
|
||||
*/
|
||||
@Categories({Category.collections})
|
||||
@ThreadSafeMapper
|
||||
public class ListSized implements LongFunction<List<Object>> {
|
||||
|
||||
private final List<LongFunction<? extends Object>> valueFuncs;
|
||||
private final int size;
|
||||
private final LongToIntFunction sizeFunc;
|
||||
|
||||
@Example({
|
||||
"ListFunctions(NumberNameToString(),NumberNameToString())",
|
||||
"Create a list of ['one','one']"
|
||||
})
|
||||
public ListSized(LongToIntFunction sizeFunc, LongFunction<? extends Object>... funcs) {
|
||||
this.sizeFunc = sizeFunc;
|
||||
this.valueFuncs = Arrays.asList(funcs);
|
||||
this.size = valueFuncs.size();
|
||||
}
|
||||
|
||||
@Example({
|
||||
"ListFunctions(NumberNameToString(),NumberNameToString())",
|
||||
"Create a list of ['one','one']"
|
||||
})
|
||||
public ListSized(LongToIntFunction sizeFunc, LongUnaryOperator... funcs) {
|
||||
List<LongFunction<?>> building = new ArrayList<>(funcs.length);
|
||||
for (LongUnaryOperator func : funcs) {
|
||||
building.add(func::applyAsLong);
|
||||
}
|
||||
this.sizeFunc = sizeFunc;
|
||||
this.valueFuncs = building;
|
||||
this.size = building.size();
|
||||
}
|
||||
|
||||
@Example({
|
||||
"ListFunctions(NumberNameToString(),NumberNameToString())",
|
||||
"Create a list of ['one','one']"
|
||||
})
|
||||
public ListSized(LongToIntFunction sizeFunc, Function<Long,Object>... funcs) {
|
||||
List<LongFunction<?>> building = new ArrayList<>(funcs.length);
|
||||
for (Function<Long,Object> func : funcs) {
|
||||
building.add(func::apply);
|
||||
}
|
||||
this.sizeFunc = sizeFunc;
|
||||
this.valueFuncs = building;
|
||||
this.size = building.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Object> apply(long value) {
|
||||
int size = sizeFunc.applyAsInt(value);
|
||||
List<Object> list = new ArrayList<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
int selector = Math.min(i, valueFuncs.size() - 1);
|
||||
LongFunction<?> func = valueFuncs.get(selector);
|
||||
list.add(func.apply(value));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
package io.nosqlbench.virtdata.library.basics.shared.from_long.to_collection;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
||||
import io.nosqlbench.virtdata.api.annotations.Example;
|
||||
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
|
||||
import io.nosqlbench.virtdata.library.basics.shared.from_long.to_long.Hash;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.LongFunction;
|
||||
import java.util.function.LongToIntFunction;
|
||||
import java.util.function.LongUnaryOperator;
|
||||
|
||||
/**
|
||||
* Create a {@code List} from a long input
|
||||
* based on two functions, the first to
|
||||
* determine the list size, and the second to populate the list with
|
||||
* object values. The input fed to the second function is incremented
|
||||
* between elements.
|
||||
*
|
||||
* To directly create Lists of Strings from the String version of the same
|
||||
* mapping functions, simply use {@link StringList} instead.
|
||||
*/
|
||||
@Categories({Category.collections})
|
||||
@ThreadSafeMapper
|
||||
public class ListSizedHashed implements LongFunction<List<Object>> {
|
||||
|
||||
private final List<LongFunction<? extends Object>> valueFuncs;
|
||||
private final int size;
|
||||
private final Hash hasher = new Hash();
|
||||
private final LongToIntFunction sizeFunc;
|
||||
|
||||
@Example({
|
||||
"ListFunctions(NumberNameToString(),NumberNameToString())",
|
||||
"Create a list of ['one','one']"
|
||||
})
|
||||
public ListSizedHashed(LongToIntFunction sizeFunc, LongFunction<? extends Object>... funcs) {
|
||||
this.sizeFunc = sizeFunc;
|
||||
this.valueFuncs = Arrays.asList(funcs);
|
||||
this.size = valueFuncs.size();
|
||||
}
|
||||
|
||||
@Example({
|
||||
"ListFunctions(NumberNameToString(),NumberNameToString())",
|
||||
"Create a list of ['one','one']"
|
||||
})
|
||||
public ListSizedHashed(LongToIntFunction sizeFunc, LongUnaryOperator... funcs) {
|
||||
List<LongFunction<?>> building = new ArrayList<>(funcs.length);
|
||||
for (LongUnaryOperator func : funcs) {
|
||||
building.add(func::applyAsLong);
|
||||
}
|
||||
this.sizeFunc = sizeFunc;
|
||||
this.valueFuncs = building;
|
||||
this.size = building.size();
|
||||
}
|
||||
|
||||
@Example({
|
||||
"ListFunctions(NumberNameToString(),NumberNameToString())",
|
||||
"Create a list of ['one','one']"
|
||||
})
|
||||
public ListSizedHashed(LongToIntFunction sizeFunc, Function<Long,Object>... funcs) {
|
||||
List<LongFunction<?>> building = new ArrayList<>(funcs.length);
|
||||
for (Function<Long,Object> func : funcs) {
|
||||
building.add(func::apply);
|
||||
}
|
||||
this.sizeFunc = sizeFunc;
|
||||
this.valueFuncs = building;
|
||||
this.size = building.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Object> apply(long value) {
|
||||
int size = sizeFunc.applyAsInt(value);
|
||||
|
||||
long hashed = value;
|
||||
List<Object> list = new ArrayList<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
hashed = hasher.applyAsLong(hashed);
|
||||
// Get the pair-wise function to the list index (0 based)
|
||||
// if the list is longer than the functions, use the last function
|
||||
|
||||
int selector = Math.min(i, valueFuncs.size() - 1);
|
||||
LongFunction<?> func = valueFuncs.get(selector);
|
||||
list.add(func.apply(hashed));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
package io.nosqlbench.virtdata.library.basics.shared.from_long.to_collection;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
||||
import io.nosqlbench.virtdata.api.annotations.Example;
|
||||
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
|
||||
import io.nosqlbench.virtdata.library.basics.shared.from_long.to_long.Hash;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.LongFunction;
|
||||
import java.util.function.LongToIntFunction;
|
||||
import java.util.function.LongUnaryOperator;
|
||||
|
||||
/**
|
||||
* Create a {@code List} from a long input
|
||||
* based on two functions, the first to
|
||||
* determine the list size, and the second to populate the list with
|
||||
* object values. The input fed to the second function is incremented
|
||||
* between elements.
|
||||
*
|
||||
* To directly create Lists of Strings from the String version of the same
|
||||
* mapping functions, simply use {@link StringList} instead.
|
||||
*/
|
||||
@Categories({Category.collections})
|
||||
@ThreadSafeMapper
|
||||
public class ListSizedStepped implements LongFunction<List<Object>> {
|
||||
|
||||
private final List<LongFunction<? extends Object>> valueFuncs;
|
||||
private final int size;
|
||||
private final LongToIntFunction sizeFunc;
|
||||
|
||||
@Example({
|
||||
"ListFunctions(NumberNameToString(),NumberNameToString())",
|
||||
"Create a list of ['one','one']"
|
||||
})
|
||||
public ListSizedStepped(LongToIntFunction sizeFunc, LongFunction<? extends Object>... funcs) {
|
||||
this.sizeFunc = sizeFunc;
|
||||
this.valueFuncs = Arrays.asList(funcs);
|
||||
this.size = valueFuncs.size();
|
||||
}
|
||||
|
||||
@Example({
|
||||
"ListFunctions(NumberNameToString(),NumberNameToString())",
|
||||
"Create a list of ['one','one']"
|
||||
})
|
||||
public ListSizedStepped(LongToIntFunction sizeFunc, LongUnaryOperator... funcs) {
|
||||
List<LongFunction<?>> building = new ArrayList<>(funcs.length);
|
||||
for (LongUnaryOperator func : funcs) {
|
||||
building.add(func::applyAsLong);
|
||||
}
|
||||
this.sizeFunc = sizeFunc;
|
||||
this.valueFuncs = building;
|
||||
this.size = building.size();
|
||||
}
|
||||
|
||||
@Example({
|
||||
"ListFunctions(NumberNameToString(),NumberNameToString())",
|
||||
"Create a list of ['one','one']"
|
||||
})
|
||||
public ListSizedStepped(LongToIntFunction sizeFunc, Function<Long,Object>... funcs) {
|
||||
List<LongFunction<?>> building = new ArrayList<>(funcs.length);
|
||||
for (Function<Long,Object> func : funcs) {
|
||||
building.add(func::apply);
|
||||
}
|
||||
this.sizeFunc = sizeFunc;
|
||||
this.valueFuncs = building;
|
||||
this.size = building.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Object> apply(long value) {
|
||||
int size = sizeFunc.applyAsInt(value);
|
||||
List<Object> list = new ArrayList<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
int selector = Math.min(i, valueFuncs.size() - 1);
|
||||
LongFunction<?> func = valueFuncs.get(selector);
|
||||
list.add(func.apply(i+value));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
package io.nosqlbench.virtdata.library.basics.shared.from_long.to_collection;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
||||
import io.nosqlbench.virtdata.api.annotations.Example;
|
||||
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.LongFunction;
|
||||
import java.util.function.LongToIntFunction;
|
||||
import java.util.function.LongUnaryOperator;
|
||||
|
||||
/**
|
||||
* Create a {@code List} from a long input
|
||||
* based on two functions, the first to
|
||||
* determine the list size, and the second to populate the list with
|
||||
* object values. The input fed to the second function is incremented
|
||||
* between elements.
|
||||
*
|
||||
* To directly create Lists of Strings from the String version of the same
|
||||
* mapping functions, simply use {@link StringList} instead.
|
||||
*/
|
||||
@Categories({Category.collections})
|
||||
@ThreadSafeMapper
|
||||
public class ListStepped implements LongFunction<List<Object>> {
|
||||
|
||||
private final List<LongFunction<? extends Object>> valueFuncs;
|
||||
private final int size;
|
||||
private final LongToIntFunction sizeFunc;
|
||||
|
||||
@Example({
|
||||
"ListFunctions(NumberNameToString(),NumberNameToString())",
|
||||
"Create a list of ['one','one']"
|
||||
})
|
||||
public ListStepped(LongToIntFunction sizeFunc, LongFunction<? extends Object>... funcs) {
|
||||
this.sizeFunc = sizeFunc;
|
||||
this.valueFuncs = Arrays.asList(funcs);
|
||||
this.size = valueFuncs.size();
|
||||
}
|
||||
|
||||
@Example({
|
||||
"ListFunctions(NumberNameToString(),NumberNameToString())",
|
||||
"Create a list of ['one','one']"
|
||||
})
|
||||
public ListStepped(LongToIntFunction sizeFunc, LongUnaryOperator... funcs) {
|
||||
List<LongFunction<?>> building = new ArrayList<>(funcs.length);
|
||||
for (LongUnaryOperator func : funcs) {
|
||||
building.add(func::applyAsLong);
|
||||
}
|
||||
this.sizeFunc = sizeFunc;
|
||||
this.valueFuncs = building;
|
||||
this.size = building.size();
|
||||
}
|
||||
|
||||
@Example({
|
||||
"ListFunctions(NumberNameToString(),NumberNameToString())",
|
||||
"Create a list of ['one','one']"
|
||||
})
|
||||
public ListStepped(LongToIntFunction sizeFunc, Function<Long,Object>... funcs) {
|
||||
List<LongFunction<?>> building = new ArrayList<>(funcs.length);
|
||||
for (Function<Long,Object> func : funcs) {
|
||||
building.add(func::apply);
|
||||
}
|
||||
this.sizeFunc = sizeFunc;
|
||||
this.valueFuncs = building;
|
||||
this.size = building.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Object> apply(long value) {
|
||||
int size = sizeFunc.applyAsInt(value);
|
||||
List<Object> list = new ArrayList<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
int selector = Math.min(i, valueFuncs.size() - 1);
|
||||
LongFunction<?> func = valueFuncs.get(selector);
|
||||
list.add(func.apply(value+i));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package io.nosqlbench.virtdata.library.basics.shared.from_long.to_collection;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.LongFunction;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class ListFunctionsTest {
|
||||
|
||||
@Test
|
||||
public void ListFunctions() {
|
||||
LongFunction<String> f1 = (long l) -> "long[" + l + "]";
|
||||
ListFunctions func = new ListFunctions(f1);
|
||||
List<Object> value = func.apply(234L);
|
||||
assertThat(value).hasSize(1);
|
||||
assertThat(value.get(0)).isOfAnyClassIn(String.class);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package io.nosqlbench.virtdata.library.basics.shared.from_long.to_collection;
|
||||
|
||||
|
||||
import io.nosqlbench.virtdata.library.basics.shared.from_long.to_string.NumberNameToString;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.LongFunction;
|
||||
import java.util.function.LongToIntFunction;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class ListSizedHashedTest {
|
||||
|
||||
@Test
|
||||
public void testTwoPartExample() {
|
||||
LongToIntFunction sizer = (l) -> (int) l;
|
||||
LongFunction<String> namer = (l) -> "L{" + l + "}";
|
||||
|
||||
ListSizedHashed f1 = new ListSizedHashed(sizer, namer);
|
||||
List<Object> for37 = f1.apply(37L);
|
||||
assertThat(for37).hasSize(37);
|
||||
assertThat(for37.get(0)).isNotEqualTo(for37.get(36));
|
||||
for (Object o : for37) {
|
||||
System.out.println(o);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFunctionSelection() {
|
||||
LongToIntFunction sizer = (l) -> (int) l;
|
||||
LongFunction<String> namer = (l) -> "L{" + l + "}";
|
||||
LongFunction<String> brackets = (l) -> "[[" + l + "]]";
|
||||
|
||||
ListSizedHashed f2 = new ListSizedHashed(sizer, namer, namer, brackets, namer);
|
||||
List<Object> for53 = f2.apply(53L);
|
||||
assertThat(for53).hasSize(53);
|
||||
assertThat(for53.get(2).toString()).startsWith("[[");
|
||||
assertThat(for53.get(52)).isOfAnyClassIn(String.class);
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user