use of com.datastax.oss.driver.api.core.config.TypedDriverOption in project java-driver by datastax.
the class MapBasedDriverConfigLoaderTest method get.
private Optional<Object> get(DriverExecutionProfile config, TypedDriverOption<?> typedOption) {
DriverOption option = typedOption.getRawOption();
GenericType<?> type = typedOption.getExpectedType();
Object value = null;
if (config.isDefined(option)) {
// anywhere outside of this test.
if (type.equals(GenericType.listOf(String.class))) {
value = config.getStringList(option);
} else if (type.equals(GenericType.STRING)) {
value = config.getString(option);
} else if (type.equals(GenericType.DURATION)) {
value = config.getDuration(option);
} else if (type.equals(GenericType.INTEGER)) {
value = config.getInt(option);
} else if (type.equals(GenericType.BOOLEAN)) {
value = config.getBoolean(option);
} else if (type.equals(GenericType.LONG)) {
try {
value = config.getLong(option);
} catch (ConfigException.WrongType e) {
value = config.getBytes(option);
}
} else if (type.equals(GenericType.mapOf(GenericType.STRING, GenericType.STRING))) {
value = config.getStringMap(option);
} else {
fail("Unexpected type " + type);
}
}
return Optional.ofNullable(value);
}
Aggregations