mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2024-12-02 13:29:26 -06:00
add uniform mutator methods to config model APIs
This commit is contained in:
parent
5dbfa385a8
commit
b9d08bf04c
@ -67,6 +67,10 @@ public interface NBConfigModel {
|
|||||||
*/
|
*/
|
||||||
NBConfiguration extractConfig(NBConfiguration cfg);
|
NBConfiguration extractConfig(NBConfiguration cfg);
|
||||||
|
|
||||||
|
NBConfiguration matchConfig(NBConfiguration cfg);
|
||||||
|
|
||||||
|
NBConfiguration matchConfig(Map<String, ?> sharedConfig);
|
||||||
|
|
||||||
NBConfigModel add(NBConfigModel otherModel);
|
NBConfigModel add(NBConfigModel otherModel);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,9 @@
|
|||||||
|
|
||||||
package io.nosqlbench.nb.api.config.standard;
|
package io.nosqlbench.nb.api.config.standard;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All implementation types which wish to have a type-marshalled configuration
|
* All implementation types which wish to have a type-marshalled configuration
|
||||||
* should implement this interface.
|
* should implement this interface.
|
||||||
@ -46,4 +49,34 @@ public interface NBConfigurable extends NBCanConfigure, NBConfigModelProvider {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
NBConfigModel getConfigModel();
|
NBConfigModel getConfigModel();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience method to apply a configuration to any object which
|
||||||
|
* is expected to be be configurable.
|
||||||
|
* @param cfg The cfg to apply
|
||||||
|
* @param configurables zero or more Objects which may implement NBConfigurable
|
||||||
|
*/
|
||||||
|
static void applyMatching(NBConfiguration cfg, Object... configurables) {
|
||||||
|
for (Object configurable : configurables) {
|
||||||
|
if (configurable instanceof NBConfigurable c) {
|
||||||
|
NBConfiguration partial = c.getConfigModel().matchConfig(cfg);
|
||||||
|
c.applyConfig(partial);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static NBConfigModel collectModels(Class<?> of, Collection<?> configurables) {
|
||||||
|
ConfigModel model = ConfigModel.of(of);
|
||||||
|
for (Object configurable : configurables) {
|
||||||
|
if (configurable instanceof NBConfigurable c) {
|
||||||
|
model = model.add(c.getConfigModel());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return model.asReadOnly();
|
||||||
|
}
|
||||||
|
|
||||||
|
static NBConfigModel collectModels(Class<?> of, Object... configurables) {
|
||||||
|
return collectModels(of, Arrays.asList(configurables));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user