io.deepsense.neptune.clientlibrary.config.user.MultiSourcedUserConfiguration Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of neptune-client-library Show documentation
Show all versions of neptune-client-library Show documentation
Enables integration with Neptune in your Java code
/**
* Copyright (c) 2016, CodiLime Inc.
*/
package io.deepsense.neptune.clientlibrary.config.user;
import com.google.common.base.Preconditions;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
public final class MultiSourcedUserConfiguration extends StaticUserConfiguration {
/**
* Creates a combined configuration based on given configurations.
* Each next configuration overrides the previous one.
*
* @param configurations Base configurations, ordered from the least important to most important.
* @return multiSourcedUserConfiguration
*/
public static MultiSourcedUserConfiguration create(UserConfiguration... configurations) {
List configurationList = Arrays.asList(Preconditions.checkNotNull(configurations));
return new MultiSourcedUserConfiguration(
getOverridenConfigurationProperty(configurationList, UserConfiguration::getUsername).orElse(null),
getOverridenConfigurationProperty(configurationList, UserConfiguration::getPassword).orElse(null));
}
private MultiSourcedUserConfiguration(String username, String password) {
super(username, password);
}
private static Optional getOverridenConfigurationProperty(
List configurations,
Function> configurationPropertyExtractor) {
return configurations.stream()
.map(configurationPropertyExtractor)
.reduce(Optional.empty(), MultiSourcedUserConfiguration::overrideConfigurationProperty);
}
private static Optional overrideConfigurationProperty(
Optional propertyToOverride,
Optional overridingProperty) {
return Optional.ofNullable(overridingProperty.orElse(propertyToOverride.orElse(null)));
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy