diff options
author | Thomas <> | 2023-10-02 13:08:24 +0200 |
---|---|---|
committer | Thomas <> | 2023-10-02 13:08:24 +0200 |
commit | 7dc56d353fcd5c76d9be3660bbdd2cb4a8b23f38 (patch) | |
tree | 64a55366956bb43f6bea22facc031e688de0ebde /eaaf_core_utils/src/main/java/at | |
parent | 44240b20f863fbd437e06947b539f76e73e91668 (diff) | |
download | EAAF-Components-7dc56d353fcd5c76d9be3660bbdd2cb4a8b23f38.tar.gz EAAF-Components-7dc56d353fcd5c76d9be3660bbdd2cb4a8b23f38.tar.bz2 EAAF-Components-7dc56d353fcd5c76d9be3660bbdd2cb4a8b23f38.zip |
feat(core): add configuration utils to operate on specific types of configuration values
Diffstat (limited to 'eaaf_core_utils/src/main/java/at')
-rw-r--r-- | eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/ConfigurationUtils.java | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/ConfigurationUtils.java b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/ConfigurationUtils.java new file mode 100644 index 00000000..2e6d53c9 --- /dev/null +++ b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/ConfigurationUtils.java @@ -0,0 +1,62 @@ +package at.gv.egiz.eaaf.core.impl.utils; + +import at.gv.egiz.eaaf.core.api.idp.IConfiguration; +import at.gv.egiz.eaaf.core.exceptions.EaafConfigurationException; +import lombok.extern.slf4j.Slf4j; + +/** + * Utils for configuration value mapping. + * + * @author tlenz + * + */ +@Slf4j +public class ConfigurationUtils { + + + /** + * Parse Integer value from configuration. + * + * @param basicConfig Configuration object + * @param propertyKey Configuration key + * @return Configuration value + * @throws EaafConfigurationException If configuration value is not an Integer + */ + public static int parseInteger(IConfiguration basicConfig, String propertyKey) + throws EaafConfigurationException { + try { + return Integer.parseInt(basicConfig.getBasicConfiguration(propertyKey)); + + } catch (NumberFormatException e) { + log.error("Can not read Integer value from configuration: {}", propertyKey, e); + throw new EaafConfigurationException("internal.configuration.02", + new Object[] { propertyKey, Integer.class.getSimpleName() }, e); + + } + } + + /** + * Parse Long value from configuration. + * + * @param basicConfig Configuration object + * @param propertyKey Configuration key + * @return Configuration value + * @throws EaafConfigurationException If configuration value is not an Long + */ + public static long parseLong(IConfiguration basicConfig, String propertyKey) + throws EaafConfigurationException { + try { + return Long.parseLong(basicConfig.getBasicConfiguration(propertyKey)); + + } catch (NumberFormatException e) { + log.error("Can not read Long value from configuration: {}", propertyKey, e); + throw new EaafConfigurationException("internal.configuration.02", + new Object[] { propertyKey, Long.class.getSimpleName() }, e); + + } + } + + private ConfigurationUtils() { + + } +} |