1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-23 09:52:16 -05:00

Merge pull request #89 from andrewgaul/is-empty

Prefer Collection.isEmpty over size
This commit is contained in:
Andrew Chen 2011-11-03 06:34:15 -07:00
commit 64b299ebec
13 changed files with 32 additions and 32 deletions

View File

@ -1135,7 +1135,7 @@ public class Account implements BaseAccount {
ident++; ident++;
} while (gotOne); } while (gotOne);
if (newIdentities.size() == 0) { if (newIdentities.isEmpty()) {
String name = prefs.getString(mUuid + ".name", null); String name = prefs.getString(mUuid + ".name", null);
String email = prefs.getString(mUuid + ".email", null); String email = prefs.getString(mUuid + ".email", null);
boolean signatureUse = prefs.getBoolean(mUuid + ".signatureUse", true); boolean signatureUse = prefs.getBoolean(mUuid + ".signatureUse", true);

View File

@ -154,7 +154,7 @@ public class Preferences {
if (defaultAccount == null) { if (defaultAccount == null) {
Collection<Account> accounts = getAvailableAccounts(); Collection<Account> accounts = getAvailableAccounts();
if (accounts.size() > 0) { if (!accounts.isEmpty()) {
defaultAccount = accounts.iterator().next(); defaultAccount = accounts.iterator().next();
setDefaultAccount(defaultAccount); setDefaultAccount(defaultAccount);
} }

View File

@ -388,7 +388,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
mAdapter = new AccountsAdapter(newAccounts.toArray(EMPTY_BASE_ACCOUNT_ARRAY)); mAdapter = new AccountsAdapter(newAccounts.toArray(EMPTY_BASE_ACCOUNT_ARRAY));
getListView().setAdapter(mAdapter); getListView().setAdapter(mAdapter);
if (newAccounts.size() > 0) { if (!newAccounts.isEmpty()) {
mHandler.progress(Window.PROGRESS_START); mHandler.progress(Window.PROGRESS_START);
} }
pendingWork.clear(); pendingWork.clear();

View File

@ -2567,13 +2567,13 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
// Read subject from the "subject" parameter. // Read subject from the "subject" parameter.
List<String> subject = uri.getQueryParameters("subject"); List<String> subject = uri.getQueryParameters("subject");
if (subject.size() > 0) { if (!subject.isEmpty()) {
mSubjectView.setText(subject.get(0)); mSubjectView.setText(subject.get(0));
} }
// Read message body from the "body" parameter. // Read message body from the "body" parameter.
List<String> body = uri.getQueryParameters("body"); List<String> body = uri.getQueryParameters("body");
if (body.size() > 0) { if (!body.isEmpty()) {
mMessageContentView.setText(body.get(0)); mMessageContentView.setText(body.get(0));
} }
} }

View File

@ -1977,7 +1977,7 @@ public class MessageList
} }
} }
if (messagesToSearch.size() > 0) { if (!messagesToSearch.isEmpty()) {
mController.searchLocalMessages(mAccountUuids, mFolderNames, messagesToSearch.toArray(EMPTY_MESSAGE_ARRAY), mQueryString, mIntegrate, mQueryFlags, mForbiddenFlags, mController.searchLocalMessages(mAccountUuids, mFolderNames, messagesToSearch.toArray(EMPTY_MESSAGE_ARRAY), mQueryString, mIntegrate, mQueryFlags, mForbiddenFlags,
new MessagingListener() { new MessagingListener() {
@Override @Override
@ -1987,11 +1987,11 @@ public class MessageList
}); });
} }
if (messagesToRemove.size() > 0) { if (!messagesToRemove.isEmpty()) {
removeMessages(messagesToRemove); removeMessages(messagesToRemove);
} }
if (messagesToAdd.size() > 0) { if (!messagesToAdd.isEmpty()) {
mHandler.addMessages(messagesToAdd); mHandler.addMessages(messagesToAdd);
} }

View File

