mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
Add support for using a sizing function in AlphaNumericString()
This commit is contained in:
parent
f22c7f84db
commit
a316962d22
@ -18,6 +18,7 @@ package io.nosqlbench.virtdata.library.basics.shared.from_long.to_string;
|
||||
|
||||
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.bindings.VirtDataConversions;
|
||||
import io.nosqlbench.virtdata.library.basics.shared.from_long.to_long.Hash;
|
||||
@ -36,15 +37,26 @@ public class AlphaNumericString implements LongFunction<String> {
|
||||
private final Hash hash = new Hash();
|
||||
private final LongToIntFunction lengthFunc;
|
||||
|
||||
|
||||
public AlphaNumericString(int length)
|
||||
{
|
||||
this.lengthFunc = (l) -> length;
|
||||
@Example({
|
||||
"AlphaNumericString(10)",
|
||||
"Create a 10-character alpha-numeric string"
|
||||
})
|
||||
@Example({
|
||||
"AlphaNumericString(HashRange(10, 20))",
|
||||
"Create an alpha-numeric string with a length between 10 and 20 characters"
|
||||
})
|
||||
public AlphaNumericString(int length) {
|
||||
this.lengthFunc = l -> length;
|
||||
}
|
||||
|
||||
public AlphaNumericString(Object lengthfunc)
|
||||
{
|
||||
this.lengthFunc = VirtDataConversions.adaptFunction(lengthfunc, LongToIntFunction.class);
|
||||
public AlphaNumericString(Object lengthfunc) {
|
||||
if (lengthfunc instanceof Number) {
|
||||
int length = ((Number) lengthfunc).intValue();
|
||||
this.lengthFunc = l -> length;
|
||||
}
|
||||
else {
|
||||
this.lengthFunc = VirtDataConversions.adaptFunction(lengthfunc, LongToIntFunction.class);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user