1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-30 13:12:25 -05:00

use more idiomatic String.isEmpty() instead of comparing length to 0

This commit is contained in:
András Veres-Szentkirályi 2014-02-15 23:47:56 +01:00
parent df75853c64
commit cbbd0bc405
9 changed files with 15 additions and 15 deletions

View File

@ -137,7 +137,7 @@ public abstract class AccountList extends K9ListActivity implements OnItemClickL
holder.email.setText(account.getEmail()); holder.email.setText(account.getEmail());
} }
if (description == null || description.length() == 0) { if (description == null || description.isEmpty()) {
description = account.getEmail(); description = account.getEmail();
} }

View File

@ -1735,7 +1735,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
} }
String description = account.getDescription(); String description = account.getDescription();
if (description == null || description.length() == 0) { if (description == null || description.isEmpty()) {
description = account.getEmail(); description = account.getEmail();
} }

View File

@ -59,7 +59,7 @@ public class ChooseIdentity extends K9ListActivity {
identities = mAccount.getIdentities(); identities = mAccount.getIdentities();
for (Identity identity : identities) { for (Identity identity : identities) {
String description = identity.getDescription(); 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()); description = getString(R.string.message_view_from_format, identity.getName(), identity.getEmail());
} }
adapter.add(description); adapter.add(description);

View File

@ -40,7 +40,7 @@ public class LauncherShortcuts extends AccountList {
Intent intent = new Intent(); Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
String description = account.getDescription(); String description = account.getDescription();
if (description == null || description.length() == 0) { if (description == null || description.isEmpty()) {
description = account.getEmail(); description = account.getEmail();
} }
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, description); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, description);

View File

@ -57,7 +57,7 @@ public class DomainNameChecker {
*/ */
public static boolean match(X509Certificate certificate, String thisDomain) { public static boolean match(X509Certificate certificate, String thisDomain) {
if ((certificate == null) || (thisDomain == null) if ((certificate == null) || (thisDomain == null)
|| (thisDomain.length() == 0)) { || thisDomain.isEmpty()) {
return false; return false;
} }
@ -73,7 +73,7 @@ public class DomainNameChecker {
* @return True iff the domain name is specified as an IP address * @return True iff the domain name is specified as an IP address
*/ */
private static boolean isIpAddress(String domain) { private static boolean isIpAddress(String domain) {
if ((domain == null) || (domain.length() == 0)) { if ((domain == null) || domain.isEmpty()) {
return false; return false;
} }
@ -210,8 +210,8 @@ public class DomainNameChecker {
+ thatDomain); + thatDomain);
} }
if ((thisDomain == null) || (thisDomain.length() == 0) if ((thisDomain == null) || thisDomain.isEmpty()
|| (thatDomain == null) || (thatDomain.length() == 0)) { || (thatDomain == null) || thatDomain.isEmpty()) {
return false; return false;
} }

View File

@ -3,7 +3,7 @@ package com.fsck.k9.helper;
public final class StringUtils { public final class StringUtils {
public static boolean isNullOrEmpty(String string){ 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) { public static boolean containsAny(String haystack, String[] needles) {

View File

@ -176,7 +176,7 @@ public class DecoderUtil {
return null; return null;
} }
if (encodedText.length() == 0) { if (encodedText.isEmpty()) {
Log.w(K9.LOG_TAG, "Missing encoded text in encoded word: '" + body.substring(begin, end) + "'"); Log.w(K9.LOG_TAG, "Missing encoded text in encoded word: '" + body.substring(begin, end) + "'");
return null; return null;
} }

View File

@ -1059,7 +1059,7 @@ public class MimeUtility {
in.read(buf, 0, buf.length); in.read(buf, 0, buf.length);
String str = new String(buf, "US-ASCII"); String str = new String(buf, "US-ASCII");
if (str.length() == 0) { if (str.isEmpty()) {
return ""; return "";
} }
Pattern p = Pattern.compile("<meta http-equiv=\"?Content-Type\"? content=\"text/html; charset=(.+?)\">", Pattern.CASE_INSENSITIVE); Pattern p = Pattern.compile("<meta http-equiv=\"?Content-Type\"? content=\"text/html; charset=(.+?)\">", Pattern.CASE_INSENSITIVE);
@ -3426,9 +3426,9 @@ public class MimeUtility {
BodyPart bodyPart = multipart.getBodyPart(i); BodyPart bodyPart = multipart.getBodyPart(i);
String bodyText = getTextFromPart(bodyPart); String bodyText = getTextFromPart(bodyPart);
if (bodyText != null) { if (bodyText != null) {
if (text.length() == 0 && bodyPart.isMimeType("text/plain")) { if (text.isEmpty() && bodyPart.isMimeType("text/plain")) {
text = bodyText; text = bodyText;
} else if (html.length() == 0 && bodyPart.isMimeType("text/html")) { } else if (html.isEmpty() && bodyPart.isMimeType("text/html")) {
html = bodyText; html = bodyText;
} }
} }

View File

@ -380,7 +380,7 @@ public class SettingsImporter {
// Mark account as disabled if the settings file didn't contain a password // Mark account as disabled if the settings file didn't contain a password
boolean createAccountDisabled = (incoming.password == null || boolean createAccountDisabled = (incoming.password == null ||
incoming.password.length() == 0); incoming.password.isEmpty());
if (account.outgoing == null && !WebDavStore.STORE_TYPE.equals(account.incoming.type)) { if (account.outgoing == null && !WebDavStore.STORE_TYPE.equals(account.incoming.type)) {
// All account types except WebDAV need to provide outgoing server settings // 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)); putString(editor, accountKeyPrefix + Account.TRANSPORT_URI_KEY, Utility.base64Encode(transportUri));
// Mark account as disabled if the settings file didn't contain a password // 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; createAccountDisabled = true;
} }
} }