From cbbd0bc4057cb660fb1570d46419e811b9755f62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Veres-Szentkir=C3=A1lyi?= Date: Sat, 15 Feb 2014 23:47:56 +0100 Subject: [PATCH] use more idiomatic String.isEmpty() instead of comparing length to 0 --- src/com/fsck/k9/activity/AccountList.java | 2 +- src/com/fsck/k9/activity/Accounts.java | 2 +- src/com/fsck/k9/activity/ChooseIdentity.java | 2 +- src/com/fsck/k9/activity/LauncherShortcuts.java | 2 +- src/com/fsck/k9/helper/DomainNameChecker.java | 8 ++++---- src/com/fsck/k9/helper/StringUtils.java | 2 +- src/com/fsck/k9/mail/internet/DecoderUtil.java | 2 +- src/com/fsck/k9/mail/internet/MimeUtility.java | 6 +++--- src/com/fsck/k9/preferences/SettingsImporter.java | 4 ++-- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/com/fsck/k9/activity/AccountList.java b/src/com/fsck/k9/activity/AccountList.java index 10ef10e7e..d5f29b32e 100644 --- a/src/com/fsck/k9/activity/AccountList.java +++ b/src/com/fsck/k9/activity/AccountList.java @@ -137,7 +137,7 @@ public abstract class AccountList extends K9ListActivity implements OnItemClickL holder.email.setText(account.getEmail()); } - if (description == null || description.length() == 0) { + if (description == null || description.isEmpty()) { description = account.getEmail(); } diff --git a/src/com/fsck/k9/activity/Accounts.java b/src/com/fsck/k9/activity/Accounts.java index 9601d883e..16fac193c 100644 --- a/src/com/fsck/k9/activity/Accounts.java +++ b/src/com/fsck/k9/activity/Accounts.java @@ -1735,7 +1735,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener { } String description = account.getDescription(); - if (description == null || description.length() == 0) { + if (description == null || description.isEmpty()) { description = account.getEmail(); } diff --git a/src/com/fsck/k9/activity/ChooseIdentity.java b/src/com/fsck/k9/activity/ChooseIdentity.java index 57e852275..6795ea0b9 100644 --- a/src/com/fsck/k9/activity/ChooseIdentity.java +++ b/src/com/fsck/k9/activity/ChooseIdentity.java @@ -59,7 +59,7 @@ public class ChooseIdentity extends K9ListActivity { identities = mAccount.getIdentities(); for (Identity identity : identities) { String description = identity.getDescription(); - if (description == null || description.trim().length() == 0) { + if (description == null || description.trim().isEmpty()) { description = getString(R.string.message_view_from_format, identity.getName(), identity.getEmail()); } adapter.add(description); diff --git a/src/com/fsck/k9/activity/LauncherShortcuts.java b/src/com/fsck/k9/activity/LauncherShortcuts.java index 427e39dbf..563505896 100644 --- a/src/com/fsck/k9/activity/LauncherShortcuts.java +++ b/src/com/fsck/k9/activity/LauncherShortcuts.java @@ -40,7 +40,7 @@ public class LauncherShortcuts extends AccountList { Intent intent = new Intent(); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); String description = account.getDescription(); - if (description == null || description.length() == 0) { + if (description == null || description.isEmpty()) { description = account.getEmail(); } intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, description); diff --git a/src/com/fsck/k9/helper/DomainNameChecker.java b/src/com/fsck/k9/helper/DomainNameChecker.java index fb551977f..360e13e22 100644 --- a/src/com/fsck/k9/helper/DomainNameChecker.java +++ b/src/com/fsck/k9/helper/DomainNameChecker.java @@ -57,7 +57,7 @@ public class DomainNameChecker { */ public static boolean match(X509Certificate certificate, String thisDomain) { if ((certificate == null) || (thisDomain == null) - || (thisDomain.length() == 0)) { + || thisDomain.isEmpty()) { return false; } @@ -73,7 +73,7 @@ public class DomainNameChecker { * @return True iff the domain name is specified as an IP address */ private static boolean isIpAddress(String domain) { - if ((domain == null) || (domain.length() == 0)) { + if ((domain == null) || domain.isEmpty()) { return false; } @@ -210,8 +210,8 @@ public class DomainNameChecker { + thatDomain); } - if ((thisDomain == null) || (thisDomain.length() == 0) - || (thatDomain == null) || (thatDomain.length() == 0)) { + if ((thisDomain == null) || thisDomain.isEmpty() + || (thatDomain == null) || thatDomain.isEmpty()) { return false; } diff --git a/src/com/fsck/k9/helper/StringUtils.java b/src/com/fsck/k9/helper/StringUtils.java index 8ffc06a9a..2567a294d 100644 --- a/src/com/fsck/k9/helper/StringUtils.java +++ b/src/com/fsck/k9/helper/StringUtils.java @@ -3,7 +3,7 @@ package com.fsck.k9.helper; public final class StringUtils { public static boolean isNullOrEmpty(String string){ - return string == null || string.length() == 0; + return string == null || string.isEmpty(); } public static boolean containsAny(String haystack, String[] needles) { diff --git a/src/com/fsck/k9/mail/internet/DecoderUtil.java b/src/com/fsck/k9/mail/internet/DecoderUtil.java index 28abeed84..5c7d5034f 100644 --- a/src/com/fsck/k9/mail/internet/DecoderUtil.java +++ b/src/com/fsck/k9/mail/internet/DecoderUtil.java @@ -176,7 +176,7 @@ public class DecoderUtil { return null; } - if (encodedText.length() == 0) { + if (encodedText.isEmpty()) { Log.w(K9.LOG_TAG, "Missing encoded text in encoded word: '" + body.substring(begin, end) + "'"); return null; } diff --git a/src/com/fsck/k9/mail/internet/MimeUtility.java b/src/com/fsck/k9/mail/internet/MimeUtility.java index a43efff21..c97e25df6 100644 --- a/src/com/fsck/k9/mail/internet/MimeUtility.java +++ b/src/com/fsck/k9/mail/internet/MimeUtility.java @@ -1059,7 +1059,7 @@ public class MimeUtility { in.read(buf, 0, buf.length); String str = new String(buf, "US-ASCII"); - if (str.length() == 0) { + if (str.isEmpty()) { return ""; } Pattern p = Pattern.compile("", Pattern.CASE_INSENSITIVE); @@ -3426,9 +3426,9 @@ public class MimeUtility { BodyPart bodyPart = multipart.getBodyPart(i); String bodyText = getTextFromPart(bodyPart); if (bodyText != null) { - if (text.length() == 0 && bodyPart.isMimeType("text/plain")) { + if (text.isEmpty() && bodyPart.isMimeType("text/plain")) { text = bodyText; - } else if (html.length() == 0 && bodyPart.isMimeType("text/html")) { + } else if (html.isEmpty() && bodyPart.isMimeType("text/html")) { html = bodyText; } } diff --git a/src/com/fsck/k9/preferences/SettingsImporter.java b/src/com/fsck/k9/preferences/SettingsImporter.java index a3a26d65e..c9fd6557c 100644 --- a/src/com/fsck/k9/preferences/SettingsImporter.java +++ b/src/com/fsck/k9/preferences/SettingsImporter.java @@ -380,7 +380,7 @@ public class SettingsImporter { // Mark account as disabled if the settings file didn't contain a password boolean createAccountDisabled = (incoming.password == null || - incoming.password.length() == 0); + 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 @@ -394,7 +394,7 @@ public class SettingsImporter { putString(editor, accountKeyPrefix + Account.TRANSPORT_URI_KEY, Utility.base64Encode(transportUri)); // Mark account as disabled if the settings file didn't contain a password - if (outgoing.password == null || outgoing.password.length() == 0) { + if (outgoing.password == null || outgoing.password.isEmpty()) { createAccountDisabled = true; } }