summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Pearce <spearce@spearce.org>2015-12-01 14:20:44 -0800
committerShawn Pearce <spearce@spearce.org>2015-12-01 19:59:03 -0800
commitf89f30ffcdfbd6d18e674f9d5e565bd6a21ee938 (patch)
tree474b9da8b9914cd4fd7a271e9c0ca67174157606
parent8078021e8f960f1673449790425235f2c1edf63a (diff)
downloadjgit-f89f30ffcdfbd6d18e674f9d5e565bd6a21ee938.tar.gz
jgit-f89f30ffcdfbd6d18e674f9d5e565bd6a21ee938.zip
ReceiveCommand.filter: Accept Iterable
PreReceiveHook is given a Collection<ReceiveCommand> and it can be very useful here to call ReceiveCommand.filter(cmds, NOT_ATTEMPTED). Overload filter to accept both Iterable and List. Keep backwards binary compatibility for List by upcasting to Iterable. Change-Id: Ib1341876c703670945ef209edc8259715ee86c26
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceiveCommand.java35
1 files changed, 28 insertions, 7 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceiveCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceiveCommand.java
index 7c44dba4a2..0cc7e5c50e 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceiveCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceiveCommand.java
@@ -46,6 +46,7 @@ package org.eclipse.jgit.transport;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import org.eclipse.jgit.internal.JGitText;
@@ -127,26 +128,46 @@ public class ReceiveCommand {
}
/**
- * Filter a list of commands according to result.
+ * Filter a collection of commands according to result.
*
- * @param commands
+ * @param in
* commands to filter.
* @param want
* desired status to filter by.
* @return a copy of the command list containing only those commands with
* the desired status.
- * @since 2.0
+ * @since 4.3
*/
- public static List<ReceiveCommand> filter(List<ReceiveCommand> commands,
- final Result want) {
- List<ReceiveCommand> r = new ArrayList<ReceiveCommand>(commands.size());
- for (final ReceiveCommand cmd : commands) {
+ public static List<ReceiveCommand> filter(Iterable<ReceiveCommand> in,
+ Result want) {
+ List<ReceiveCommand> r;
+ if (in instanceof Collection)
+ r = new ArrayList<>(((Collection<?>) in).size());
+ else
+ r = new ArrayList<>();
+ for (ReceiveCommand cmd : in) {
if (cmd.getResult() == want)
r.add(cmd);
}
return r;
}
+ /**
+ * Filter a list of commands according to result.
+ *
+ * @param commands
+ * commands to filter.
+ * @param want
+ * desired status to filter by.
+ * @return a copy of the command list containing only those commands with
+ * the desired status.
+ * @since 2.0
+ */
+ public static List<ReceiveCommand> filter(List<ReceiveCommand> commands,
+ Result want) {
+ return filter((Iterable<ReceiveCommand>) commands, want);
+ }
+
private final ObjectId oldId;
private final ObjectId newId;