You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.5 KiB
63 lines
1.5 KiB
package org.leolo.rail.nrd; |
|
|
|
import java.io.FileReader; |
|
import java.io.IOException; |
|
import java.util.Properties; |
|
import java.util.function.BiConsumer; |
|
|
|
import org.apache.logging.log4j.LogManager; |
|
import org.apache.logging.log4j.Logger; |
|
|
|
public class ConfigurationManager { |
|
private static Logger log = LogManager.getLogger(ConfigurationManager.class); |
|
|
|
private static ConfigurationManager instance; |
|
private Properties prop = new Properties(); |
|
|
|
public synchronized static ConfigurationManager getInstance() { |
|
if(instance==null) { |
|
instance = new ConfigurationManager(); |
|
} |
|
return instance; |
|
} |
|
|
|
private ConfigurationManager() { |
|
try(FileReader fr = new FileReader("configuration.properties")){ |
|
log.debug("Loading properties file"); |
|
prop.load(fr); |
|
log.info("{} entries loaded", prop.size()); |
|
}catch(IOException e) { |
|
log.fatal(e.getMessage(), e); |
|
System.exit(1); |
|
} |
|
|
|
} |
|
|
|
public void forEach(BiConsumer<? super Object, ? super Object> action) { |
|
prop.forEach(action); |
|
} |
|
|
|
public Object get(Object key) { |
|
return prop.get(key); |
|
} |
|
|
|
public Object getOrDefault(Object key, Object defaultValue) { |
|
return prop.getOrDefault(key, defaultValue); |
|
} |
|
|
|
public String getProperty(String key, String defaultValue) { |
|
return prop.getProperty(key, defaultValue); |
|
} |
|
|
|
public String getProperty(String key) { |
|
return prop.getProperty(key); |
|
} |
|
|
|
public int size() { |
|
return prop.size(); |
|
} |
|
|
|
public boolean containsKey(Object key) { |
|
return prop.containsKey(key); |
|
} |
|
}
|
|
|