@Test public void testBoolean() throws Exception { String key = "myKey"; assertTrue(settings.getBoolean(key, true)); assertFalse(settings.getBoolean(key, false)); map.put(key, Boolean.TRUE); assertTrue(settings.getBoolean(key, false)); map.put(key, "true"); assertTrue(settings.getBoolean(key, false)); map.put(key, new Object()); try { settings.getBoolean(key, false); fail(); } catch (ClassCastException e) { ; } }
public boolean getBoolean(String key, boolean defaultValue) { Object value = map.get(key); if (value == null) { return defaultValue; } else if (value instanceof Boolean) { return (Boolean) value; } else if (value instanceof String) { return Boolean.parseBoolean((String) value); } else { throw new ClassCastException(errorMessage(key, value, "boolean")); } }
TypedSettings { public boolean getBoolean(String key, boolean defaultValue) { Object value = map.get(key); if (value == null) { return defaultValue; } else if (value instanceof Boolean) { return (Boolean) value; } else if (value instanceof String) { return Boolean.parseBoolean((String) value); } else { throw new ClassCastException(errorMessage(key, value, "boolean")); } } }
TypedSettings { public boolean getBoolean(String key, boolean defaultValue) { Object value = map.get(key); if (value == null) { return defaultValue; } else if (value instanceof Boolean) { return (Boolean) value; } else if (value instanceof String) { return Boolean.parseBoolean((String) value); } else { throw new ClassCastException(errorMessage(key, value, "boolean")); } } TypedSettings(Map<String, Object> map); }
TypedSettings { public boolean getBoolean(String key, boolean defaultValue) { Object value = map.get(key); if (value == null) { return defaultValue; } else if (value instanceof Boolean) { return (Boolean) value; } else if (value instanceof String) { return Boolean.parseBoolean((String) value); } else { throw new ClassCastException(errorMessage(key, value, "boolean")); } } TypedSettings(Map<String, Object> map); String getString(String key, String defaultValue); boolean getBoolean(String key, boolean defaultValue); int getInt(String key, int defaultValue); long getLong(String key, int defaultValue); double getDouble(String key, double defaultValue); float getFloat(String key, float defaultValue); Object getObject(String key, Object defaultValue); }
TypedSettings { public boolean getBoolean(String key, boolean defaultValue) { Object value = map.get(key); if (value == null) { return defaultValue; } else if (value instanceof Boolean) { return (Boolean) value; } else if (value instanceof String) { return Boolean.parseBoolean((String) value); } else { throw new ClassCastException(errorMessage(key, value, "boolean")); } } TypedSettings(Map<String, Object> map); String getString(String key, String defaultValue); boolean getBoolean(String key, boolean defaultValue); int getInt(String key, int defaultValue); long getLong(String key, int defaultValue); double getDouble(String key, double defaultValue); float getFloat(String key, float defaultValue); Object getObject(String key, Object defaultValue); static final String DRY_RUN_SETTING_NAME; static final String TASK_CONTEXT_SETTING_NAME; }