HTraceConfiguration { public boolean getBoolean(String key, boolean defaultValue) { String value = get(key, String.valueOf(defaultValue)).trim().toLowerCase(); if ("true".equals(value)) { return true; } else if ("false".equals(value)) { return false; } LOG.warn("Expected boolean for key [" + key + "] instead got [" + value + "]."); return defaultValue; }  static HTraceConfiguration fromMap(Map<String, String> conf); static HTraceConfiguration fromKeyValuePairs(String... pairs); abstract String get(String key); abstract String get(String key, String defaultValue); boolean getBoolean(String key, boolean defaultValue); int getInt(String key, int defaultVal); static final HTraceConfiguration EMPTY; }
@Test public void testGetBoolean() throws Exception { Map<String, String> m = new HashMap<String, String>(); m.put("testTrue", " True"); m.put("testFalse", "falsE "); HTraceConfiguration configuration = HTraceConfiguration.fromMap(m); assertTrue(configuration.getBoolean("testTrue", false)); assertFalse(configuration.getBoolean("testFalse", true)); assertTrue(configuration.getBoolean("absent", true)); assertFalse(configuration.getBoolean("absent", false)); }