ReplicateRefUpdate: Drop awkward constructor
A constructor taking an object with a set of refs and also one of those
refs is an awkward pattern. Remove that code by using a small helper in
the UriUpdates interface.
Change-Id: I999e57b405d009307bca023e5b9aa7f40c71fb58
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorage.java b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorage.java
index d697d11..36c9c98 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorage.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorage.java
@@ -68,14 +68,6 @@
public final String uri;
public final String remote;
- public ReplicateRefUpdate(UriUpdates uriUpdates, String ref) {
- this(
- uriUpdates.getProjectNameKey().get(),
- ref,
- uriUpdates.getURI(),
- uriUpdates.getRemoteName());
- }
-
public ReplicateRefUpdate(String project, String ref, URIish uri, String remote) {
this.project = project;
this.ref = ref;
@@ -119,14 +111,14 @@
}
public synchronized void start(UriUpdates uriUpdates) {
- for (String ref : uriUpdates.getRefs()) {
- new Task(new ReplicateRefUpdate(uriUpdates, ref)).start();
+ for (ReplicateRefUpdate update : uriUpdates.getReplicateRefUpdates()) {
+ new Task(update).start();
}
}
public synchronized void reset(UriUpdates uriUpdates) {
- for (String ref : uriUpdates.getRefs()) {
- new Task(new ReplicateRefUpdate(uriUpdates, ref)).reset();
+ for (ReplicateRefUpdate update : uriUpdates.getReplicateRefUpdates()) {
+ new Task(update).reset();
}
}
@@ -137,8 +129,8 @@
}
public synchronized void finish(UriUpdates uriUpdates) {
- for (String ref : uriUpdates.getRefs()) {
- new Task(new ReplicateRefUpdate(uriUpdates, ref)).finish();
+ for (ReplicateRefUpdate update : uriUpdates.getReplicateRefUpdates()) {
+ new Task(update).finish();
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/UriUpdates.java b/src/main/java/com/googlesource/gerrit/plugins/replication/UriUpdates.java
index d6d6adf..9c56c8e 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/UriUpdates.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/UriUpdates.java
@@ -15,7 +15,9 @@
package com.googlesource.gerrit.plugins.replication;
import com.google.gerrit.entities.Project;
+import java.util.List;
import java.util.Set;
+import java.util.stream.Collectors;
import org.eclipse.jgit.transport.URIish;
/** A data container for updates to a single URI */
@@ -27,4 +29,13 @@
String getRemoteName();
Set<String> getRefs();
+
+ default List<ReplicationTasksStorage.ReplicateRefUpdate> getReplicateRefUpdates() {
+ return getRefs().stream()
+ .map(
+ (ref) ->
+ new ReplicationTasksStorage.ReplicateRefUpdate(
+ getProjectNameKey().get(), ref, getURI(), getRemoteName()))
+ .collect(Collectors.toList());
+ }
}