pull ConfigAware api up

This commit is contained in:
Jonathan Shook
2020-10-23 02:36:04 -05:00
parent 71195d0a0b
commit 574a89e75a
8 changed files with 15 additions and 21 deletions

View File

@@ -1,7 +1,7 @@
package io.nosqlbench.virtdata.core.bindings;
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
import io.nosqlbench.virtdata.core.config.ConfigAware;
import io.nosqlbench.nb.api.config.ConfigAware;
import org.apache.commons.lang3.ClassUtils;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
@@ -64,10 +64,7 @@ public class VirtDataFunctionResolver {
return false;
}
Class<?> componentType = ctypes[ctypes.length - 1].getComponentType();
if (parameterTypes.length >= ctypes.length && !ClassUtils.isAssignable(parameterTypes[ctypes.length - 1], componentType, true)) {
return false;
}
return true;
return parameterTypes.length < ctypes.length || ClassUtils.isAssignable(parameterTypes[ctypes.length - 1], componentType, true);
} else {
if (parameterTypes.length!=ctypes.length) {
return false;

View File

@@ -1,8 +0,0 @@
package io.nosqlbench.virtdata.core.config;
import java.util.Map;
public interface ConfigAware {
void applyConfig(Map<String,?> element);
ConfigModel getConfigModel();
}

View File

@@ -1,91 +0,0 @@
package io.nosqlbench.virtdata.core.config;
import io.nosqlbench.nb.api.errors.BasicError;
import java.util.*;
public class ConfigData {
private final ConfigData inner;
private final LinkedHashMap<String,Object> configs;
public ConfigData(LinkedHashMap<String,Object> configs, ConfigData inner) {
this.configs = configs;
this.inner =inner;
}
public ConfigData(LinkedHashMap<String,Object> configs) {
this.configs = configs;
this.inner = null;
}
public ConfigData() {
this.configs = new LinkedHashMap<>();
this.inner = null;
}
public ConfigData layer() {
return new ConfigData(new LinkedHashMap<>(),this);
}
public ConfigData layer(Map<String,Object> configs ){
return new ConfigData(new LinkedHashMap<>(configs),this);
}
/**
* Get the typed optional value for the requested parameter name.
* @param name The name of the parameter to use
* @param type The class type which the value must be assignable to.
* @param <T> The generic parameter of the class type
* @return An optional of type T
* @throws BasicError if a value is found which can't be returned as the
* specified type.
*/
public <T> Optional<T> get(String name, Class<? extends T> type) {
Object o = configs.get(name);
if (o!=null) {
if (type.isAssignableFrom(o.getClass())) {
return Optional.of(type.cast(o));
} else {
throw new BasicError("Tried to access a virtdata config element named '" + name +
"' as a '" + type.getCanonicalName() + "', but it was not compatible with that type");
}
}
if (inner !=null) {
return inner.get(name, type);
}
return Optional.empty();
}
/**
* Get the typed optional list for the requested list name. This is no different than
* getting an object without the list qualifier, except that the type checking is done for
* you internal to the getList method.
* @param name The name of the parameter to return
* @param type The type of the list element. Every element must be assignable to this type.
* @param <T> The generic parameter of the list element type
* @return An optional list of T
* @throws BasicError if any of the elements are not assignable to the required element type
*/
public <T> Optional<List<T>> getList(String name, Class<? extends T> type) {
Optional<List> found = get(name, List.class);
if (found.isPresent()) {
ArrayList<T> list = new ArrayList<>();
for (Object o : found.get()) {
if (type.isAssignableFrom(o.getClass())) {
list.add(type.cast(o));
} else {
throw new BasicError("Tried to access a virtdata config list element found under name '" + name +
"' as a '" + type.getCanonicalName() + "', but it was not compatible with that type");
}
}
return Optional.of(list);
}
return Optional.empty();
}
public void put(String paramName, List<String> paramValue) {
this.configs.put(paramName,paramValue);
}
}

View File

@@ -1,17 +0,0 @@
package io.nosqlbench.virtdata.core.config;
import java.util.List;
public interface ConfigModel {
List<Element> getElements();
public static class Element {
public final String name;
public final Class<?> type;
public Element(String name, Class<?> type) {
this.name = name;
this.type =type;
}
}
}

View File

@@ -1,30 +0,0 @@
package io.nosqlbench.virtdata.core.config;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class MutableConfigModel implements ConfigModel {
private final List<ConfigModel.Element> elements = new ArrayList<>();
public MutableConfigModel() {}
public MutableConfigModel add(String name, Class<?> clazz) {
add(new ConfigModel.Element(name, clazz));
return this;
}
private void add(ConfigModel.Element element) {
this.elements.add(element);
}
public ConfigModel asReadOnly() {
return this;
}
@Override
public List<Element> getElements() {
return Collections.unmodifiableList(elements);
}
}

View File

@@ -1,5 +1,6 @@
package io.nosqlbench.virtdata.core.config;
import io.nosqlbench.nb.api.config.ConfigData;
import org.junit.Test;
import java.util.List;