@ -296,7 +296,7 @@ public class MessagingController implements Runnable {
" Command '" + command.description + "' completed"); " Command '" + command.description + "' completed");
for (MessagingListener l : getListeners(command.listener)) { for (MessagingListener l : getListeners(command.listener)) {
l.controllerCommandCompleted(mCommands.size() > 0); l.controllerCommandCompleted(!mCommands.isEmpty());
} }
} }
} catch (Exception e) { } catch (Exception e) {
@ -417,7 +417,7 @@ public class MessagingController implements Runnable {
Folder[] folderArray = localFolders.toArray(EMPTY_FOLDER_ARRAY); Folder[] folderArray = localFolders.toArray(EMPTY_FOLDER_ARRAY);
if (refreshRemote || localFolders.size() == 0) { if (refreshRemote || localFolders.isEmpty()) {
doRefreshRemote(account, listener); doRefreshRemote(account, listener);
return; return;
} }
@ -1225,7 +1225,7 @@ public class MessagingController implements Runnable {
messages.clear(); messages.clear();
final ArrayList<Message> largeMessages = new ArrayList<Message>(); final ArrayList<Message> largeMessages = new ArrayList<Message>();
final ArrayList<Message> smallMessages = new ArrayList<Message>(); final ArrayList<Message> smallMessages = new ArrayList<Message>();
if (unsyncedMessages.size() > 0) { if (!unsyncedMessages.isEmpty()) {
/* /*
* Reverse the order of the messages. Depending on the server this may get us * Reverse the order of the messages. Depending on the server this may get us
@ -1481,7 +1481,7 @@ public class MessagingController implements Runnable {
} }
}); });
if (chunk.size() > 0) { if (!chunk.isEmpty()) {
writeUnsyncedMessages(chunk, localFolder, account, folder); writeUnsyncedMessages(chunk, localFolder, account, folder);
chunk.clear(); chunk.clear();
} }
@ -2227,7 +2227,7 @@ public class MessagingController implements Runnable {
} }
} }
if (messages.size() == 0) { if (messages.isEmpty()) {
return; return;
} }
remoteFolder.setFlags(messages.toArray(EMPTY_MESSAGE_ARRAY), new Flag[] { flag }, newState); remoteFolder.setFlags(messages.toArray(EMPTY_MESSAGE_ARRAY), new Flag[] { flag }, newState);
@ -4230,7 +4230,7 @@ public class MessagingController implements Runnable {
names.add(folder.getName()); names.add(folder.getName());
} }
if (names.size() > 0) { if (!names.isEmpty()) {
PushReceiver receiver = new MessagingControllerPushReceiver(mApplication, account, this); PushReceiver receiver = new MessagingControllerPushReceiver(mApplication, account, this);
int maxPushFolders = account.getMaxPushFolders(); int maxPushFolders = account.getMaxPushFolders();

View File

@ -176,7 +176,7 @@ public class Apg extends CryptoProvider {
activity.getResources().getString(R.string.insufficient_apg_permissions), activity.getResources().getString(R.string.insufficient_apg_permissions),
Toast.LENGTH_LONG).show(); Toast.LENGTH_LONG).show();
} }
if (keyIds.size() > 0) { if (!keyIds.isEmpty()) {
initialKeyIds = new long[keyIds.size()]; initialKeyIds = new long[keyIds.size()];
for (int i = 0, size = keyIds.size(); i < size; ++i) { for (int i = 0, size = keyIds.size(); i < size; ++i) {
initialKeyIds[i] = keyIds.get(i); initialKeyIds[i] = keyIds.get(i);

View File

@ -187,8 +187,8 @@ public abstract class Contacts {
*/ */
public boolean hasContactPicker() { public boolean hasContactPicker() {
if (mHasContactPicker == null) { if (mHasContactPicker == null) {
mHasContactPicker = (mContext.getPackageManager(). mHasContactPicker = !(mContext.getPackageManager().
queryIntentActivities(contactPickerIntent(), 0).size() > 0); queryIntentActivities(contactPickerIntent(), 0).isEmpty());
} }
return mHasContactPicker; return mHasContactPicker;
} }

View File

@ -78,7 +78,7 @@ public class MimeHeader {
values.add(field.value); values.add(field.value);
} }
} }
if (values.size() == 0) { if (values.isEmpty()) {
return null; return null;
} }
return values.toArray(EMPTY_STRING_ARRAY); return values.toArray(EMPTY_STRING_ARRAY);

View File

@ -73,7 +73,7 @@ public class MimeMultipart extends Multipart {
writer.write(mPreamble + "\r\n"); writer.write(mPreamble + "\r\n");
} }
if (mParts.size() == 0) { if (mParts.isEmpty()) {
writer.write("--" + mBoundary + "\r\n"); writer.write("--" + mBoundary + "\r\n");
} }

View File

@ -655,7 +655,7 @@ public class ImapStore extends Store {
if (bracketedObj instanceof ImapList) { if (bracketedObj instanceof ImapList) {
ImapList bracketed = (ImapList)bracketedObj; ImapList bracketed = (ImapList)bracketedObj;
if (bracketed.size() > 0) { if (!bracketed.isEmpty()) {
Object keyObj = bracketed.get(0); Object keyObj = bracketed.get(0);
if (keyObj instanceof String) { if (keyObj instanceof String) {
String key = (String)keyObj; String key = (String)keyObj;
@ -1409,7 +1409,7 @@ public class ImapStore extends Store {
// { // {
// ImapList bracketed = (ImapList)bracketedObj; // ImapList bracketed = (ImapList)bracketedObj;
// //
// if (bracketed.size() > 0) // if (!bracketed.isEmpty())
// { // {
// Object keyObj = bracketed.get(0); // Object keyObj = bracketed.get(0);
// if (keyObj instanceof String) // if (keyObj instanceof String)
@ -1545,7 +1545,7 @@ public class ImapStore extends Store {
StringBuilder contentDisposition = new StringBuilder(); StringBuilder contentDisposition = new StringBuilder();
if (bodyDisposition != null && bodyDisposition.size() > 0) { if (bodyDisposition != null && !bodyDisposition.isEmpty()) {
if (!"NIL".equalsIgnoreCase(bodyDisposition.getString(0))) { if (!"NIL".equalsIgnoreCase(bodyDisposition.getString(0))) {
contentDisposition.append(bodyDisposition.getString(0).toLowerCase(Locale.US)); contentDisposition.append(bodyDisposition.getString(0).toLowerCase(Locale.US));
} }
@ -1817,7 +1817,7 @@ public class ImapStore extends Store {
private List<ImapResponse> receiveCapabilities(List<ImapResponse> responses) { private List<ImapResponse> receiveCapabilities(List<ImapResponse> responses) {
for (ImapResponse response : responses) { for (ImapResponse response : responses) {
ImapList capabilityList = null; ImapList capabilityList = null;
if (response.size() > 0 && ImapResponseParser.equalsIgnoreCase(response.get(0), "OK")) { if (!response.isEmpty() && ImapResponseParser.equalsIgnoreCase(response.get(0), "OK")) {
for (Object thisPart : response) { for (Object thisPart : response) {
if (thisPart instanceof ImapList) { if (thisPart instanceof ImapList) {
ImapList thisList = (ImapList)thisPart; ImapList thisList = (ImapList)thisPart;
@ -1832,7 +1832,7 @@ public class ImapStore extends Store {
} }
if (capabilityList != null) { if (capabilityList != null) {
if (capabilityList.size() > 0 && ImapResponseParser.equalsIgnoreCase(capabilityList.get(0), CAPABILITY_CAPABILITY)) { if (!capabilityList.isEmpty() && ImapResponseParser.equalsIgnoreCase(capabilityList.get(0), CAPABILITY_CAPABILITY)) {
if (K9.DEBUG) { if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "Saving " + capabilityList.size() + " capabilities for " + getLogId()); Log.d(K9.LOG_TAG, "Saving " + capabilityList.size() + " capabilities for " + getLogId());
} }
@ -2495,13 +2495,13 @@ public class ImapStore extends Store {
ImapMessage message = new ImapMessage("" + uid, ImapFolderPusher.this); ImapMessage message = new ImapMessage("" + uid, ImapFolderPusher.this);
messages.add(message); messages.add(message);
} }
if (messages.size() > 0) { if (!messages.isEmpty()) {
pushMessages(messages, true); pushMessages(messages, true);
} }
} else { } else {
List<ImapResponse> untaggedResponses = null; List<ImapResponse> untaggedResponses = null;
while (storedUntaggedResponses.size() > 0) { while (!storedUntaggedResponses.isEmpty()) {
if (K9.DEBUG) if (K9.DEBUG)
Log.i(K9.LOG_TAG, "Processing " + storedUntaggedResponses.size() + " untagged responses from previous commands for " + getLogId()); Log.i(K9.LOG_TAG, "Processing " + storedUntaggedResponses.size() + " untagged responses from previous commands for " + getLogId());
untaggedResponses = new ArrayList<ImapResponse>(storedUntaggedResponses); untaggedResponses = new ArrayList<ImapResponse>(storedUntaggedResponses);
@ -2608,10 +2608,10 @@ public class ImapStore extends Store {
if (K9.DEBUG) if (K9.DEBUG)
Log.d(K9.LOG_TAG, "UIDs for messages needing flag sync are " + flagSyncMsgSeqs + " for " + getLogId()); Log.d(K9.LOG_TAG, "UIDs for messages needing flag sync are " + flagSyncMsgSeqs + " for " + getLogId());
if (flagSyncMsgSeqs.size() > 0) { if (!flagSyncMsgSeqs.isEmpty()) {
syncMessages(flagSyncMsgSeqs); syncMessages(flagSyncMsgSeqs);
} }
if (removeMsgUids.size() > 0) { if (!removeMsgUids.isEmpty()) {
removeMessages(removeMsgUids); removeMessages(removeMsgUids);
} }
} }
@ -2649,7 +2649,7 @@ public class ImapStore extends Store {
ImapMessage message = new ImapMessage("" + uid, ImapFolderPusher.this); ImapMessage message = new ImapMessage("" + uid, ImapFolderPusher.this);
messages.add(message); messages.add(message);
} }
if (messages.size() > 0) { if (!messages.isEmpty()) {
pushMessages(messages, true); pushMessages(messages, true);
} }
} }

View File

@ -892,7 +892,7 @@ public class LocalStore extends Store implements Serializable {
whereClause.append(" )"); whereClause.append(" )");
} }
if (folders != null && folders.size() > 0) { if (folders != null && !folders.isEmpty()) {
whereClause.append(" AND folder_id in ("); whereClause.append(" AND folder_id in (");
boolean anyAdded = false; boolean anyAdded = false;
for (LocalFolder folder : folders) { for (LocalFolder folder : folders) {
@ -1786,7 +1786,7 @@ public class LocalStore extends Store implements Serializable {
@Override @Override
public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException { public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException {
Cursor cursor = null; Cursor cursor = null;
if (messages.size() == 0) { if (messages.isEmpty()) {
return null; return null;
} }
try { try {

View File

@ -506,7 +506,7 @@ public class Pop3Store extends Store {
unindexedUids.add(uid); unindexedUids.add(uid);
} }
} }
if (unindexedUids.size() == 0) { if (unindexedUids.isEmpty()) {
return; return;
} }
/* /*