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