ChangeArgumentParser: Replace FluentIterable with Java 8 stream
Change-Id: I34dbf535241a604089ddb5d3af570c4b97c5cc2e
This commit is contained in:

committed by
David Pursehouse

parent
34c0481f47
commit
e624bc00f5
@@ -14,10 +14,8 @@
|
|||||||
|
|
||||||
package com.google.gerrit.sshd;
|
package com.google.gerrit.sshd;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import static java.util.stream.Collectors.toList;
|
||||||
import com.google.common.base.Optional;
|
|
||||||
import com.google.common.base.Predicates;
|
|
||||||
import com.google.common.collect.FluentIterable;
|
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
import com.google.gerrit.reviewdb.client.Project;
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
@@ -37,6 +35,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class ChangeArgumentParser {
|
public class ChangeArgumentParser {
|
||||||
private final CurrentUser currentUser;
|
private final CurrentUser currentUser;
|
||||||
@@ -96,24 +95,21 @@ public class ChangeArgumentParser {
|
|||||||
changes.put(ctl.getId(), changesCollection.parse(ctl));
|
changes.put(ctl.getId(), changesCollection.parse(ctl));
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ChangeControl> changeFromNotesFactory(String id,
|
private List<ChangeControl> changeFromNotesFactory(String id, CurrentUser currentUser)
|
||||||
final CurrentUser currentUser) throws OrmException {
|
throws OrmException {
|
||||||
List<ChangeNotes> changes =
|
return changeNotesFactory.create(db, Arrays.asList(Change.Id.parse(id)))
|
||||||
changeNotesFactory.create(db, Arrays.asList(Change.Id.parse(id)));
|
.stream()
|
||||||
return FluentIterable.from(changes)
|
.map(changeNote -> controlForChange(changeNote, currentUser))
|
||||||
.transform(new Function<ChangeNotes, ChangeControl>() {
|
.filter(changeControl -> changeControl.isPresent())
|
||||||
@Override
|
.map(changeControl -> changeControl.get())
|
||||||
public ChangeControl apply(ChangeNotes changeNote) {
|
.collect(toList());
|
||||||
return controlForChange(changeNote, currentUser);
|
|
||||||
}
|
|
||||||
}).filter(Predicates.notNull()).toList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ChangeControl controlForChange(ChangeNotes change, CurrentUser user) {
|
private Optional<ChangeControl> controlForChange(ChangeNotes change, CurrentUser user) {
|
||||||
try {
|
try {
|
||||||
return changeControlFactory.controlFor(change, user);
|
return Optional.of(changeControlFactory.controlFor(change, user));
|
||||||
} catch (NoSuchChangeException e) {
|
} catch (NoSuchChangeException e) {
|
||||||
return null;
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user