mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
add primitive int lambda for op fields
This commit is contained in:
parent
7b8e9145d7
commit
d5ec597152
@ -43,6 +43,7 @@ import java.util.*;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.LongFunction;
|
||||
import java.util.function.LongToIntFunction;
|
||||
|
||||
/**
|
||||
* <H1>ParsedOp API</H1>
|
||||
@ -662,6 +663,9 @@ public class ParsedOp extends NBBaseComponent implements LongFunction<Map<String
|
||||
public <V> LongFunction<V> getAsFunctionOr(String name, V defaultValue) {
|
||||
return tmap.getAsFunctionOr(name, defaultValue);
|
||||
}
|
||||
public LongToIntFunction getAsFunctionOrInt(String name, int defaultValue) {
|
||||
return tmap.getAsFunctionOrInt(name, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a LongFunction that first creates a LongFunction of String as in
|
||||
|
@ -38,6 +38,7 @@ import org.apache.logging.log4j.Logger;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.LongFunction;
|
||||
import java.util.function.LongToIntFunction;
|
||||
|
||||
/**
|
||||
* A parsed map template, which allows construction of extracted or projected functions related
|
||||
@ -618,6 +619,25 @@ public class ParsedTemplateMap implements LongFunction<Map<String, ?>>, StaticFi
|
||||
}
|
||||
}
|
||||
|
||||
public LongToIntFunction getAsFunctionOrInt(String name, int defaultValue) {
|
||||
if (isDynamic(name)) {
|
||||
LongFunction<?> f = dynamics.get(name);
|
||||
Object testValue = f.apply(0);
|
||||
if (!testValue.getClass().isPrimitive()) {
|
||||
throw new OpConfigError(STR."getAsFunctionOrInt returned non primitive type: \{testValue.getClass().getCanonicalName()}");
|
||||
}
|
||||
if (!testValue.getClass().equals(int.class)) {
|
||||
throw new OpConfigError(STR."getAsFunctionOrInt returned non-int type: \{testValue.getClass().getCanonicalName()}");
|
||||
}
|
||||
return (long i) -> (int) f.apply(i);
|
||||
} else if (isStatic(name) || isConfig(name)) {
|
||||
int v = (int) getStaticValue(name);
|
||||
return l -> v;
|
||||
} else {
|
||||
return l -> defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a LongFunction that first creates a LongFunction of String as in {@link #getAsFunctionOr(String, Object)} )}, but then
|
||||
* applies the result and cached it for subsequent access. This relies on {@link ObjectCache} internally.
|
||||
@ -1142,4 +1162,5 @@ public class ParsedTemplateMap implements LongFunction<Map<String, ?>>, StaticFi
|
||||
prototype.putAll(getConfigPrototype());
|
||||
return prototype;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user