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

Merge pull request #449 from dnet/cleanup20140215

This commit is contained in:
cketti 2014-02-17 20:03:30 +01:00
commit 1be9272b9b
25 changed files with 65 additions and 88 deletions

View File

@ -619,9 +619,9 @@ public class Account implements BaseAccount {
public static List<Integer> getExistingAccountNumbers(Preferences preferences) {
Account[] accounts = preferences.getAccounts();
List<Integer> accountNumbers = new LinkedList<Integer>();
for (int i = 0; i < accounts.length; i++) {
accountNumbers.add(accounts[i].getAccountNumber());
List<Integer> accountNumbers = new ArrayList<Integer>(accounts.length);
for (Account a : accounts) {
accountNumbers.add(a.getAccountNumber());
}
return accountNumbers;
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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);

View File

@ -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);

View File

@ -18,6 +18,7 @@ import android.os.Handler;
import android.os.Parcelable;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.util.Rfc822Tokenizer;
import android.util.AttributeSet;
@ -2776,12 +2777,9 @@ public class MessageCompose extends K9Activity implements OnClickListener,
if (message.getMessageId() != null && message.getMessageId().length() > 0) {
mInReplyTo = message.getMessageId();
if (message.getReferences() != null && message.getReferences().length > 0) {
StringBuilder buffy = new StringBuilder();
for (int i = 0; i < message.getReferences().length; i++)
buffy.append(message.getReferences()[i]);
mReferences = buffy.toString() + " " + mInReplyTo;
String[] refs = message.getReferences();
if (refs != null && refs.length > 0) {
mReferences = TextUtils.join("", refs) + " " + mInReplyTo;
} else {
mReferences = mInReplyTo;
}

View File

@ -5,6 +5,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import android.content.Context;
import android.content.Intent;
@ -168,7 +169,7 @@ public class Prefs extends K9PreferenceActivity {
List<CharSequence> entryVector = new ArrayList<CharSequence>(Arrays.asList(mLanguage.getEntries()));
List<CharSequence> entryValueVector = new ArrayList<CharSequence>(Arrays.asList(mLanguage.getEntryValues()));
String supportedLanguages[] = getResources().getStringArray(R.array.supported_languages);
HashSet<String> supportedLanguageSet = new HashSet<String>(Arrays.asList(supportedLanguages));
Set<String> supportedLanguageSet = new HashSet<String>(Arrays.asList(supportedLanguages));
for (int i = entryVector.size() - 1; i > -1; --i) {
if (!supportedLanguageSet.contains(entryValueVector.get(i))) {
entryVector.remove(i);

View File

@ -616,11 +616,11 @@ public class MessagingController implements Runnable {
List <? extends Folder > remoteFolders = store.getPersonalNamespaces(false);
LocalStore localStore = account.getLocalStore();
HashSet<String> remoteFolderNames = new HashSet<String>();
Set<String> remoteFolderNames = new HashSet<String>();
List<LocalFolder> foldersToCreate = new LinkedList<LocalFolder>();
localFolders = localStore.getPersonalNamespaces(false);
HashSet<String> localFolderNames = new HashSet<String>();
Set<String> localFolderNames = new HashSet<String>();
for (Folder localFolder : localFolders) {
localFolderNames.add(localFolder.getName());
}
@ -693,7 +693,7 @@ public class MessagingController implements Runnable {
public void searchLocalMessagesSynchronous(final LocalSearch search, final MessagingListener listener) {
final AccountStats stats = new AccountStats();
final HashSet<String> uuidSet = new HashSet<String>(Arrays.asList(search.getAccountUuids()));
final Set<String> uuidSet = new HashSet<String>(Arrays.asList(search.getAccountUuids()));
Account[] accounts = Preferences.getPreferences(mApplication.getApplicationContext()).getAccounts();
boolean allAccounts = uuidSet.contains(SearchSpecification.ALL_ACCOUNTS);
@ -2344,14 +2344,10 @@ public class MessagingController implements Runnable {
/*
* This next part is used to bring the local UIDs of the local destination folder
* upto speed with the remote UIDs of remote destionation folder.
* upto speed with the remote UIDs of remote destination folder.
*/
if (!localUidMap.isEmpty() && remoteUidMap != null && !remoteUidMap.isEmpty()) {
Set<Map.Entry<String, String>> remoteSrcEntries = remoteUidMap.entrySet();
Iterator<Map.Entry<String, String>> remoteSrcEntriesIterator = remoteSrcEntries.iterator();
while (remoteSrcEntriesIterator.hasNext()) {
Map.Entry<String, String> entry = remoteSrcEntriesIterator.next();
for (Map.Entry<String, String> entry : remoteUidMap.entrySet()) {
String remoteSrcUid = entry.getKey();
String localDestUid = localUidMap.get(remoteSrcUid);
String newUid = entry.getValue();

View File

@ -895,7 +895,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
long[] selected = new long[mSelected.size()];
int i = 0;
for (Long id : mSelected) {
selected[i++] = Long.valueOf(id);
selected[i++] = id;
}
outState.putLongArray(STATE_SELECTED_MESSAGES, selected);
}
@ -2667,8 +2667,9 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
outMessages.add(message);
}
for (String folderName : folderMap.keySet()) {
List<Message> outMessages = folderMap.get(folderName);
for (Map.Entry<String, List<Message>> entry : folderMap.entrySet()) {
String folderName = entry.getKey();
List<Message> outMessages = entry.getValue();
Account account = outMessages.get(0).getFolder().getAccount();
if (operation == FolderOperation.MOVE) {
@ -3461,12 +3462,13 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
return false;
}
boolean loadFinished = true;
for (int i = 0; i < mCursorValid.length; i++) {
loadFinished &= mCursorValid[i];
for (boolean cursorValid : mCursorValid) {
if (!cursorValid) {
return false;
}
}
return loadFinished;
return true;
}
/**

View File

@ -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;
}
@ -118,10 +118,9 @@ public class DomainNameChecker {
}
try {
Collection<?> subjectAltNames = certificate.getSubjectAlternativeNames();
Collection<List<?>> subjectAltNames = certificate.getSubjectAlternativeNames();
if (subjectAltNames != null) {
for (Object subjectAltName : subjectAltNames) {
List<?> altNameEntry = (List<?>)(subjectAltName);
for (List<?> altNameEntry : subjectAltNames) {
if ((altNameEntry != null) && (2 <= altNameEntry.size())) {
Integer altNameType = (Integer)(altNameEntry.get(0));
if (altNameType != null && altNameType.intValue() == ALT_IPA_NAME) {
@ -157,11 +156,9 @@ public class DomainNameChecker {
private static boolean matchDns(X509Certificate certificate, String thisDomain) {
boolean hasDns = false;
try {
Collection<?> subjectAltNames = certificate.getSubjectAlternativeNames();
Collection<List<?>> subjectAltNames = certificate.getSubjectAlternativeNames();
if (subjectAltNames != null) {
Iterator<?> i = subjectAltNames.iterator();
while (i.hasNext()) {
List<?> altNameEntry = (List<?>)(i.next());
for (List<?> altNameEntry : subjectAltNames) {
if ((altNameEntry != null) && (2 <= altNameEntry.size())) {
Integer altNameType = (Integer)(altNameEntry.get(0));
if (altNameType != null && altNameType.intValue() == ALT_DNS_NAME) {
@ -213,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;
}

View File

@ -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) {

View File

@ -11,6 +11,7 @@ import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.text.Editable;
import android.text.TextUtils;
import android.util.Log;
import android.widget.EditText;
import android.widget.TextView;
@ -99,18 +100,8 @@ public class Utility {
public static String combine(Object[] parts, char separator) {
if (parts == null) {
return null;
} else if (parts.length == 0) {
return "";
} else if (parts.length == 1) {
return parts[0].toString();
}
StringBuilder sb = new StringBuilder();
sb.append(parts[0]);
for (int i = 1; i < parts.length; ++i) {
sb.append(separator);
sb.append(parts[i]);
}
return sb.toString();
return TextUtils.join(String.valueOf(separator), parts);
}
public static String base64Decode(String encoded) {

View File

@ -14,6 +14,7 @@ import android.text.Spannable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.text.TextUtils;
import android.text.util.Rfc822Token;
import android.text.util.Rfc822Tokenizer;
import android.util.Log;
@ -198,14 +199,7 @@ public class Address {
if (addresses == null) {
return null;
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < addresses.length; i++) {
sb.append(addresses[i].toString());
if (i < addresses.length - 1) {
sb.append(", ");
}
}
return sb.toString();
return TextUtils.join(", ", addresses);
}
public String toEncodedString() {

View File

@ -26,7 +26,7 @@ public abstract class Message implements Part, CompositeBody {
protected String mUid;
protected HashSet<Flag> mFlags = new HashSet<Flag>();
protected Set<Flag> mFlags = new HashSet<Flag>();
protected Date mInternalDate;

View File

@ -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;
}

View File

@ -130,8 +130,8 @@ public class EncoderUtil {
private static int qEncodedLength(byte[] bytes) {
int count = 0;
for (int idx = 0; idx < bytes.length; idx++) {
int v = bytes[idx] & 0xff;
for (byte b : bytes) {
int v = b & 0xff;
if (v == 32) {
count++;
} else if (!Q_RESTRICTED_CHARS.get(v)) {

View File

@ -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("<meta http-equiv=\"?Content-Type\"? content=\"text/html; charset=(.+?)\">", 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;
}
}

View File

@ -531,7 +531,7 @@ public class ImapStore extends Store {
return allFolders;
} else {
List<Folder> resultFolders = new LinkedList<Folder>();
HashSet<String> subscribedFolderNames = new HashSet<String>();
Set<String> subscribedFolderNames = new HashSet<String>();
List <? extends Folder > subscribedFolders = listFolders(connection, true);
for (Folder subscribedFolder : subscribedFolders) {
subscribedFolderNames.add(subscribedFolder.getName());
@ -1476,11 +1476,10 @@ public class ImapStore extends Store {
checkOpen(); //only need READ access
List<String> uids = new ArrayList<String>(messages.length);
HashMap<String, Message> messageMap = new HashMap<String, Message>();
for (int i = 0, count = messages.length; i < count; i++) {
String uid = messages[i].getUid();
for (Message msg : messages) {
String uid = msg.getUid();
uids.add(uid);
messageMap.put(uid, messages[i]);
messageMap.put(uid, msg);
}
/*
@ -1489,7 +1488,7 @@ public class ImapStore extends Store {
* Envelope - UID FETCH ([FLAGS] INTERNALDATE UID RFC822.SIZE FLAGS BODY.PEEK[HEADER.FIELDS (date subject from content-type to cc)])
*
*/
LinkedHashSet<String> fetchFields = new LinkedHashSet<String>();
Set<String> fetchFields = new LinkedHashSet<String>();
fetchFields.add("UID");
if (fp.contains(FetchProfile.Item.FLAGS)) {
fetchFields.add("FLAGS");

View File

@ -27,6 +27,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class Pop3Store extends Store {
public static final String STORE_TYPE = "POP3";
@ -628,7 +629,7 @@ public class Pop3Store extends Store {
private void indexUids(ArrayList<String> uids)
throws MessagingException, IOException {
HashSet<String> unindexedUids = new HashSet<String>();
Set<String> unindexedUids = new HashSet<String>();
for (String uid : uids) {
if (mUidToMsgMap.get(uid) == null) {
if (K9.DEBUG && K9.DEBUG_PROTOCOL_POP3) {
@ -801,7 +802,7 @@ public class Pop3Store extends Store {
}
}
} else {
HashSet<String> msgUidIndex = new HashSet<String>();
Set<String> msgUidIndex = new HashSet<String>();
for (Message message : messages) {
msgUidIndex.add(message.getUid());
}

View File

@ -560,7 +560,7 @@ public class StorageManager {
*/
public String getDefaultProviderId() {
// assume there is at least 1 provider defined
return mProviders.entrySet().iterator().next().getKey();
return mProviders.keySet().iterator().next();
}
/**

View File

@ -463,8 +463,7 @@ public class WebDavStore extends Store {
dataset = processRequest(this.mUrl, "SEARCH", getFolderListXml(), headers);
String[] folderUrls = dataset.getHrefs();
for (int i = 0; i < folderUrls.length; i++) {
String tempUrl = folderUrls[i];
for (String tempUrl : folderUrls) {
WebDavFolder folder = createFolder(tempUrl);
if (folder != null)
folderList.add(folder);

View File

@ -183,7 +183,6 @@ public class SmtpTransport extends Transport {
}
Account mAccount;
String mHost;
int mPort;
String mUsername;
@ -204,7 +203,6 @@ public class SmtpTransport extends Transport {
throw new MessagingException("Error while decoding transport URI", e);
}
mAccount = account;
mHost = settings.host;
mPort = settings.port;

View File

@ -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;
}
}

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Stack;
import java.util.Set;
import android.database.Cursor;
import android.os.Parcel;
@ -243,8 +244,8 @@ public class ConditionsTreeNode implements Parcelable {
* Get a set of all the leaves in the tree.
* @return Set of all the leaves.
*/
public HashSet<ConditionsTreeNode> getLeafSet() {
HashSet<ConditionsTreeNode> leafSet = new HashSet<ConditionsTreeNode>();
public Set<ConditionsTreeNode> getLeafSet() {
Set<ConditionsTreeNode> leafSet = new HashSet<ConditionsTreeNode>();
return getLeafSet(leafSet);
}
@ -338,7 +339,7 @@ public class ConditionsTreeNode implements Parcelable {
* @param leafSet Leafset that's being built.
* @return Set of leaves being completed.
*/
private HashSet<ConditionsTreeNode> getLeafSet(HashSet<ConditionsTreeNode> leafSet) {
private Set<ConditionsTreeNode> getLeafSet(Set<ConditionsTreeNode> leafSet) {
if (mLeft == null && mRight == null) {
// if we ended up in a leaf, add ourself and return
leafSet.add(this);

View File

@ -28,9 +28,9 @@ public class LocalSearch implements SearchSpecification {
private boolean mManualSearch = false;
// since the uuid isn't in the message table it's not in the tree neither
private HashSet<String> mAccountUuids = new HashSet<String>();
private Set<String> mAccountUuids = new HashSet<String>();
private ConditionsTreeNode mConditions = null;
private HashSet<ConditionsTreeNode> mLeafSet = new HashSet<ConditionsTreeNode>();
private Set<ConditionsTreeNode> mLeafSet = new HashSet<ConditionsTreeNode>();
///////////////////////////////////////////////////////////////