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

View file

@ -1,6 +1,7 @@
package com.fsck.k9.controller;
import java.util.List;
import java.util.Map;
import com.fsck.k9.mail.Flag;
@ -15,7 +16,7 @@ public class MessagingControllerCommands {
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);
}
@ -39,7 +40,7 @@ public class MessagingControllerCommands {
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);
}
@ -56,11 +57,11 @@ public class MessagingControllerCommands {
public final String srcFolder;
public final String destFolder;
public final boolean isCopy;
public final String[] uids;
public final List<String> uids;
public final Map<String, String> newUidMap;
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.destFolder = destFolder;
this.isCopy = isCopy;
@ -83,9 +84,9 @@ public class MessagingControllerCommands {
public final String folder;
public final boolean newState;
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.newState = newState;
this.flag = flag;