From 5f14e3b4e15fc873f346ce7ff9e538346aeac179 Mon Sep 17 00:00:00 2001 From: cketti Date: Mon, 16 Mar 2015 13:26:13 +0100 Subject: [PATCH] Use switch statement inside calculateDefaultDeletePolicy() With this - at least in theory - the JIT compiler can produce better code than is possible with the static HashMap. --- .../com/fsck/k9/account/AccountCreator.java | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/k9mail/src/main/java/com/fsck/k9/account/AccountCreator.java b/k9mail/src/main/java/com/fsck/k9/account/AccountCreator.java index fddb456a8..6a8f9ead7 100644 --- a/k9mail/src/main/java/com/fsck/k9/account/AccountCreator.java +++ b/k9mail/src/main/java/com/fsck/k9/account/AccountCreator.java @@ -5,9 +5,6 @@ import com.fsck.k9.Account.DeletePolicy; import com.fsck.k9.mail.ConnectionSecurity; import com.fsck.k9.mail.ServerSettings.Type; -import java.util.HashMap; -import java.util.Map; - /** * Deals with logic surrounding account creation. @@ -16,16 +13,23 @@ import java.util.Map; */ public class AccountCreator { - private static Map defaults = new HashMap(); - - static { - defaults.put(Type.IMAP, DeletePolicy.ON_DELETE); - defaults.put(Type.POP3, DeletePolicy.NEVER); - defaults.put(Type.WebDAV, DeletePolicy.ON_DELETE); - } - public static DeletePolicy calculateDefaultDeletePolicy(Type type) { - return defaults.get(type); + switch (type) { + case IMAP: { + return DeletePolicy.ON_DELETE; + } + case POP3: { + return DeletePolicy.NEVER; + } + case WebDAV: { + return DeletePolicy.ON_DELETE; + } + case SMTP: { + throw new IllegalStateException("Delete policy doesn't apply to SMTP"); + } + } + + throw new AssertionError("Unhandled case: " + type); } public static int getDefaultPort(ConnectionSecurity securityType, Type storeType) {