mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
allow for reductive configuration in ParsedOp
This commit is contained in:
parent
ae40294ff4
commit
4d7355c803
@ -446,6 +446,13 @@ public class ParsedOp implements LongFunction<Map<String, ?>>, StaticFieldReader
|
||||
public <T> T getStaticConfigOr(String name, T defaultValue) {
|
||||
return tmap.getStaticConfigOr(name, defaultValue);
|
||||
}
|
||||
public <T> T takeStaticConfigOr(String name, T defaultValue) {
|
||||
return tmap.takeStaticConfigOr(name, defaultValue);
|
||||
}
|
||||
public String getStaticConfig(String name, Class<String> clazz) {
|
||||
return tmap.getStaticConfig(name, clazz);
|
||||
}
|
||||
|
||||
|
||||
public <T> Optional<T> getOptionalStaticConfig(String name, Class<T> type) {
|
||||
return tmap.getOptionalStaticConfig(name, type);
|
||||
@ -476,6 +483,11 @@ public class ParsedOp implements LongFunction<Map<String, ?>>, StaticFieldReader
|
||||
return Optional.ofNullable(tmap.getStaticValue(field, classOfT));
|
||||
}
|
||||
|
||||
|
||||
public <T> Optional<T> takeOptionalStaticValue(String field, Class<T> classOfT) {
|
||||
return Optional.ofNullable(tmap.takeStaticValue(field, classOfT));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the named field value for a given long input. This uses parameter type inference -- The casting
|
||||
* to the return type will be based on the type of any assignment or casting on the caller's side.
|
||||
|
@ -227,6 +227,10 @@ public class ParsedTemplateMap implements LongFunction<Map<String, ?>>, StaticFi
|
||||
return (T) statics.get(field);
|
||||
}
|
||||
|
||||
public <T> T takeStaticValue(String field, Class<T> classOfT) {
|
||||
return (T) statics.remove(field);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the static value for the provided name, cast to the required type, where the type is inferred
|
||||
* from the calling context.
|
||||
@ -294,6 +298,41 @@ public class ParsedTemplateMap implements LongFunction<Map<String, ?>>, StaticFi
|
||||
}
|
||||
}
|
||||
|
||||
public String getStaticConfig(String name, Class<String> clazz) {
|
||||
if (statics.containsKey(name)) {
|
||||
return NBTypeConverter.convert(statics.get(name),clazz);
|
||||
}
|
||||
for (Map<String, Object> cfgsource : cfgsources) {
|
||||
if (cfgsource.containsKey(name)) {
|
||||
return NBTypeConverter.convert(cfgsource.get(name),clazz);
|
||||
}
|
||||
}
|
||||
if (dynamics.containsKey(name)) {
|
||||
throw new OpConfigError("static config field '" + name + "' was defined dynamically. This may be supportable if the driver developer" +
|
||||
"updates the op mapper to support this field as a dynamic field, but it is not yet supported.");
|
||||
}
|
||||
throw new OpConfigError("static config field '" + name + "' was requested, but it does not exist");
|
||||
}
|
||||
|
||||
public <T> T takeStaticConfigOr(String name, T defaultValue) {
|
||||
if (statics.containsKey(name)) {
|
||||
Object value = statics.remove(name);
|
||||
return NBTypeConverter.convertOr(value, defaultValue);
|
||||
}
|
||||
for (Map<String, Object> cfgsource : cfgsources) {
|
||||
if (cfgsource.containsKey(name)) {
|
||||
return NBTypeConverter.convertOr(cfgsource.get(name), defaultValue);
|
||||
}
|
||||
}
|
||||
if (dynamics.containsKey(name)) {
|
||||
throw new OpConfigError("static config field '" + name + "' was defined dynamically. This may be supportable if the driver developer" +
|
||||
"updates the op mapper to support this field as a dynamic field, but it is not yet supported.");
|
||||
} else {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public <T> Optional<T> getOptionalStaticConfig(String name, Class<T> type) {
|
||||
if (statics.containsKey(name)) {
|
||||
return Optional.of(NBTypeConverter.convert(statics.get(name), type));
|
||||
|
Loading…
Reference in New Issue
Block a user