Search in sources :

Example 1 with TypedDriverOption

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);
}
Also used : TypedDriverOption(com.datastax.oss.driver.api.core.config.TypedDriverOption) DriverOption(com.datastax.oss.driver.api.core.config.DriverOption) DefaultDriverOption(com.datastax.oss.driver.api.core.config.DefaultDriverOption)

Aggregations

DefaultDriverOption (com.datastax.oss.driver.api.core.config.DefaultDriverOption)1 DriverOption (com.datastax.oss.driver.api.core.config.DriverOption)1 TypedDriverOption (com.datastax.oss.driver.api.core.config.TypedDriverOption)1