io.nosqlbench.nb.api.config.ConfigReader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of driver-cql-shaded Show documentation
Show all versions of driver-cql-shaded Show documentation
A Shaded CQL ActivityType driver for http://nosqlbench.io/
package io.nosqlbench.nb.api.config;
import io.nosqlbench.nb.api.NBEnvironment;
import java.util.LinkedHashMap;
import java.util.Optional;
public class ConfigReader extends LinkedHashMap {
private final ConfigModel configModel;
public ConfigReader(ConfigModel model, LinkedHashMap validConfig) {
super(validConfig);
this.configModel = model;
}
public T paramEnv(String name, Class extends T> vclass) {
T param = param(name, vclass);
if (param instanceof String) {
Optional interpolated = NBEnvironment.INSTANCE.interpolate(param.toString());
if (interpolated.isEmpty()) {
throw new RuntimeException("Unable to interpolate env and sys props in '" + param + "'");
}
return (T) interpolated.get();
} else {
return param;
}
}
public T param(String name, Class extends T> vclass) {
Object o = get(name);
ConfigElement> elem = configModel.getElements().get(name);
if (elem == null) {
throw new RuntimeException("Invalid config element named '" + name + "'" );
}
Class type = (Class) elem.getType();
T typeCastedValue = type.cast(o);
return typeCastedValue;
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(this.configModel.getOf().getSimpleName()).append(":" );
sb.append(this.configModel.toString());
return sb.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy