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 nb-api Show documentation
Show all versions of nb-api Show documentation
The top level API module for NoSQLBench. This module should have no internal
module dependencies other than the mvn-default module.
All modules within NoSQLBench can safely depend on this module with circular
dependencies. This module provides cross-cutting code infrastracture, such as
path utilities and ways of describing services used between modules.
It is also the transitive aggregation point for system-wide library dependencies
for logging and testing or similar needs.
package io.nosqlbench.nb.api.config.params;
import java.util.*;
/**
* The source data for a param reader is intended to be a collection of something, not a single value.
* As such, if a single value is provided, an attempt will be made to convert it from JSON if it starts with
* object or array notation. If not, the value is assumed to be in the simple ParamsParser form.
*/
public class ElementImpl implements Element {
private final ElementData data;
public ElementImpl(ElementData data) {
this.data = data;
}
public String getElementName() {
String name = data.getGivenName();
if (name!=null) {
return name;
}
return get(ElementData.NAME, String.class).orElse(null);
}
public Optional get(String name, Class extends T> classOfT) {
T found = lookup(data,name, classOfT);
return Optional.ofNullable(found);
}
@Override
public Optional get(String name) {
return Optional.ofNullable(data.lookup(name,null));
}
private T lookup(ElementData data, String name, Class type) {
return data.lookup(name,type);
// int idx=name.indexOf('.');
// while (idx>0) { // TODO: What about when idx==0 ?
// String parentName = name.substring(0,idx);
// if (data.containsKey(parentName)) {
// Object o = data.get(parentName);
// ElementData parentElement = DataSources.element(o);
// String childName = name.substring(idx+1);
// T found = parentElement.lookup(name,type);
// if (found!=null) {
// return found;
// }
// }
// idx=name.indexOf('.',idx+1);
// }
// return data.get(name,type);
}
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;
}
@Override
public String toString() {
return data.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy