protected void maintainVersion() { if (shouldUpdate()) { if (isOutOfDate()) { // we need to update from the default, overriding any out-dated keys loader.updateFromResource(); for (EntryType type : EntryType.values()) { LinkedHashMap<String, ConfigEntry> mappings = loader.getMappings(type); data.put(type, mappings); } } } setDateStamp(); }
/** @return */ private LinkedHashMap<String, List<String>> getDataStrings() { LinkedHashMap<String, List<String>> dataToWrite = new LinkedHashMap<String, List<String>>(); for (EntryType type : EntryType.values()) { if (!data.containsKey(type)) { continue; } List<String> linesToWrite = new ArrayList<String>(); LinkedHashMap<String, ConfigEntry> typeMappings = data.get(type); for (String key : typeMappings.keySet()) { ConfigEntry entry = typeMappings.get(key); String entryString = safelyGetSaveString(entry); linesToWrite.add(String.format("%s %s", key, entryString)); } dataToWrite.put(type.toString(), linesToWrite); } return dataToWrite; }
public boolean loadFromConfig() { loader.setForceReload(true); boolean changed = false; synchronized (data) { LinkedHashMap<String, List<String>> oldData = getDataStrings(); data.clear(); for (EntryType type : EntryType.values()) { LinkedHashMap<String, ConfigEntry> mappings = loader.getMappings(type); data.put(type, mappings); } maintainVersion(); LinkedHashMap<String, List<String>> newData = getDataStrings(); changed |= !oldData.equals(newData); if (changed) { savedDataStrings.clear(); savedDataStrings.putAll(newData); } } return changed; }
public <T extends ConfigManager> boolean copyFromManager(T manager) { boolean changed = false; synchronized (data) { LinkedHashMap<String, List<String>> oldData = getDataStrings(); data.clear(); for (EntryType type : EntryType.values()) { LinkedHashMap<String, ConfigEntry> mappings = new LinkedHashMap<String, ConfigEntry>(); List<String> keyOrder = new ArrayList<String>(); for (String key : manager.getKeys(type)) { ConfigEntry entry = manager.getEntry(type, key); keyOrder.add(key); mappings.put(key, entry); } data.put(type, mappings); } LinkedHashMap<String, List<String>> newData = getDataStrings(); changed |= !oldData.equals(newData); onCopyFrom(manager); } return changed; }