From 5dc1b82340f71a7a8e2cfcf396cb5fe5e857717d Mon Sep 17 00:00:00 2001 From: Art O Cathain Date: Sat, 11 Oct 2014 23:52:48 +0100 Subject: [PATCH] address review comments --- src/com/fsck/k9/activity/MessageCompose.java | 4 +-- .../NotificationDeleteConfirmation.java | 3 ++ src/com/fsck/k9/helper/Utility.java | 31 +++++-------------- .../k9/service/NotificationActionService.java | 6 ++++ .../src/com/fsck/k9/helper/UtilityTest.java | 28 ----------------- 5 files changed, 18 insertions(+), 54 deletions(-) delete mode 100644 tests-on-jvm/src/com/fsck/k9/helper/UtilityTest.java diff --git a/src/com/fsck/k9/activity/MessageCompose.java b/src/com/fsck/k9/activity/MessageCompose.java index 4a0ab4cfa..9a9a6c16e 100644 --- a/src/com/fsck/k9/activity/MessageCompose.java +++ b/src/com/fsck/k9/activity/MessageCompose.java @@ -1155,7 +1155,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - List attachments = new ArrayList(); + ArrayList attachments = new ArrayList(); for (int i = 0, count = mAttachments.getChildCount(); i < count; i++) { View view = mAttachments.getChildAt(i); Attachment attachment = (Attachment) view.getTag(); @@ -1164,7 +1164,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, outState.putInt(STATE_KEY_NUM_ATTACHMENTS_LOADING, mNumAttachmentsLoading); outState.putString(STATE_KEY_WAITING_FOR_ATTACHMENTS, mWaitingForAttachments.name()); - outState.putParcelableArrayList(STATE_KEY_ATTACHMENTS, Utility.toArrayList(attachments)); + outState.putParcelableArrayList(STATE_KEY_ATTACHMENTS, attachments); outState.putBoolean(STATE_KEY_CC_SHOWN, mCcWrapper.getVisibility() == View.VISIBLE); outState.putBoolean(STATE_KEY_BCC_SHOWN, mBccWrapper.getVisibility() == View.VISIBLE); outState.putSerializable(STATE_KEY_QUOTED_TEXT_MODE, mQuotedTextMode); diff --git a/src/com/fsck/k9/activity/NotificationDeleteConfirmation.java b/src/com/fsck/k9/activity/NotificationDeleteConfirmation.java index 9a070ed39..bd234d0e7 100644 --- a/src/com/fsck/k9/activity/NotificationDeleteConfirmation.java +++ b/src/com/fsck/k9/activity/NotificationDeleteConfirmation.java @@ -27,6 +27,9 @@ public class NotificationDeleteConfirmation extends Activity { private Account mAccount; private List mMessageRefs; + /** + * @param refs must be Serializable + */ public static PendingIntent getIntent(Context context, final Account account, final List refs) { Intent i = new Intent(context, NotificationDeleteConfirmation.class); i.putExtra(EXTRA_ACCOUNT, account.getUuid()); diff --git a/src/com/fsck/k9/helper/Utility.java b/src/com/fsck/k9/helper/Utility.java index e97e852ef..75150a147 100644 --- a/src/com/fsck/k9/helper/Utility.java +++ b/src/com/fsck/k9/helper/Utility.java @@ -708,34 +708,17 @@ public class Utility { return sMainThreadHandler; } + /** + * @return the supplied list casted to Serializable. + * + * See https://github.com/k9mail/k9mail_pgp_mime/pull/12#issuecomment-58767082 + */ public static Serializable toSerializableList(List list) { - return isExpectedCollectionClass(Serializable.class, list) ? - (Serializable) list : - new ArrayList(list); - } - - public static ArrayList toArrayList(List list) { - return isExpectedCollectionClass(ArrayList.class, list) ? - (ArrayList) list : - new ArrayList(list); + return (Serializable) list; } public static Serializable toSerializableConcurrentMap(ConcurrentMap map) { - return isExpectedCollectionClass(ConcurrentHashMap.class, map) ? - (ConcurrentHashMap) map : - new ConcurrentHashMap(map); - } - - private static boolean isExpectedCollectionClass(Class expected, Object instance) { -// Objects.requireNonNull(instance); // uncomment when project moves to API level 19 - if (!expected.isInstance(instance)) { - Log.w(K9.LOG_TAG, "Instance class [" + instance.getClass().getName() - + "] would be better as [" + expected.getName() - + "] for performance, to prevent collection copying"); - return false; - } else { - return true; - } + return (ConcurrentHashMap) map; } } diff --git a/src/com/fsck/k9/service/NotificationActionService.java b/src/com/fsck/k9/service/NotificationActionService.java index e4cad21c9..a29b50568 100644 --- a/src/com/fsck/k9/service/NotificationActionService.java +++ b/src/com/fsck/k9/service/NotificationActionService.java @@ -37,6 +37,9 @@ public class NotificationActionService extends CoreService { return PendingIntent.getService(context, account.getAccountNumber(), i, PendingIntent.FLAG_UPDATE_CURRENT); } + /** + * @param refs must be Serializable + */ public static PendingIntent getReadAllMessagesIntent(Context context, final Account account, final List refs) { Intent i = new Intent(context, NotificationActionService.class); @@ -55,6 +58,9 @@ public class NotificationActionService extends CoreService { return PendingIntent.getService(context, account.getAccountNumber(), i, PendingIntent.FLAG_UPDATE_CURRENT); } + /** + * @param refs must be Serializable + */ public static Intent getDeleteAllMessagesIntent(Context context, final Account account, final List refs) { Intent i = new Intent(context, NotificationActionService.class); diff --git a/tests-on-jvm/src/com/fsck/k9/helper/UtilityTest.java b/tests-on-jvm/src/com/fsck/k9/helper/UtilityTest.java deleted file mode 100644 index a0fff4d2e..000000000 --- a/tests-on-jvm/src/com/fsck/k9/helper/UtilityTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.fsck.k9.mail.internet; - -import com.fsck.k9.helper.Utility; - -import junit.framework.TestCase; - -import java.io.*; -import java.util.*; - -public class UtilityTest extends TestCase { - - public void testToArrayList() { - LinkedList input = new LinkedList(Arrays.asList("a", "b")); - - Serializable serializableList = Utility.toArrayList(input); - - assertEquals(serializableList, input); - } - - public void testToArrayListAlreadyArrayList() { - ArrayList input = new ArrayList(Arrays.asList("a", "b")); - - Serializable serializableList = Utility.toArrayList(input); - - assertSame(serializableList, input); - } - -}