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
This commit is contained in:
parent
8078021e8f
commit
f89f30ffcd
|
@ -46,6 +46,7 @@
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.jgit.internal.JGitText;
|
import org.eclipse.jgit.internal.JGitText;
|
||||||
|
@ -126,6 +127,31 @@ public static enum Result {
|
||||||
OK;
|
OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter a collection of commands according to result.
|
||||||
|
*
|
||||||
|
* @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 4.3
|
||||||
|
*/
|
||||||
|
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.
|
* Filter a list of commands according to result.
|
||||||
*
|
*
|
||||||
|
@ -138,13 +164,8 @@ public static enum Result {
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
*/
|
*/
|
||||||
public static List<ReceiveCommand> filter(List<ReceiveCommand> commands,
|
public static List<ReceiveCommand> filter(List<ReceiveCommand> commands,
|
||||||
final Result want) {
|
Result want) {
|
||||||
List<ReceiveCommand> r = new ArrayList<ReceiveCommand>(commands.size());
|
return filter((Iterable<ReceiveCommand>) commands, want);
|
||||||
for (final ReceiveCommand cmd : commands) {
|
|
||||||
if (cmd.getResult() == want)
|
|
||||||
r.add(cmd);
|
|
||||||
}
|
|
||||||
return r;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final ObjectId oldId;
|
private final ObjectId oldId;
|
||||||
|
|
Loading…
Reference in New Issue