/** * Convert settings from the internal representation to the string representation used in the * preference storage. * * @param settings * The map of settings to convert. * @param settingDescriptions * The structure containing the {@link SettingsDescription} objects that will be used * to convert the setting values. * * @return The settings converted to the string representation used in the preference storage. */ public static Map<String, String> convert(Map<String, Object> settings, Map<String, TreeMap<Integer, SettingsDescription>> settingDescriptions) { Map<String, String> serializedSettings = new HashMap<>(); for (Entry<String, Object> setting : settings.entrySet()) { String settingName = setting.getKey(); Object internalValue = setting.getValue(); TreeMap<Integer, SettingsDescription> versionedSetting = settingDescriptions.get(settingName); Integer highestVersion = versionedSetting.lastKey(); SettingsDescription settingDesc = versionedSetting.get(highestVersion); if (settingDesc != null) { String stringValue = settingDesc.toString(internalValue); serializedSettings.put(settingName, stringValue); } else { Timber.w("Settings.convert() called with a setting that should have been removed: %s", settingName); } } return serializedSettings; }
/** * Convert a setting value to the "pretty" string representation. * * @param value * The setting's value. * * @return A pretty-printed version of the setting's value. */ public String toPrettyString(T value) { return toString(value); }