io.nosqlbench.nb.api.config.params.ElementImpl 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.params;
import java.util.*;
public class ElementImpl implements Element {
private final ElementData data;
public ElementImpl(ElementData data) {
this.data = data;
}
public String getElementName() {
return get(ElementData.NAME, String.class).orElse(null);
}
public Optional get(String name, Class extends T> classOfT) {
List path = Arrays.asList(name.split("\\."));
ElementData top = data;
int idx = 0;
String lookup = path.get(idx);
while (idx + 1 < path.size()) {
if (!top.containsKey(lookup)) {
throw new RuntimeException("unable to find '" + lookup + "' in '" + String.join(".", path));
}
Object o = top.get(lookup);
top = DataSources.element(o);
// top = top.getChildElementData(lookup);
idx++;
lookup = path.get(idx);
}
if (top.containsKey(lookup)) {
Object elem = top.get(lookup);
T convertedValue = top.convert(elem, classOfT);
// T typeCastedValue = classOfT.cast(elem);
return Optional.of(convertedValue);
} else {
return Optional.empty();
}
}
public T getOr(String name, T defaultValue) {
Class cls = (Class) defaultValue.getClass();
return get(name, cls).orElse(defaultValue);
}
@Override
public Map getMap() {
Set keys = this.data.getKeys();
Map map = new LinkedHashMap<>();
for (String key : keys) {
Object value = this.data.get(key);
map.put(key, value);
}
return map;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy