@Test public void shouldGetDefaultIntValue() { Config<String, String> config = Configuration.get("test1"); int value = config.getAsInt("nonexistingkey", 2); assertThat(value).isEqualTo(2); }
public static Config<String, String> get(String name, boolean readSystemPropertiesOnNull) { if (configurations.containsKey(name)) { return configurations.get(name); } for (PropertiesProvider propertyProvider : propertyProviders) { Map<String, String> props = propertyProvider.lookupProperties(name); if (props != null) { log.info("Loaded configuration for: " + name + " using " + propertyProvider.getClass().getName()); Config<String, String> conf; if (readSystemPropertiesOnNull) { conf = new SystemPropertiesMapWrapper(props); } else { conf = new MapWrapper(props); } configurations.put(name, conf); return conf; } } throw new RuntimeException("No configuration found for: " + name); }
Configuration { public static Config<String, String> get(String name, boolean readSystemPropertiesOnNull) { if (configurations.containsKey(name)) { return configurations.get(name); } for (PropertiesProvider propertyProvider : propertyProviders) { Map<String, String> props = propertyProvider.lookupProperties(name); if (props != null) { log.info("Loaded configuration for: " + name + " using " + propertyProvider.getClass().getName()); Config<String, String> conf; if (readSystemPropertiesOnNull) { conf = new SystemPropertiesMapWrapper(props); } else { conf = new MapWrapper(props); } configurations.put(name, conf); return conf; } } throw new RuntimeException("No configuration found for: " + name); } }
Configuration { public static Config<String, String> get(String name, boolean readSystemPropertiesOnNull) { if (configurations.containsKey(name)) { return configurations.get(name); } for (PropertiesProvider propertyProvider : propertyProviders) { Map<String, String> props = propertyProvider.lookupProperties(name); if (props != null) { log.info("Loaded configuration for: " + name + " using " + propertyProvider.getClass().getName()); Config<String, String> conf; if (readSystemPropertiesOnNull) { conf = new SystemPropertiesMapWrapper(props); } else { conf = new MapWrapper(props); } configurations.put(name, conf); return conf; } } throw new RuntimeException("No configuration found for: " + name); }  }
Configuration { public static Config<String, String> get(String name, boolean readSystemPropertiesOnNull) { if (configurations.containsKey(name)) { return configurations.get(name); } for (PropertiesProvider propertyProvider : propertyProviders) { Map<String, String> props = propertyProvider.lookupProperties(name); if (props != null) { log.info("Loaded configuration for: " + name + " using " + propertyProvider.getClass().getName()); Config<String, String> conf; if (readSystemPropertiesOnNull) { conf = new SystemPropertiesMapWrapper(props); } else { conf = new MapWrapper(props); } configurations.put(name, conf); return conf; } } throw new RuntimeException("No configuration found for: " + name); }  static Config<String, String> get(String name, boolean readSystemPropertiesOnNull); static Config<String, String> get(String name); static void registerPropertiesProvider(Class<? extends PropertiesProvider> providerClass); static void registerPropertiesProvider(PropertiesProvider provider); static void setConfiguration(String configurationName, ImmutableMap<String, String> properties); static void clearConfiguration(String configurationName); static void setFromFile(String configurationName, File file); }
Configuration { public static Config<String, String> get(String name, boolean readSystemPropertiesOnNull) { if (configurations.containsKey(name)) { return configurations.get(name); } for (PropertiesProvider propertyProvider : propertyProviders) { Map<String, String> props = propertyProvider.lookupProperties(name); if (props != null) { log.info("Loaded configuration for: " + name + " using " + propertyProvider.getClass().getName()); Config<String, String> conf; if (readSystemPropertiesOnNull) { conf = new SystemPropertiesMapWrapper(props); } else { conf = new MapWrapper(props); } configurations.put(name, conf); return conf; } } throw new RuntimeException("No configuration found for: " + name); }  static Config<String, String> get(String name, boolean readSystemPropertiesOnNull); static Config<String, String> get(String name); static void registerPropertiesProvider(Class<? extends PropertiesProvider> providerClass); static void registerPropertiesProvider(PropertiesProvider provider); static void setConfiguration(String configurationName, ImmutableMap<String, String> properties); static void clearConfiguration(String configurationName); static void setFromFile(String configurationName, File file);  }