Class ConfigService

java.lang.Object
es.urjc.etsii.grafo.services.ConfigService

@Service public class ConfigService extends Object
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 Details

    • ConfigService

      public ConfigService(org.springframework.core.env.Environment env)
      Set environment from spring
      Parameters:
      env - current environment
  • Method Details

    • getInt

      public static Optional<Integer> getInt(String key)
      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

      public static Optional<Long> getLong(String key)
      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

      public static Optional<Double> getDouble(String key)
      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

      public static Optional<Boolean> getBoolean(String key)
      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

      public static int getInt(String key, int defaultValue)
      Get config value as an integer. Throws exception if the value exists but it is not an Integer
      Parameters:
      key - Config key name
      defaultValue - 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

      public static long getLong(String key, long defaultValue)
      Get config value as a long. Throws exception if the value exists but it is not a long
      Parameters:
      key - Config key name
      defaultValue - 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

      public static double getDouble(String key, double defaultValue)
      Get config value as a double. Throws exception if the value exists but it is not a double
      Parameters:
      key - Config key name
      defaultValue - 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

      public static boolean getBoolean(String key, boolean defaultValue)
      Get config value as a boolean. Throws exception if the value exists but cannot be converted to a boolean.
      Parameters:
      key - Config key name
      defaultValue - 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

      public static Optional<String> getString(String key)
      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

      public static String getString(String key, String defaultValue)
      Get config value as a String. Throws exception if the value exists but cannot be converted to a String
      Parameters:
      key - Config key name
      defaultValue - 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