From 7464a1527a1e13950942ec1c73639d462080a044 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Mon, 19 Jul 2010 01:52:18 +0000 Subject: [PATCH] Convert for loops to "enhanced" syntax per SDK performance guidelines (Automatic with Eclipse) --- src/com/fsck/k9/Preferences.java | 4 +-- .../k9/controller/MessagingController.java | 3 +-- src/com/fsck/k9/helper/Utility.java | 4 +-- src/com/fsck/k9/mail/filter/Base64.java | 10 ++++---- src/com/fsck/k9/mail/store/ImapStore.java | 6 ++--- .../k9/mail/store/TrustManagerFactory.java | 4 +-- src/com/fsck/k9/mail/store/WebDavStore.java | 25 ++++++++----------- src/com/fsck/k9/preferences/Storage.java | 3 +-- 8 files changed, 26 insertions(+), 33 deletions(-) diff --git a/src/com/fsck/k9/Preferences.java b/src/com/fsck/k9/Preferences.java index 2237090de..fd7b1b501 100644 --- a/src/com/fsck/k9/Preferences.java +++ b/src/com/fsck/k9/Preferences.java @@ -47,9 +47,9 @@ public class Preferences { String[] uuids = accountUuids.split(","); accounts = new ArrayList(uuids.length); - for (int i = 0, length = uuids.length; i < length; i++) + for (String uuid : uuids) { - accounts.add(new Account(this, uuids[i])); + accounts.add(new Account(this, uuid)); } } else diff --git a/src/com/fsck/k9/controller/MessagingController.java b/src/com/fsck/k9/controller/MessagingController.java index 21f100185..c59a3980e 100644 --- a/src/com/fsck/k9/controller/MessagingController.java +++ b/src/com/fsck/k9/controller/MessagingController.java @@ -2933,9 +2933,8 @@ public class MessagingController implements Runnable localFolder = localStore.getFolder(folderName); localFolder.open(OpenMode.READ_WRITE); ArrayList messages = new ArrayList(); - for (int i = 0; i < uids.length; i++) + for (String uid : uids) { - String uid = uids[i]; // Allows for re-allowing sending of messages that could not be sent if (flag == Flag.FLAGGED && newState == false && uid != null diff --git a/src/com/fsck/k9/helper/Utility.java b/src/com/fsck/k9/helper/Utility.java index b4f815cbf..36d493190 100644 --- a/src/com/fsck/k9/helper/Utility.java +++ b/src/com/fsck/k9/helper/Utility.java @@ -29,9 +29,9 @@ public class Utility public final static boolean arrayContains(Object[] a, Object o) { - for (int i = 0, count = a.length; i < count; i++) + for (Object element : a) { - if (a[i].equals(o)) + if (element.equals(o)) { return true; } diff --git a/src/com/fsck/k9/mail/filter/Base64.java b/src/com/fsck/k9/mail/filter/Base64.java index a88742cfb..4ac505de4 100644 --- a/src/com/fsck/k9/mail/filter/Base64.java +++ b/src/com/fsck/k9/mail/filter/Base64.java @@ -557,9 +557,9 @@ public class Base64 implements BinaryEncoder, BinaryDecoder */ private static boolean containsBase64Byte(byte[] arrayOctet) { - for (int i = 0; i < arrayOctet.length; i++) + for (byte element : arrayOctet) { - if (isBase64(arrayOctet[i])) + if (isBase64(element)) { return true; } @@ -730,11 +730,11 @@ public class Base64 implements BinaryEncoder, BinaryDecoder byte groomedData[] = new byte[data.length]; int bytesCopied = 0; - for (int i = 0; i < data.length; i++) + for (byte element : data) { - if (isBase64(data[i])) + if (isBase64(element)) { - groomedData[bytesCopied++] = data[i]; + groomedData[bytesCopied++] = element; } } diff --git a/src/com/fsck/k9/mail/store/ImapStore.java b/src/com/fsck/k9/mail/store/ImapStore.java index 8e03a2060..d21a6caf8 100644 --- a/src/com/fsck/k9/mail/store/ImapStore.java +++ b/src/com/fsck/k9/mail/store/ImapStore.java @@ -1879,9 +1879,8 @@ public class ImapStore extends Store private String combineFlags(Flag[] flags) { ArrayList flagNames = new ArrayList(); - for (int i = 0, count = flags.length; i < count; i++) + for (Flag flag : flags) { - Flag flag = flags[i]; if (flag == Flag.SEEN) { flagNames.add("\\Seen"); @@ -1960,9 +1959,8 @@ public class ImapStore extends Store uids[i] = messages[i].getUid(); } ArrayList flagNames = new ArrayList(); - for (int i = 0, count = flags.length; i < count; i++) + for (Flag flag : flags) { - Flag flag = flags[i]; if (flag == Flag.SEEN) { flagNames.add("\\Seen"); diff --git a/src/com/fsck/k9/mail/store/TrustManagerFactory.java b/src/com/fsck/k9/mail/store/TrustManagerFactory.java index 3e029b9a3..052d629f5 100644 --- a/src/com/fsck/k9/mail/store/TrustManagerFactory.java +++ b/src/com/fsck/k9/mail/store/TrustManagerFactory.java @@ -216,10 +216,10 @@ public final class TrustManagerFactory try { javax.net.ssl.TrustManagerFactory tmf = javax.net.ssl.TrustManagerFactory.getInstance("X509"); - for (int i = 0; i < chain.length; i++) + for (X509Certificate element : chain) { keyStore.setCertificateEntry - (chain[i].getSubjectDN().toString(), chain[i]); + (element.getSubjectDN().toString(), element); } tmf.init(keyStore); diff --git a/src/com/fsck/k9/mail/store/WebDavStore.java b/src/com/fsck/k9/mail/store/WebDavStore.java index 321fe3d16..2e074e602 100644 --- a/src/com/fsck/k9/mail/store/WebDavStore.java +++ b/src/com/fsck/k9/mail/store/WebDavStore.java @@ -489,9 +489,9 @@ public class WebDavStore extends Store buffer.append("\r\n"); buffer.append("\r\n"); buffer.append("\r\n"); - for (int i = 0, count = urls.length; i < count; i++) + for (String url : urls) { - buffer.append(" "+urls[i]+"\r\n"); + buffer.append(" "+url+"\r\n"); } buffer.append("\r\n"); buffer.append("\r\n"); @@ -515,9 +515,9 @@ public class WebDavStore extends Store buffer.append("\r\n"); buffer.append("\r\n"); buffer.append("\r\n"); - for (int i = 0, count = urls.length; i < count; i++) + for (String url : urls) { - buffer.append(" "+urls[i]+"\r\n"); + buffer.append(" "+url+"\r\n"); } buffer.append("\r\n"); @@ -1865,10 +1865,8 @@ public class WebDavStore extends Store uids[i] = messages[i].getUid(); } - for (int i = 0, count = flags.length; i < count; i++) + for (Flag flag : flags) { - Flag flag = flags[i]; - if (flag == Flag.SEEN) { markServerMessagesRead(uids, value); @@ -1903,10 +1901,9 @@ public class WebDavStore extends Store { HashMap uidToUrl = getMessageUrls(uids); - for (int i = 0, count = uids.length; i < count; i++) + for (String uid : uids) { HashMap headers = new HashMap(); - String uid = uids[i]; String url = uidToUrl.get(uid); String destinationUrl = generateDeleteUrl(url); @@ -2161,19 +2158,19 @@ public class WebDavStore extends Store String[] headers = envelope.getHeaderList(); HashMap messageHeaders = envelope.getMessageHeaders(); - for (int i = 0, count = headers.length; i < count; i++) + for (String header : headers) { - String headerValue = messageHeaders.get(headers[i]); - if (headers[i].equals("Content-Length")) + String headerValue = messageHeaders.get(header); + if (header.equals("Content-Length")) { - int size = Integer.parseInt(messageHeaders.get(headers[i])); + int size = Integer.parseInt(messageHeaders.get(header)); this.setSize(size); } if (headerValue != null && !headerValue.equals("")) { - this.addHeader(headers[i], headerValue); + this.addHeader(header, headerValue); } } } diff --git a/src/com/fsck/k9/preferences/Storage.java b/src/com/fsck/k9/preferences/Storage.java index 057df302f..133ada7b2 100644 --- a/src/com/fsck/k9/preferences/Storage.java +++ b/src/com/fsck/k9/preferences/Storage.java @@ -51,9 +51,8 @@ public class Storage implements SharedPreferences if (accountUuids != null && accountUuids.length() != 0) { String[] uuids = accountUuids.split(","); - for (int i = 0, length = uuids.length; i < length; i++) + for (String uuid : uuids) { - String uuid = uuids[i]; try { String storeUriStr = Utility.base64Decode(readValue(mDb, uuid + ".storeUri"));