All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.mowedgrass.jasyptgradleboot.password.property.PropertyResolver Maven / Gradle / Ivy

There is a newer version: 0.1.32
Show newest version
package com.github.mowedgrass.jasyptgradleboot.password.property;

import org.springframework.core.env.StandardEnvironment;

import java.util.Optional;
import java.util.function.Function;

import static java.util.Optional.ofNullable;

public class PropertyResolver {

    private StandardEnvironment environment;

    public PropertyResolver(StandardEnvironment environment) {
        this.environment = environment;
    }

    public Optional getEnvironmentProperty(String key) {
        return getProperty(environment::getProperty, key);
    }

    public Optional getSystemProperty(String key) {
        return getProperty(
                property -> ((String) environment.getSystemEnvironment().get(property)),
                key
        );
    }

    private Optional getProperty(Function source, String key) {
        return ofNullable(source.apply(key))
                .filter(s -> !s.isEmpty());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy