@Test public void getLong() throws Exception { String key = "myKey"; assertEquals(1, settings.getLong(key, 1)); assertEquals(2, settings.getLong(key, 2)); map.put(key, 3L); assertEquals(3, settings.getLong(key, 2)); map.put(key, "4"); assertEquals(4, settings.getLong(key, 2)); map.put(key, new Object()); try { settings.getLong(key, 9); fail(); } catch (ClassCastException e) { ; } }
public long getLong(String key, int defaultValue) { Object value = map.get(key); if (value == null) { return defaultValue; } else if (value instanceof Long) { return (Long) value; } else if (value instanceof String) { return Long.parseLong((String) value); } else { throw new ClassCastException(errorMessage(key, value, "long")); } }
TypedSettings { public long getLong(String key, int defaultValue) { Object value = map.get(key); if (value == null) { return defaultValue; } else if (value instanceof Long) { return (Long) value; } else if (value instanceof String) { return Long.parseLong((String) value); } else { throw new ClassCastException(errorMessage(key, value, "long")); } } }
TypedSettings { public long getLong(String key, int defaultValue) { Object value = map.get(key); if (value == null) { return defaultValue; } else if (value instanceof Long) { return (Long) value; } else if (value instanceof String) { return Long.parseLong((String) value); } else { throw new ClassCastException(errorMessage(key, value, "long")); } } TypedSettings(Map<String, Object> map); }
TypedSettings { public long getLong(String key, int defaultValue) { Object value = map.get(key); if (value == null) { return defaultValue; } else if (value instanceof Long) { return (Long) value; } else if (value instanceof String) { return Long.parseLong((String) value); } else { throw new ClassCastException(errorMessage(key, value, "long")); } } 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 long getLong(String key, int defaultValue) { Object value = map.get(key); if (value == null) { return defaultValue; } else if (value instanceof Long) { return (Long) value; } else if (value instanceof String) { return Long.parseLong((String) value); } else { throw new ClassCastException(errorMessage(key, value, "long")); } } 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; }