List of usage examples for java.util Dictionary equals
public boolean equals(Object obj)
From source file:com.basistech.yca.FlatteningConfigFileManager.java
private void processAddOrUpdate(Path filename) { // create and modify look quite similar. Path child = configurationDirectory.resolve(filename); // The heck with content type probing, let's do this the simple way. int lastDot = filename.toString().lastIndexOf('.'); if (lastDot == -1) { LOG.info("File has no suffix; ignoring: " + child); return;/*from w w w. j ava 2 s. c o m*/ } ObjectMapper mapper; String suffix = filename.toString().substring(lastDot + 1); if ("json".equals(suffix) || "js".equals(suffix)) { mapper = new ObjectMapper(); } else if ("yaml".equals(suffix) || "yml".equals(suffix)) { mapper = new ObjectMapper(new YAMLFactory()); } else { LOG.error("Unsupported file name " + filename.toString()); return; } JsonNode content; try { content = mapper.readTree(child.toFile()); } catch (IOException e) { LOG.error("Failed to read contents of " + child, e); return; } @SuppressWarnings("unchecked") Dictionary<String, Object> dict = (Dictionary<String, Object>) JsonNodeFlattener.flatten(content); String pid[] = parsePid(filename); Configuration config; try { config = getConfiguration(toConfigKey(filename), pid[0], pid[1]); } catch (IOException e) { LOG.error("Failed to get configuration for " + formatPid(pid)); return; } Dictionary<String, Object> props = config.getProperties(); Hashtable<String, Object> old = null; if (props != null) { old = new Hashtable<>(new DictionaryAsMap<>(props)); } if (old != null) { old.remove(FILENAME_PROPERTY_KEY); old.remove(Constants.SERVICE_PID); old.remove(ConfigurationAdmin.SERVICE_FACTORYPID); } if (!dict.equals(old)) { dict.put(FILENAME_PROPERTY_KEY, toConfigKey(filename)); if (old == null) { LOG.info("Creating configuration from " + filename); } else { LOG.info("Updating configuration from " + filename); } try { config.update(dict); } catch (IOException e) { LOG.error("Failed to update configuration for " + formatPid(pid)); } } }
From source file:org.datacleaner.reference.AbstractReferenceDataTest.java
public void testSerializationAndDeserializationOfDictionaries() throws Exception { String[] dictionaryNames = referenceDataCatalog.getDictionaryNames(); for (String name : dictionaryNames) { Dictionary dict = referenceDataCatalog.getDictionary(name); if (dict instanceof AbstractReferenceData) { System.out.println("Cloning dictionary: " + dict); Object clone = SerializationUtils.clone(dict); if (!dict.equals(clone)) { dict.equals(clone);/*from ww w . j a va2 s . com*/ } assertEquals(dict, clone); } } }