Package es.urjc.etsii.grafo.services
Class ConfigService
java.lang.Object
es.urjc.etsii.grafo.services.ConfigService
Fallback configuration service for when it is not viable to use a Config DTO.
Avoid using this class and use small Config classes
(examples: SolverConfig, ExcelConfig, etc.) whenever possible
-
Constructor Summary
ConstructorsConstructorDescriptionConfigService
(org.springframework.core.env.Environment env) Set environment from spring -
Method Summary
Modifier and TypeMethodDescriptiongetBoolean
(String key) Get config value as a boolean.static boolean
getBoolean
(String key, boolean defaultValue) Get config value as a boolean.Get config value as a double.static double
Get config value as a double.Get config value as an integer.static int
Get config value as an integer.Get config value as a long.static long
Get config value as a long.Get config value as a String.static String
Get config value as a String.
-
Constructor Details
-
ConfigService
public ConfigService(org.springframework.core.env.Environment env) Set environment from spring- Parameters:
env
- current environment
-
-
Method Details
-
getInt
Get config value as an integer. Throws exception if the value exists but it is not an Integer- Parameters:
key
- Config key name- Returns:
- Config value for the given key
-
getLong
Get config value as a long. Throws exception if the value exists but it is not a long- Parameters:
key
- Config key name- Returns:
- Config value for the given key
-
getDouble
Get config value as a double. Throws exception if the value exists but it is not a double- Parameters:
key
- Config key name- Returns:
- Config value for the given key
-
getBoolean
Get config value as a boolean. Throws exception if the value exists but it is not an boolean- Parameters:
key
- Config key name- Returns:
- Config value for the given key
-
getInt
Get config value as an integer. Throws exception if the value exists but it is not an Integer- Parameters:
key
- Config key namedefaultValue
- value to return if config key does not exist. If the key exists but the value is not an integer an exception is thrown instead.- Returns:
- Config value for the given key, or default value if config key is not defined in the current environment
-
getLong
Get config value as a long. Throws exception if the value exists but it is not a long- Parameters:
key
- Config key namedefaultValue
- value to return if config key does not exist. If the key exists but the value is not a long an exception is thrown instead.- Returns:
- Config value for the given key, or default value if config key is not defined in the current environment
-
getDouble
Get config value as a double. Throws exception if the value exists but it is not a double- Parameters:
key
- Config key namedefaultValue
- value to return if config key does not exist. If the key exists but the value is not a double an exception is thrown instead.- Returns:
- Config value for the given key, or default value if config key is not defined in the current environment
-
getBoolean
Get config value as a boolean. Throws exception if the value exists but cannot be converted to a boolean.- Parameters:
key
- Config key namedefaultValue
- value to return if config key does not exist. If the key exists but the value is not a boolean an exception is thrown instead.- Returns:
- Config value for the given key, or default value if config key is not defined in the current environment
-
getString
Get config value as a String. Throws exception if the value exists but cannot be converted to String- Parameters:
key
- Config key name- Returns:
- Config value for the given key
-
getString
Get config value as a String. Throws exception if the value exists but cannot be converted to a String- Parameters:
key
- Config key namedefaultValue
- value to return if config key does not exist.- Returns:
- Config value for the given key, or default value if config key is not defined in the current environment
-