diff options
author | Thomas <> | 2023-10-02 13:08:24 +0200 |
---|---|---|
committer | Thomas <> | 2024-02-01 07:42:44 +0100 |
commit | b6a931c21927675491af40bc32cebfa5d432124e (patch) | |
tree | 0bfe7c0599c5e7ebfe755d84b429f973eb2e3fdf /eaaf_core_utils/src/main/java | |
parent | 7bb4a6638ab04a19172dc303d1d6b387fa064aa0 (diff) | |
download | EAAF-Components-b6a931c21927675491af40bc32cebfa5d432124e.tar.gz EAAF-Components-b6a931c21927675491af40bc32cebfa5d432124e.tar.bz2 EAAF-Components-b6a931c21927675491af40bc32cebfa5d432124e.zip |
feat(core): add configuration utils to operate on specific types of configuration values
Diffstat (limited to 'eaaf_core_utils/src/main/java')
-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() { + + } +} |