
com.laamella.parameter_source.FallbackParameterSource Maven / Gradle / Ivy
package com.laamella.parameter_source;
import java.util.Optional;
import static java.util.Objects.requireNonNull;
/**
* Supports the "withFallback" method.
*/
public class FallbackParameterSource implements ParameterSource {
private final ParameterSource primarySource;
private final ParameterSource fallbackSource;
public FallbackParameterSource(ParameterSource primarySource, ParameterSource fallbackSource) {
requireNonNull(primarySource);
requireNonNull(fallbackSource);
this.primarySource = primarySource;
this.fallbackSource = fallbackSource;
}
@Override
public Optional getOptionalString(String key) {
Optional value = primarySource.getOptionalString(key);
if (value.isPresent()) {
return value;
}
return fallbackSource.getOptionalString(key);
}
@Override
public Optional getOptionalInteger(String key) {
Optional value = primarySource.getOptionalInteger(key);
if (value.isPresent()) {
return value;
}
return fallbackSource.getOptionalInteger(key);
}
@Override
public Optional
© 2015 - 2025 Weber Informatics LLC | Privacy Policy