Avoid using TreeMap methods introduced with API 9
This commit is contained in:
parent
ffa77ad288
commit
a191415860
2 changed files with 32 additions and 13 deletions
|
@ -5,6 +5,7 @@ import java.util.HashMap;
|
|||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
|
@ -44,15 +45,25 @@ public class Settings {
|
|||
for (Map.Entry<String, TreeMap<Integer, SettingsDescription>> versionedSetting :
|
||||
settings.entrySet()) {
|
||||
|
||||
Entry<Integer, SettingsDescription> setting =
|
||||
versionedSetting.getValue().floorEntry(version);
|
||||
// Get the setting description with the highest version lower than or equal to the
|
||||
// supplied content version.
|
||||
TreeMap<Integer, SettingsDescription> versions = versionedSetting.getValue();
|
||||
SortedMap<Integer, SettingsDescription> headMap = versions.headMap(version + 1);
|
||||
|
||||
if (setting == null) {
|
||||
// Skip this setting if it was introduced after 'version'
|
||||
if (headMap.size() == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Integer settingVersion = headMap.lastKey();
|
||||
SettingsDescription desc = versions.get(settingVersion);
|
||||
|
||||
// Skip this setting if it is no longer used in 'version'
|
||||
if (desc == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String key = versionedSetting.getKey();
|
||||
SettingsDescription desc = setting.getValue();
|
||||
|
||||
boolean useDefaultValue;
|
||||
if (!importedSettings.containsKey(key)) {
|
||||
|
@ -127,7 +138,7 @@ public class Settings {
|
|||
// Check if it was already added to upgradedSettings by the SettingsUpgrader
|
||||
if (!upgradedSettings.containsKey(settingName)) {
|
||||
// Insert default value to upgradedSettings
|
||||
SettingsDescription setting = versionedSettings.firstEntry().getValue();
|
||||
SettingsDescription setting = versionedSettings.get(toVersion);
|
||||
Object defaultValue = setting.getDefaultValue();
|
||||
upgradedSettings.put(settingName, defaultValue);
|
||||
|
||||
|
@ -140,8 +151,9 @@ public class Settings {
|
|||
}
|
||||
|
||||
// Handle removed settings
|
||||
Entry<Integer, SettingsDescription> lastEntry = versionedSettings.lastEntry();
|
||||
if (lastEntry.getKey().intValue() == toVersion && lastEntry.getValue() == null) {
|
||||
Integer highestVersion = versionedSettings.lastKey();
|
||||
if (highestVersion.intValue() == toVersion &&
|
||||
versionedSettings.get(highestVersion) == null) {
|
||||
upgradedSettings.remove(settingName);
|
||||
if (deletedSettings == null) {
|
||||
deletedSettings = new HashSet<String>();
|
||||
|
@ -179,8 +191,10 @@ public class Settings {
|
|||
String settingName = setting.getKey();
|
||||
Object internalValue = setting.getValue();
|
||||
|
||||
SettingsDescription settingDesc =
|
||||
settingDescriptions.get(settingName).lastEntry().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);
|
||||
|
|
|
@ -172,7 +172,9 @@ public class SettingsExporter {
|
|||
|
||||
String key = versionedSetting.getKey();
|
||||
String valueString = (String) prefs.get(key);
|
||||
SettingsDescription setting = versionedSetting.getValue().lastEntry().getValue();
|
||||
TreeMap<Integer, SettingsDescription> versions = versionedSetting.getValue();
|
||||
Integer highestVersion = versions.lastKey();
|
||||
SettingsDescription setting = versions.get(highestVersion);
|
||||
if (setting == null) {
|
||||
// Setting was removed.
|
||||
continue;
|
||||
|
@ -322,7 +324,8 @@ public class SettingsExporter {
|
|||
AccountSettings.SETTINGS.get(keyPart);
|
||||
|
||||
if (versionedSetting != null) {
|
||||
SettingsDescription setting = versionedSetting.lastEntry().getValue();
|
||||
Integer highestVersion = versionedSetting.lastKey();
|
||||
SettingsDescription setting = versionedSetting.get(highestVersion);
|
||||
|
||||
if (setting != null) {
|
||||
// Only export account settings that can be found in AccountSettings.SETTINGS
|
||||
|
@ -416,7 +419,8 @@ public class SettingsExporter {
|
|||
IdentitySettings.SETTINGS.get(identityKey);
|
||||
|
||||
if (versionedSetting != null) {
|
||||
SettingsDescription setting = versionedSetting.lastEntry().getValue();
|
||||
Integer highestVersion = versionedSetting.lastKey();
|
||||
SettingsDescription setting = versionedSetting.get(highestVersion);
|
||||
|
||||
if (setting != null) {
|
||||
// Only write settings that have an entry in IdentitySettings.SETTINGS
|
||||
|
@ -467,7 +471,8 @@ public class SettingsExporter {
|
|||
FolderSettings.SETTINGS.get(folderKey);
|
||||
|
||||
if (versionedSetting != null) {
|
||||
SettingsDescription setting = versionedSetting.lastEntry().getValue();
|
||||
Integer highestVersion = versionedSetting.lastKey();
|
||||
SettingsDescription setting = versionedSetting.get(highestVersion);
|
||||
|
||||
if (setting != null) {
|
||||
// Only write settings that have an entry in FolderSettings.SETTINGS
|
||||
|
|
Loading…
Reference in a new issue