CommentsUtil: Use java.util.Optional
Change-Id: I5a70fc6d6b46274404e2bcd886f7068652c81ae9
This commit is contained in:
@@ -18,7 +18,6 @@ import static com.google.common.base.MoreObjects.firstNonNull;
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.ComparisonChain;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@@ -64,6 +63,8 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
/**
|
||||
@@ -153,22 +154,18 @@ public class CommentsUtil {
|
||||
public Optional<Comment> get(ReviewDb db, ChangeNotes notes,
|
||||
Comment.Key key) throws OrmException {
|
||||
if (!migration.readChanges()) {
|
||||
PatchLineComment plc = db.patchComments()
|
||||
.get(PatchLineComment.Key.from(notes.getChangeId(), key));
|
||||
Comment c = plc != null ? plc.asComment(serverId) : null;
|
||||
return Optional.fromNullable(c);
|
||||
return Optional.ofNullable(
|
||||
db.patchComments()
|
||||
.get(PatchLineComment.Key.from(notes.getChangeId(), key)))
|
||||
.map(plc -> plc.asComment(serverId));
|
||||
}
|
||||
for (Comment c : publishedByChange(db, notes)) {
|
||||
if (key.equals(c.key)) {
|
||||
return Optional.of(c);
|
||||
}
|
||||
Predicate<Comment> p = c -> key.equals(c.key);
|
||||
Optional<Comment> c =
|
||||
publishedByChange(db, notes).stream().filter(p).findFirst();
|
||||
if (c.isPresent()) {
|
||||
return c;
|
||||
}
|
||||
for (Comment c : draftByChange(db, notes)) {
|
||||
if (key.equals(c.key)) {
|
||||
return Optional.of(c);
|
||||
}
|
||||
}
|
||||
return Optional.absent();
|
||||
return draftByChange(db, notes).stream().filter(p).findFirst();
|
||||
}
|
||||
|
||||
public List<Comment> publishedByChange(ReviewDb db, ChangeNotes notes)
|
||||
|
||||
@@ -16,7 +16,6 @@ package com.google.gerrit.server.change;
|
||||
|
||||
import static com.google.gerrit.server.CommentsUtil.setCommentRevId;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.gerrit.common.TimeUtil;
|
||||
import com.google.gerrit.extensions.common.CommentInfo;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
@@ -39,6 +38,7 @@ import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
|
||||
@Singleton
|
||||
public class DeleteDraftComment
|
||||
|
||||
@@ -16,7 +16,6 @@ package com.google.gerrit.server.change;
|
||||
|
||||
import static com.google.gerrit.server.CommentsUtil.setCommentRevId;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.gerrit.common.TimeUtil;
|
||||
import com.google.gerrit.extensions.api.changes.DraftInput;
|
||||
import com.google.gerrit.extensions.common.CommentInfo;
|
||||
@@ -44,6 +43,7 @@ import com.google.inject.Singleton;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
|
||||
@Singleton
|
||||
public class PutDraftComment implements RestModifyView<DraftCommentResource, DraftInput> {
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.server.mail;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Ordering;
|
||||
import com.google.gerrit.common.errors.EmailException;
|
||||
@@ -43,6 +42,7 @@ import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/** Send comments, after the author of them hit used Publish Comments in the UI.
|
||||
@@ -252,7 +252,7 @@ public class CommentSender extends ReplyToChangeSender {
|
||||
} catch (OrmException e) {
|
||||
log.warn("Could not find the parent of this comment: "
|
||||
+ child.toString());
|
||||
parent = Optional.absent();
|
||||
parent = Optional.empty();
|
||||
}
|
||||
if (parent.isPresent()) {
|
||||
String msg = parent.get().message.trim();
|
||||
|
||||
Reference in New Issue
Block a user