Convert static PutDraftComment#side(Comment) method to method on Comment

Change-Id: I9c3956257f1187150d62a228d2ab91515960174d
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2016-09-21 13:42:57 +02:00
parent aaf6337a17
commit e2d2f654d6
4 changed files with 10 additions and 14 deletions

View File

@@ -59,6 +59,13 @@ public abstract class Comment {
} }
} }
public short side() {
if (side == Side.PARENT) {
return (short) (parent == null ? 0 : -parent.shortValue());
}
return 1;
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) { if (this == o) {

View File

@@ -15,7 +15,6 @@
package com.google.gerrit.server.change; package com.google.gerrit.server.change;
import static com.google.gerrit.server.PatchLineCommentsUtil.setCommentRevId; import static com.google.gerrit.server.PatchLineCommentsUtil.setCommentRevId;
import static com.google.gerrit.server.change.PutDraftComment.side;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.gerrit.common.TimeUtil; import com.google.gerrit.common.TimeUtil;
@@ -119,7 +118,7 @@ public class CreateDraftComment implements RestModifyView<RevisionResource, Draf
ChangeUtil.messageUUID(ctx.getDb())), ChangeUtil.messageUUID(ctx.getDb())),
line, ctx.getAccountId(), Url.decode(in.inReplyTo), line, ctx.getAccountId(), Url.decode(in.inReplyTo),
ctx.getWhen()); ctx.getWhen());
comment.setSide(side(in)); comment.setSide(in.side());
comment.setMessage(in.message.trim()); comment.setMessage(in.message.trim());
comment.setRange(in.range); comment.setRange(in.range);
comment.setTag(in.tag); comment.setTag(in.tag);

View File

@@ -17,7 +17,6 @@ package com.google.gerrit.server.change;
import static com.google.common.base.MoreObjects.firstNonNull; import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.gerrit.server.PatchLineCommentsUtil.setCommentRevId; import static com.google.gerrit.server.PatchLineCommentsUtil.setCommentRevId;
import static com.google.gerrit.server.change.PutDraftComment.side;
import static com.google.gerrit.server.notedb.ReviewerStateInternal.REVIEWER; import static com.google.gerrit.server.notedb.ReviewerStateInternal.REVIEWER;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST; import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
@@ -484,7 +483,7 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
} }
e.setStatus(PatchLineComment.Status.PUBLISHED); e.setStatus(PatchLineComment.Status.PUBLISHED);
e.setWrittenOn(ctx.getWhen()); e.setWrittenOn(ctx.getWhen());
e.setSide(side(c)); e.setSide(c.side());
setCommentRevId(e, patchListCache, ctx.getChange(), ps); setCommentRevId(e, patchListCache, ctx.getChange(), ps);
e.setMessage(c.message); e.setMessage(c.message);
e.setTag(in.tag); e.setTag(in.tag);

View File

@@ -19,8 +19,6 @@ import static com.google.gerrit.server.PatchLineCommentsUtil.setCommentRevId;
import com.google.common.base.Optional; 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.client.Comment;
import com.google.gerrit.extensions.client.Side;
import com.google.gerrit.extensions.common.CommentInfo; import com.google.gerrit.extensions.common.CommentInfo;
import com.google.gerrit.extensions.restapi.BadRequestException; import com.google.gerrit.extensions.restapi.BadRequestException;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException; import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
@@ -164,7 +162,7 @@ public class PutDraftComment implements RestModifyView<DraftCommentResource, Dra
private static PatchLineComment update(PatchLineComment e, DraftInput in, private static PatchLineComment update(PatchLineComment e, DraftInput in,
Timestamp when) { Timestamp when) {
if (in.side != null) { if (in.side != null) {
e.setSide(side(in)); e.setSide(in.side());
} }
if (in.inReplyTo != null) { if (in.inReplyTo != null) {
e.setParentUuid(Url.decode(in.inReplyTo)); e.setParentUuid(Url.decode(in.inReplyTo));
@@ -181,11 +179,4 @@ public class PutDraftComment implements RestModifyView<DraftCommentResource, Dra
} }
return e; return e;
} }
static short side(Comment c) {
if (c.side == Side.PARENT) {
return (short) (c.parent == null ? 0 : -c.parent.shortValue());
}
return 1;
}
} }