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

de.felixroske.jfxsupport.PropertyReaderHelper Maven / Gradle / Ivy

package de.felixroske.jfxsupport;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

import org.springframework.core.env.Environment;

public class PropertyReaderHelper {

    public static List get(Environment env, String propName) {
        ArrayList list = new ArrayList<>();
        
        String singleProp = env.getProperty(propName);
        if(singleProp != null) {
            list.add(singleProp);
            return list;
        }
        
        int counter = 0;
        String prop = env.getProperty(propName + "[" + counter + "]");
        while (prop != null) {
            list.add(prop);
            counter++;
            prop = env.getProperty(propName + "[" + counter + "]");
        }

        return list;
    }
    
    public static  void setIfPresent(Environment env, String key, Class type, Consumer function) {
        T value = (T) env.getProperty(key,type);
        if(value != null) {
            function.accept(value);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy