From 18cefedf32403e8352bfa5b7acaaddf9bef08b33 Mon Sep 17 00:00:00 2001 From: cketti Date: Sat, 26 Mar 2011 06:59:45 +0100 Subject: [PATCH] Get rid of the STORAGE_VERSION enum in StorageVersioning --- src/com/fsck/k9/activity/ExportHelper.java | 2 +- .../k9/preferences/StorageVersioning.java | 68 ++++++------------- 2 files changed, 21 insertions(+), 49 deletions(-) diff --git a/src/com/fsck/k9/activity/ExportHelper.java b/src/com/fsck/k9/activity/ExportHelper.java index 932f64b1a..fe8557dd0 100644 --- a/src/com/fsck/k9/activity/ExportHelper.java +++ b/src/com/fsck/k9/activity/ExportHelper.java @@ -12,7 +12,7 @@ import com.fsck.k9.preferences.StorageVersioning; public class ExportHelper { public static void exportSettings(final Activity activity, final HashSet accountUuids, final ExportListener listener) { // Once there are more versions, build a UI to select which one to use. For now, use the encrypted/encoded version: - String version = StorageVersioning.STORAGE_VERSION.VERSION1.getVersionString(); + String version = StorageVersioning.ENCRYPTED_XML_FILE; AsyncUIProcessor.getInstance(activity.getApplication()).exportSettings(activity, version, accountUuids, new ExportListener() { @Override diff --git a/src/com/fsck/k9/preferences/StorageVersioning.java b/src/com/fsck/k9/preferences/StorageVersioning.java index 53604070a..95080c1d2 100644 --- a/src/com/fsck/k9/preferences/StorageVersioning.java +++ b/src/com/fsck/k9/preferences/StorageVersioning.java @@ -5,74 +5,46 @@ import java.util.Map; public class StorageVersioning { - public enum STORAGE_VERSION { - VERSION1(StorageImporterVersion1.class, StorageExporterVersion1.class, true, STORAGE_VERSION_1); - - private Class importerClass; - private Class exporterClass; - private boolean needsKey; - private String versionString; - - - private STORAGE_VERSION(Class imclass, Class exclass, boolean nk, String vs) { - importerClass = imclass; - exporterClass = exclass; - needsKey = nk; - versionString = vs; - - } - public Class getImporterClass() { - return importerClass; - } - public IStorageImporter createImporter() throws InstantiationException, IllegalAccessException { - IStorageImporter storageImporter = importerClass.newInstance(); - return storageImporter; - } - public Class getExporterClass() { - return exporterClass; - } - public IStorageExporter createExporter() throws InstantiationException, IllegalAccessException { - IStorageExporter storageExporter = exporterClass.newInstance(); - return storageExporter; - } - public boolean needsKey() { - return needsKey; - } - public String getVersionString() { - return versionString; - } - } - // Never, ever re-use these numbers! - private static final String STORAGE_VERSION_1 = "1"; + public static final String ENCRYPTED_XML_FILE = "1"; - public static Map versionMap = new HashMap(); + public static Map versionMap = new HashMap(); static { - versionMap.put(STORAGE_VERSION.VERSION1.getVersionString(), STORAGE_VERSION.VERSION1); + versionMap.put(ENCRYPTED_XML_FILE, new StorageVersioning(StorageImporterVersion1.class, StorageExporterVersion1.class, true)); } public static IStorageImporter createImporter(String version) throws InstantiationException, IllegalAccessException { - STORAGE_VERSION storageVersion = versionMap.get(version); + StorageVersioning storageVersion = versionMap.get(version); if (storageVersion == null) { return null; } - return storageVersion.createImporter(); + return storageVersion.importerClass.newInstance(); } public static IStorageExporter createExporter(String version) throws InstantiationException, IllegalAccessException { - STORAGE_VERSION storageVersion = versionMap.get(version); + StorageVersioning storageVersion = versionMap.get(version); if (storageVersion == null) { return null; } - return storageVersion.createExporter(); + return storageVersion.exporterClass.newInstance(); } - public Boolean needsKey(String version) { - STORAGE_VERSION storageVersion = versionMap.get(version); + public static Boolean needsKey(String version) { + StorageVersioning storageVersion = versionMap.get(version); if (storageVersion == null) { return null; } - return storageVersion.needsKey(); + return storageVersion.needsKey; } + + private final Class importerClass; + private final Class exporterClass; + private final boolean needsKey; + + private StorageVersioning(Class imclass, Class exclass, boolean nk) { + importerClass = imclass; + exporterClass = exclass; + needsKey = nk; + } }