@Test public void allowsNewAndMissingKeys() { defaults.put("one", false); newValues.put("two", false); assertTrue(validator.isValid(newValues)); }
boolean isValid(Map<String, Object> preferences) { for (Map.Entry<String, Object> entry : defaults.entrySet()) { Object defaultValue = entry.getValue(); Object newValue = preferences.get(entry.getKey()); if (newValue != null) { if (!defaultValue.getClass().isAssignableFrom(newValue.getClass())) { return false; } } } return true; }
PreferenceValidator { boolean isValid(Map<String, Object> preferences) { for (Map.Entry<String, Object> entry : defaults.entrySet()) { Object defaultValue = entry.getValue(); Object newValue = preferences.get(entry.getKey()); if (newValue != null) { if (!defaultValue.getClass().isAssignableFrom(newValue.getClass())) { return false; } } } return true; } }
PreferenceValidator { boolean isValid(Map<String, Object> preferences) { for (Map.Entry<String, Object> entry : defaults.entrySet()) { Object defaultValue = entry.getValue(); Object newValue = preferences.get(entry.getKey()); if (newValue != null) { if (!defaultValue.getClass().isAssignableFrom(newValue.getClass())) { return false; } } } return true; } PreferenceValidator(Map<String, Object> defaults); }
PreferenceValidator { boolean isValid(Map<String, Object> preferences) { for (Map.Entry<String, Object> entry : defaults.entrySet()) { Object defaultValue = entry.getValue(); Object newValue = preferences.get(entry.getKey()); if (newValue != null) { if (!defaultValue.getClass().isAssignableFrom(newValue.getClass())) { return false; } } } return true; } PreferenceValidator(Map<String, Object> defaults);  }
PreferenceValidator { boolean isValid(Map<String, Object> preferences) { for (Map.Entry<String, Object> entry : defaults.entrySet()) { Object defaultValue = entry.getValue(); Object newValue = preferences.get(entry.getKey()); if (newValue != null) { if (!defaultValue.getClass().isAssignableFrom(newValue.getClass())) { return false; } } } return true; } PreferenceValidator(Map<String, Object> defaults);   }