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 PreReceiveHookChain implements PreReceiveHook {
23 private final PreReceiveHook[] hooks;
24 private final int count;
25
26
27
28
29
30
31
32
33 public static PreReceiveHook newChain(List<? extends PreReceiveHook> hooks) {
34 PreReceiveHook[] newHooks = new PreReceiveHook[hooks.size()];
35 int i = 0;
36 for (PreReceiveHook hook : hooks)
37 if (hook != PreReceiveHook.NULL)
38 newHooks[i++] = hook;
39 switch (i) {
40 case 0:
41 return PreReceiveHook.NULL;
42 case 1:
43 return newHooks[0];
44 default:
45 return new PreReceiveHookChain(newHooks, i);
46 }
47 }
48
49
50 @Override
51 public void onPreReceive(ReceivePack rp,
52 Collection<ReceiveCommand> commands) {
53 for (int i = 0; i < count; i++)
54 hooks[i].onPreReceive(rp, commands);
55 }
56
57 private PreReceiveHookChain(PreReceiveHook[] hooks, int count) {
58 this.hooks = hooks;
59 this.count = count;
60 }
61 }