1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.transport;
12
13 import java.util.Collection;
14 import java.util.List;
15
16
17
18
19
20
21
22 public class PostReceiveHookChain implements PostReceiveHook {
23 private final PostReceiveHook[] hooks;
24 private final int count;
25
26
27
28
29
30
31
32
33 public static PostReceiveHook newChain(
34 List<? extends PostReceiveHook> hooks) {
35 PostReceiveHook[] newHooks = new PostReceiveHook[hooks.size()];
36 int i = 0;
37 for (PostReceiveHook hook : hooks)
38 if (hook != PostReceiveHook.NULL)
39 newHooks[i++] = hook;
40 switch (i) {
41 case 0:
42 return PostReceiveHook.NULL;
43 case 1:
44 return newHooks[0];
45 default:
46 return new PostReceiveHookChain(newHooks, i);
47 }
48 }
49
50
51 @Override
52 public void onPostReceive(ReceivePack rp,
53 Collection<ReceiveCommand> commands) {
54 for (int i = 0; i < count; i++)
55 hooks[i].onPostReceive(rp, commands);
56 }
57
58 private PostReceiveHookChain(PostReceiveHook[] hooks, int count) {
59 this.hooks = hooks;
60 this.count = count;
61 }
62 }