@Test public void getDouble() throws Exception { String key = "myKey"; assertEquals(1.0, settings.getDouble(key, 1.0), 1.0E-100); assertEquals(2.0, settings.getDouble(key, 2.0), 1.0E-100); map.put(key, 3.0); assertEquals(3.0, settings.getDouble(key, 2.0), 1.0E-100); map.put(key, "4"); assertEquals(4.0, settings.getDouble(key, 2.0), 1.0E-100); map.put(key, new Object()); try { settings.getDouble(key, 9.0); fail(); } catch (ClassCastException e) { ; } }
public double getDouble(String key, double defaultValue) { Object value = map.get(key); if (value == null) { return defaultValue; } else if (value instanceof Double) { return (Double) value; } else if (value instanceof String) { return Double.parseDouble((String) value); } else { throw new ClassCastException(errorMessage(key, value, "double")); } }
TypedSettings { public double getDouble(String key, double defaultValue) { Object value = map.get(key); if (value == null) { return defaultValue; } else if (value instanceof Double) { return (Double) value; } else if (value instanceof String) { return Double.parseDouble((String) value); } else { throw new ClassCastException(errorMessage(key, value, "double")); } } }
TypedSettings { public double getDouble(String key, double defaultValue) { Object value = map.get(key); if (value == null) { return defaultValue; } else if (value instanceof Double) { return (Double) value; } else if (value instanceof String) { return Double.parseDouble((String) value); } else { throw new ClassCastException(errorMessage(key, value, "double")); } } TypedSettings(Map<String, Object> map); }
TypedSettings { public double getDouble(String key, double defaultValue) { Object value = map.get(key); if (value == null) { return defaultValue; } else if (value instanceof Double) { return (Double) value; } else if (value instanceof String) { return Double.parseDouble((String) value); } else { throw new ClassCastException(errorMessage(key, value, "double")); } } 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 double getDouble(String key, double defaultValue) { Object value = map.get(key); if (value == null) { return defaultValue; } else if (value instanceof Double) { return (Double) value; } else if (value instanceof String) { return Double.parseDouble((String) value); } else { throw new ClassCastException(errorMessage(key, value, "double")); } } 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; }