use lists instead of arrays in PendingCommands

This commit is contained in:
Vincent Breitmoser 2016-08-06 13:02:13 +02:00
parent c4ab70ca0b
commit 3eb949e674
2 changed files with 19 additions and 24 deletions

View file

@ -1908,7 +1908,7 @@ public class MessagingController {
closeFolder(localFolder); closeFolder(localFolder);
} }
} }
private void queueMoveOrCopy(Account account, String srcFolder, String destFolder, boolean isCopy, String uids[]) { private void queueMoveOrCopy(Account account, String srcFolder, String destFolder, boolean isCopy, List<String> uids) {
if (account.getErrorFolderName().equals(srcFolder)) { if (account.getErrorFolderName().equals(srcFolder)) {
return; return;
} }
@ -1917,7 +1917,7 @@ public class MessagingController {
} }
private void queueMoveOrCopy(Account account, String srcFolder, String destFolder, private void queueMoveOrCopy(Account account, String srcFolder, String destFolder,
boolean isCopy, String uids[], Map<String, String> uidMap) { boolean isCopy, List<String> uids, Map<String, String> uidMap) {
if (uidMap == null || uidMap.isEmpty()) { if (uidMap == null || uidMap.isEmpty()) {
queueMoveOrCopy(account, srcFolder, destFolder, isCopy, uids); queueMoveOrCopy(account, srcFolder, destFolder, isCopy, uids);
} else { } else {
@ -1948,7 +1948,7 @@ public class MessagingController {
localDestFolder = (LocalFolder) localStore.getFolder(destFolder); localDestFolder = (LocalFolder) localStore.getFolder(destFolder);
List<Message> messages = new ArrayList<>(); List<Message> messages = new ArrayList<>();
Collection<String> uids = command.newUidMap != null ? command.newUidMap.keySet() : Arrays.asList(command.uids); Collection<String> uids = command.newUidMap != null ? command.newUidMap.keySet() : command.uids;
for (String uid : uids) { for (String uid : uids) {
if (!uid.startsWith(K9.LOCAL_UID_PREFIX)) { if (!uid.startsWith(K9.LOCAL_UID_PREFIX)) {
messages.add(remoteSrcFolder.getMessage(uid)); messages.add(remoteSrcFolder.getMessage(uid));
@ -2024,7 +2024,7 @@ public class MessagingController {
} }
private void queueSetFlag(final Account account, final String folderName, private void queueSetFlag(final Account account, final String folderName,
final boolean newState, final Flag flag, final String[] uids) { final boolean newState, final Flag flag, final List<String> uids) {
putBackground("queueSetFlag " + account.getDescription() + ":" + folderName, null, new Runnable() { putBackground("queueSetFlag " + account.getDescription() + ":" + folderName, null, new Runnable() {
@Override @Override
public void run() { public void run() {
@ -2322,9 +2322,7 @@ public class MessagingController {
} }
// Send flag change to server // Send flag change to server
List<String> value = entry.getValue(); queueSetFlag(account, folderName, newState, flag, entry.getValue());
String[] uids = value.toArray(new String[value.size()]);
queueSetFlag(account, folderName, newState, flag, uids);
processPendingCommands(account); processPendingCommands(account);
} }
} }
@ -2387,11 +2385,7 @@ public class MessagingController {
return; return;
} }
String[] uids = new String[messages.size()]; List<String> uids = getUidsFromMessages(messages);
for (int i = 0, end = uids.length; i < end; i++) {
uids[i] = messages.get(i).getUid();
}
queueSetFlag(account, folderName, newState, flag, uids); queueSetFlag(account, folderName, newState, flag, uids);
processPendingCommands(account); processPendingCommands(account);
} catch (MessagingException me) { } catch (MessagingException me) {
@ -3234,8 +3228,8 @@ public class MessagingController {
} }
} }
Set<String> origUidKeys = origUidMap.keySet(); List<String> origUidKeys = new ArrayList<>(origUidMap.keySet());
queueMoveOrCopy(account, srcFolder, destFolder, isCopy, origUidKeys.toArray(new String[origUidKeys.size()]), uidMap); queueMoveOrCopy(account, srcFolder, destFolder, isCopy, origUidKeys, uidMap);
} }
processPendingCommands(account); processPendingCommands(account);
@ -3378,7 +3372,7 @@ public class MessagingController {
MessagingListener listener) { MessagingListener listener) {
Folder localFolder = null; Folder localFolder = null;
Folder localTrashFolder = null; Folder localTrashFolder = null;
String[] uids = getUidsFromMessages(messages); List<String> uids = getUidsFromMessages(messages);
try { try {
//We need to make these callbacks before moving the messages to the trash //We need to make these callbacks before moving the messages to the trash
//as messages get a new UID after being moved //as messages get a new UID after being moved
@ -3456,10 +3450,10 @@ public class MessagingController {
} }
} }
private static String[] getUidsFromMessages(List <? extends Message> messages) { private static List<String> getUidsFromMessages(List <? extends Message> messages) {
String[] uids = new String[messages.size()]; List<String> uids = new ArrayList<>(messages.size());
for (int i = 0; i < messages.size(); i++) { for (int i = 0; i < messages.size(); i++) {
uids[i] = messages.get(i).getUid(); uids.add(messages.get(i).getUid());
} }
return uids; return uids;
} }

View file

@ -1,6 +1,7 @@
package com.fsck.k9.controller; package com.fsck.k9.controller;
import java.util.List;
import java.util.Map; import java.util.Map;
import com.fsck.k9.mail.Flag; import com.fsck.k9.mail.Flag;
@ -15,7 +16,7 @@ public class MessagingControllerCommands {
static final String COMMAND_EMPTY_TRASH = "empty_trash"; static final String COMMAND_EMPTY_TRASH = "empty_trash";
public static PendingSetFlag createSetFlag(String folder, boolean newState, Flag flag, String[] uids) { public static PendingSetFlag createSetFlag(String folder, boolean newState, Flag flag, List<String> uids) {
return new PendingSetFlag(folder, newState, flag, uids); return new PendingSetFlag(folder, newState, flag, uids);
} }
@ -39,7 +40,7 @@ public class MessagingControllerCommands {
return new PendingMoveOrCopy(srcFolder, destFolder, isCopy, null, uidMap); return new PendingMoveOrCopy(srcFolder, destFolder, isCopy, null, uidMap);
} }
public static PendingMoveOrCopy createMoveOrCopyBulk(String srcFolder, String destFolder, boolean isCopy, String[] uids) { public static PendingMoveOrCopy createMoveOrCopyBulk(String srcFolder, String destFolder, boolean isCopy, List<String> uids) {
return new PendingMoveOrCopy(srcFolder, destFolder, isCopy, uids, null); return new PendingMoveOrCopy(srcFolder, destFolder, isCopy, uids, null);
} }
@ -56,11 +57,11 @@ public class MessagingControllerCommands {
public final String srcFolder; public final String srcFolder;
public final String destFolder; public final String destFolder;
public final boolean isCopy; public final boolean isCopy;
public final String[] uids; public final List<String> uids;
public final Map<String, String> newUidMap; public final Map<String, String> newUidMap;
public PendingMoveOrCopy( public PendingMoveOrCopy(
String srcFolder, String destFolder, boolean isCopy, String[] uids, Map<String, String> newUidMap) { String srcFolder, String destFolder, boolean isCopy, List<String> uids, Map<String, String> newUidMap) {
this.srcFolder = srcFolder; this.srcFolder = srcFolder;
this.destFolder = destFolder; this.destFolder = destFolder;
this.isCopy = isCopy; this.isCopy = isCopy;
@ -83,9 +84,9 @@ public class MessagingControllerCommands {
public final String folder; public final String folder;
public final boolean newState; public final boolean newState;
public final Flag flag; public final Flag flag;
public final String[] uids; public final List<String> uids;
public PendingSetFlag(String folder, boolean newState, Flag flag, String[] uids) { public PendingSetFlag(String folder, boolean newState, Flag flag, List<String> uids) {
this.folder = folder; this.folder = folder;
this.newState = newState; this.newState = newState;
this.flag = flag; this.flag = flag;