From f7fb0cca4187270e20bc637962ac4cdb25c3f5d8 Mon Sep 17 00:00:00 2001 From: Joe Steele Date: Mon, 18 Aug 2014 18:12:39 -0400 Subject: [PATCH] Compare Enum types with ==, != Per comments in PR #473 https://github.com/k9mail/k-9/pull/474#commitcomment-7416979 https://github.com/k9mail/k-9/pull/474#commitcomment-7416999 --- src/com/fsck/k9/Account.java | 4 ++-- src/com/fsck/k9/activity/Accounts.java | 6 ++---- .../setup/AccountSetupCheckSettings.java | 4 ++-- .../activity/setup/AccountSetupIncoming.java | 16 ++++++++-------- .../activity/setup/AccountSetupOutgoing.java | 18 +++++++++--------- .../k9/controller/MessagingController.java | 2 +- src/com/fsck/k9/mail/store/ImapStore.java | 4 ++-- src/com/fsck/k9/mail/store/Pop3Store.java | 4 ++-- .../fsck/k9/mail/transport/SmtpTransport.java | 7 +++---- .../fsck/k9/preferences/SettingsImporter.java | 19 ++++++++----------- 10 files changed, 39 insertions(+), 45 deletions(-) diff --git a/src/com/fsck/k9/Account.java b/src/com/fsck/k9/Account.java index 40b4ebaef..53e05b3e1 100644 --- a/src/com/fsck/k9/Account.java +++ b/src/com/fsck/k9/Account.java @@ -1892,7 +1892,7 @@ public class Account implements BaseAccount { public void addCertificate(CheckDirection direction, X509Certificate certificate) throws CertificateException { Uri uri; - if (direction.equals(CheckDirection.INCOMING)) { + if (direction == CheckDirection.INCOMING) { uri = Uri.parse(getStoreUri()); } else { uri = Uri.parse(getTransportUri()); @@ -1909,7 +1909,7 @@ public class Account implements BaseAccount { public void deleteCertificate(String newHost, int newPort, CheckDirection direction) { Uri uri; - if (direction.equals(CheckDirection.INCOMING)) { + if (direction == CheckDirection.INCOMING) { uri = Uri.parse(getStoreUri()); } else { uri = Uri.parse(getTransportUri()); diff --git a/src/com/fsck/k9/activity/Accounts.java b/src/com/fsck/k9/activity/Accounts.java index 8ceed741e..76cfe3abb 100644 --- a/src/com/fsck/k9/activity/Accounts.java +++ b/src/com/fsck/k9/activity/Accounts.java @@ -779,16 +779,14 @@ public class Accounts extends K9ListActivity implements OnItemClickListener { * this account type. Also don't ask when the username is missing. * Also don't ask when the AuthType is EXTERNAL. */ - boolean configureOutgoingServer = !AuthType.EXTERNAL - .equals(outgoing.authenticationType) + boolean configureOutgoingServer = AuthType.EXTERNAL != outgoing.authenticationType && !WebDavStore.STORE_TYPE.equals(outgoing.type) && outgoing.username != null && !outgoing.username.isEmpty() && (outgoing.password == null || outgoing.password .isEmpty()); - boolean configureIncomingServer = !AuthType.EXTERNAL - .equals(incoming.authenticationType) + boolean configureIncomingServer = AuthType.EXTERNAL != incoming.authenticationType && (incoming.password == null || incoming.password .isEmpty()); diff --git a/src/com/fsck/k9/activity/setup/AccountSetupCheckSettings.java b/src/com/fsck/k9/activity/setup/AccountSetupCheckSettings.java index ae9556fc8..9eefc98c9 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupCheckSettings.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupCheckSettings.java @@ -114,7 +114,7 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList ctrl.clearCertificateErrorNotifications(AccountSetupCheckSettings.this, mAccount, mDirection); - if (mDirection.equals(CheckDirection.INCOMING)) { + if (mDirection == CheckDirection.INCOMING) { store = mAccount.getRemoteStore(); if (store instanceof WebDavStore) { @@ -137,7 +137,7 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList finish(); return; } - if (mDirection.equals(CheckDirection.OUTGOING)) { + if (mDirection == CheckDirection.OUTGOING) { if (!(mAccount.getRemoteStore() instanceof WebDavStore)) { setMessage(R.string.account_setup_check_settings_check_outgoing_msg); } diff --git a/src/com/fsck/k9/activity/setup/AccountSetupIncoming.java b/src/com/fsck/k9/activity/setup/AccountSetupIncoming.java index 1230e114e..f5cfce12c 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupIncoming.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupIncoming.java @@ -354,7 +354,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener AuthType selection = (AuthType) mAuthTypeView.getSelectedItem(); // Have the user select (or confirm) the client certificate - if (AuthType.EXTERNAL.equals(selection)) { + if (AuthType.EXTERNAL == selection) { // This may again invoke validateFields() mClientCertificateSpinner.chooseCertificate(); @@ -400,7 +400,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener */ private void updateViewFromAuthType() { AuthType authType = (AuthType) mAuthTypeView.getSelectedItem(); - boolean isAuthTypeExternal = AuthType.EXTERNAL.equals(authType); + boolean isAuthTypeExternal = (AuthType.EXTERNAL == authType); if (isAuthTypeExternal) { @@ -426,10 +426,10 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener */ private void validateFields() { AuthType authType = (AuthType) mAuthTypeView.getSelectedItem(); - boolean isAuthTypeExternal = AuthType.EXTERNAL.equals(authType); + boolean isAuthTypeExternal = (AuthType.EXTERNAL == authType); ConnectionSecurity connectionSecurity = (ConnectionSecurity) mSecurityTypeView.getSelectedItem(); - boolean hasConnectionSecurity = (!connectionSecurity.equals(ConnectionSecurity.NONE)); + boolean hasConnectionSecurity = (connectionSecurity != ConnectionSecurity.NONE); if (isAuthTypeExternal && !hasConnectionSecurity) { @@ -459,10 +459,10 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener mPortView.addTextChangedListener(validationTextWatcher); authType = (AuthType) mAuthTypeView.getSelectedItem(); - isAuthTypeExternal = AuthType.EXTERNAL.equals(authType); + isAuthTypeExternal = (AuthType.EXTERNAL == authType); connectionSecurity = (ConnectionSecurity) mSecurityTypeView.getSelectedItem(); - hasConnectionSecurity = (!connectionSecurity.equals(ConnectionSecurity.NONE)); + hasConnectionSecurity = (connectionSecurity != ConnectionSecurity.NONE); } else { mCurrentAuthTypeViewPosition = mAuthTypeView.getSelectedItemPosition(); mCurrentSecurityTypeViewPosition = mSecurityTypeView.getSelectedItemPosition(); @@ -552,7 +552,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener String password = null; String clientCertificateAlias = null; AuthType authType = (AuthType) mAuthTypeView.getSelectedItem(); - if (AuthType.EXTERNAL.equals(authType)) { + if (AuthType.EXTERNAL == authType) { clientCertificateAlias = mClientCertificateSpinner.getAlias(); } else { password = mPasswordView.getText().toString(); @@ -586,7 +586,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener String clientCertificateAlias = null; AuthType authType = (AuthType) mAuthTypeView.getSelectedItem(); - if (authType.equals(AuthType.EXTERNAL)) { + if (authType == AuthType.EXTERNAL) { clientCertificateAlias = mClientCertificateSpinner.getAlias(); } else { password = mPasswordView.getText().toString(); diff --git a/src/com/fsck/k9/activity/setup/AccountSetupOutgoing.java b/src/com/fsck/k9/activity/setup/AccountSetupOutgoing.java index a9c32fe09..4cff98fe6 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupOutgoing.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupOutgoing.java @@ -234,8 +234,8 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener, if (mCurrentSecurityTypeViewPosition != position) { updatePortFromSecurityType(); - boolean isInsecure = ConnectionSecurity.NONE.equals(mSecurityTypeView.getSelectedItem()); - boolean isAuthExternal = AuthType.EXTERNAL.equals(mAuthTypeView.getSelectedItem()); + boolean isInsecure = (ConnectionSecurity.NONE == mSecurityTypeView.getSelectedItem()); + boolean isAuthExternal = (AuthType.EXTERNAL == mAuthTypeView.getSelectedItem()); boolean loginNotRequired = !mRequireLoginView.isChecked(); /* @@ -278,7 +278,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener, AuthType selection = (AuthType) mAuthTypeView.getSelectedItem(); // Have the user select (or confirm) the client certificate - if (AuthType.EXTERNAL.equals(selection)) { + if (AuthType.EXTERNAL == selection) { // This may again invoke validateFields() mClientCertificateSpinner.chooseCertificate(); @@ -331,7 +331,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener, */ private void updateViewFromAuthType() { AuthType authType = (AuthType) mAuthTypeView.getSelectedItem(); - boolean isAuthTypeExternal = AuthType.EXTERNAL.equals(authType); + boolean isAuthTypeExternal = (AuthType.EXTERNAL == authType); if (isAuthTypeExternal) { @@ -357,10 +357,10 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener, */ private void validateFields() { AuthType authType = (AuthType) mAuthTypeView.getSelectedItem(); - boolean isAuthTypeExternal = AuthType.EXTERNAL.equals(authType); + boolean isAuthTypeExternal = (AuthType.EXTERNAL == authType); ConnectionSecurity connectionSecurity = (ConnectionSecurity) mSecurityTypeView.getSelectedItem(); - boolean hasConnectionSecurity = (!connectionSecurity.equals(ConnectionSecurity.NONE)); + boolean hasConnectionSecurity = (connectionSecurity != ConnectionSecurity.NONE); if (isAuthTypeExternal && !hasConnectionSecurity) { @@ -390,10 +390,10 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener, mPortView.addTextChangedListener(validationTextWatcher); authType = (AuthType) mAuthTypeView.getSelectedItem(); - isAuthTypeExternal = AuthType.EXTERNAL.equals(authType); + isAuthTypeExternal = (AuthType.EXTERNAL == authType); connectionSecurity = (ConnectionSecurity) mSecurityTypeView.getSelectedItem(); - hasConnectionSecurity = (!connectionSecurity.equals(ConnectionSecurity.NONE)); + hasConnectionSecurity = (connectionSecurity != ConnectionSecurity.NONE); } else { mCurrentAuthTypeViewPosition = mAuthTypeView.getSelectedItemPosition(); mCurrentSecurityTypeViewPosition = mSecurityTypeView.getSelectedItemPosition(); @@ -482,7 +482,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener, username = mUsernameView.getText().toString(); authType = (AuthType) mAuthTypeView.getSelectedItem(); - if (AuthType.EXTERNAL.equals(authType)) { + if (AuthType.EXTERNAL == authType) { clientCertificateAlias = mClientCertificateSpinner.getAlias(); } else { password = mPasswordView.getText().toString(); diff --git a/src/com/fsck/k9/controller/MessagingController.java b/src/com/fsck/k9/controller/MessagingController.java index bbdc64ac9..31337a251 100644 --- a/src/com/fsck/k9/controller/MessagingController.java +++ b/src/com/fsck/k9/controller/MessagingController.java @@ -2673,7 +2673,7 @@ public class MessagingController implements Runnable { final NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); - if (direction.equals(CheckDirection.INCOMING)) { + if (direction == CheckDirection.INCOMING) { nm.cancel(null, K9.CERTIFICATE_EXCEPTION_NOTIFICATION_INCOMING + account.getAccountNumber()); } else { nm.cancel(null, K9.CERTIFICATE_EXCEPTION_NOTIFICATION_OUTGOING + account.getAccountNumber()); diff --git a/src/com/fsck/k9/mail/store/ImapStore.java b/src/com/fsck/k9/mail/store/ImapStore.java index f61d61f8c..5f9dd1079 100644 --- a/src/com/fsck/k9/mail/store/ImapStore.java +++ b/src/com/fsck/k9/mail/store/ImapStore.java @@ -214,7 +214,7 @@ public class ImapStore extends Store { authenticationType = AuthType.valueOf(userInfoParts[0]); username = URLDecoder.decode(userInfoParts[1], "UTF-8"); - if (AuthType.EXTERNAL.equals(authenticationType)) { + if (AuthType.EXTERNAL == authenticationType) { clientCertificateAlias = URLDecoder.decode(userInfoParts[2], "UTF-8"); } else { password = URLDecoder.decode(userInfoParts[2], "UTF-8"); @@ -290,7 +290,7 @@ public class ImapStore extends Store { AuthType authType = server.authenticationType; String userInfo; - if (authType.equals(AuthType.EXTERNAL)) { + if (authType == AuthType.EXTERNAL) { userInfo = authType.name() + ":" + userEnc + ":" + clientCertificateAliasEnc; } else { userInfo = authType.name() + ":" + userEnc + ":" + passwordEnc; diff --git a/src/com/fsck/k9/mail/store/Pop3Store.java b/src/com/fsck/k9/mail/store/Pop3Store.java index 5a5d232db..a66bca2ac 100644 --- a/src/com/fsck/k9/mail/store/Pop3Store.java +++ b/src/com/fsck/k9/mail/store/Pop3Store.java @@ -128,7 +128,7 @@ public class Pop3Store extends Store { } username = URLDecoder.decode(userInfoParts[userIndex], "UTF-8"); if (userInfoParts.length > passwordIndex) { - if (authType.equals(AuthType.EXTERNAL)) { + if (authType == AuthType.EXTERNAL) { clientCertificateAlias = URLDecoder.decode(userInfoParts[passwordIndex], "UTF-8"); } else { password = URLDecoder.decode(userInfoParts[passwordIndex], "UTF-8"); @@ -186,7 +186,7 @@ public class Pop3Store extends Store { AuthType authType = server.authenticationType; String userInfo; - if (AuthType.EXTERNAL.equals(authType)) { + if (AuthType.EXTERNAL == authType) { userInfo = authType.name() + ":" + userEnc + ":" + clientCertificateAliasEnc; } else { userInfo = authType.name() + ":" + userEnc + ":" + passwordEnc; diff --git a/src/com/fsck/k9/mail/transport/SmtpTransport.java b/src/com/fsck/k9/mail/transport/SmtpTransport.java index 76ac71cf3..706be3897 100644 --- a/src/com/fsck/k9/mail/transport/SmtpTransport.java +++ b/src/com/fsck/k9/mail/transport/SmtpTransport.java @@ -105,7 +105,7 @@ public class SmtpTransport extends Transport { // NOTE: In SmptTransport URIs, the authType comes last! authType = AuthType.valueOf(userInfoParts[2]); username = URLDecoder.decode(userInfoParts[0], "UTF-8"); - if (authType.equals(AuthType.EXTERNAL)) { + if (authType == AuthType.EXTERNAL) { clientCertificateAlias = URLDecoder.decode(userInfoParts[1], "UTF-8"); } else { password = URLDecoder.decode(userInfoParts[1], "UTF-8"); @@ -166,7 +166,7 @@ public class SmtpTransport extends Transport { AuthType authType = server.authenticationType; // NOTE: authType is append at last item, in contrast to ImapStore and Pop3Store! if (authType != null) { - if (AuthType.EXTERNAL.equals(authType)) { + if (AuthType.EXTERNAL == authType) { userInfo = userEnc + ":" + clientCertificateAliasEnc + ":" + authType.name(); } else { userInfo = userEnc + ":" + passwordEnc + ":" + authType.name(); @@ -326,8 +326,7 @@ public class SmtpTransport extends Transport { if (mUsername != null && mUsername.length() > 0 - && (mPassword != null && mPassword.length() > 0 || AuthType.EXTERNAL - .equals(mAuthType))) { + && (mPassword != null && mPassword.length() > 0 || AuthType.EXTERNAL == mAuthType)) { switch (mAuthType) { diff --git a/src/com/fsck/k9/preferences/SettingsImporter.java b/src/com/fsck/k9/preferences/SettingsImporter.java index a4a4802e1..c42995607 100644 --- a/src/com/fsck/k9/preferences/SettingsImporter.java +++ b/src/com/fsck/k9/preferences/SettingsImporter.java @@ -381,9 +381,8 @@ public class SettingsImporter { // Mark account as disabled if the AuthType isn't EXTERNAL and the // settings file didn't contain a password - boolean createAccountDisabled = !AuthType.EXTERNAL - .equals(incoming.authenticationType) - && (incoming.password == null || incoming.password.isEmpty()); + boolean createAccountDisabled = AuthType.EXTERNAL != incoming.authenticationType && + (incoming.password == null || incoming.password.isEmpty()); if (account.outgoing == null && !WebDavStore.STORE_TYPE.equals(account.incoming.type)) { // All account types except WebDAV need to provide outgoing server settings @@ -403,14 +402,12 @@ public class SettingsImporter { * outgoing servers are identical for this account type. Nor is a * password required if the AuthType is EXTERNAL. */ - if (!AuthType.EXTERNAL.equals(outgoing.authenticationType) - && !WebDavStore.STORE_TYPE.equals(outgoing.type) - && outgoing.username != null - && !outgoing.username.isEmpty() - && (outgoing.password == null || outgoing.password - .isEmpty())) { - createAccountDisabled = true; - } + boolean outgoingPasswordNeeded = AuthType.EXTERNAL != outgoing.authenticationType && + !WebDavStore.STORE_TYPE.equals(outgoing.type) && + outgoing.username != null && + !outgoing.username.isEmpty() && + (outgoing.password == null || outgoing.password.isEmpty()); + createAccountDisabled = outgoingPasswordNeeded || createAccountDisabled; } // Write key to mark account as disabled if necessary