aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit/transport/PostUploadHookChain.java
diff options
context:
space:
mode:
authorIvan Frade <ifrade@google.com>2019-07-08 15:09:30 -0700
committerIvan Frade <ifrade@google.com>2019-07-24 14:09:48 -0700
commitd1f7efcf2b715777b0bd74f4c9c6deba102cef4c (patch)
tree15859a25012bced7a73577df0edd64e6f4ee8aa2 /org.eclipse.jgit/src/org/eclipse/jgit/transport/PostUploadHookChain.java
parentb73441272448a1202debb4b02eb79301664408e6 (diff)
downloadjgit-d1f7efcf2b715777b0bd74f4c9c6deba102cef4c.tar.gz
jgit-d1f7efcf2b715777b0bd74f4c9c6deba102cef4c.zip
PostUploadHookChain: Use a list instead of array internally
The newly introduced ProtocolV2HookChain is implemented using lists instead of arrays. Update PostUploadHookChain to keep hook chain implementations consistent. Change-Id: Ic5694feab943e8949896b93103dbf427716c9bd7 Signed-off-by: Ivan Frade <ifrade@google.com>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/transport/PostUploadHookChain.java')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/PostUploadHookChain.java37
1 files changed, 19 insertions, 18 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PostUploadHookChain.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PostUploadHookChain.java
index 542abe7563..4334888a9a 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PostUploadHookChain.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PostUploadHookChain.java
@@ -42,7 +42,9 @@
package org.eclipse.jgit.transport;
+import java.util.Collections;
import java.util.List;
+import java.util.stream.Collectors;
import org.eclipse.jgit.storage.pack.PackStatistics;
@@ -55,8 +57,7 @@ import org.eclipse.jgit.storage.pack.PackStatistics;
* @since 4.1
*/
public class PostUploadHookChain implements PostUploadHook {
- private final PostUploadHook[] hooks;
- private final int count;
+ private final List<PostUploadHook> hooks;
/**
* Create a new hook chaining the given hooks together.
@@ -65,29 +66,29 @@ public class PostUploadHookChain implements PostUploadHook {
* hooks to execute, in order.
* @return a new chain of the given hooks.
*/
- public static PostUploadHook newChain(List<? extends PostUploadHook> hooks) {
- PostUploadHook[] newHooks = new PostUploadHook[hooks.size()];
- int i = 0;
- for (PostUploadHook hook : hooks)
- if (hook != PostUploadHook.NULL)
- newHooks[i++] = hook;
- if (i == 0)
+ public static PostUploadHook newChain(List<PostUploadHook> hooks) {
+ List<PostUploadHook> newHooks = hooks.stream()
+ .filter(hook -> !hook.equals(PostUploadHook.NULL))
+ .collect(Collectors.toList());
+
+ if (newHooks.isEmpty()) {
return PostUploadHook.NULL;
- else if (i == 1)
- return newHooks[0];
- else
- return new PostUploadHookChain(newHooks, i);
+ } else if (newHooks.size() == 1) {
+ return newHooks.get(0);
+ } else {
+ return new PostUploadHookChain(newHooks);
+ }
}
/** {@inheritDoc} */
@Override
public void onPostUpload(PackStatistics stats) {
- for (int i = 0; i < count; i++)
- hooks[i].onPostUpload(stats);
+ for (PostUploadHook hook : hooks) {
+ hook.onPostUpload(stats);
+ }
}
- private PostUploadHookChain(PostUploadHook[] hooks, int count) {
- this.hooks = hooks;
- this.count = count;
+ private PostUploadHookChain(List<PostUploadHook> hooks) {
+ this.hooks = Collections.unmodifiableList(hooks);
}
}