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.
This commit is contained in:
cketti 2015-03-16 13:26:13 +01:00
parent f733cc38ba
commit 5f14e3b4e1
1 changed files with 16 additions and 12 deletions

View File

@ -5,9 +5,6 @@ import com.fsck.k9.Account.DeletePolicy;
import com.fsck.k9.mail.ConnectionSecurity; import com.fsck.k9.mail.ConnectionSecurity;
import com.fsck.k9.mail.ServerSettings.Type; import com.fsck.k9.mail.ServerSettings.Type;
import java.util.HashMap;
import java.util.Map;
/** /**
* Deals with logic surrounding account creation. * Deals with logic surrounding account creation.
@ -16,16 +13,23 @@ import java.util.Map;
*/ */
public class AccountCreator { public class AccountCreator {
private static Map<Type, DeletePolicy> defaults = new HashMap<Type, DeletePolicy>();
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) { 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) { public static int getDefaultPort(ConnectionSecurity securityType, Type storeType) {