ChangeReportFormatter: Convert Input to use AutoValue.Builder
Change-Id: I5e1a4550701a9eaad2bbfdb9e7183a21dfda7cec Signed-off-by: David Pursehouse <dpursehouse@collab.net> Helped-by: Patrick Hiesel <hiesel@google.com>
This commit is contained in:
		@@ -14,68 +14,72 @@
 | 
			
		||||
 | 
			
		||||
package com.google.gerrit.server.git;
 | 
			
		||||
 | 
			
		||||
import com.google.auto.value.AutoValue;
 | 
			
		||||
import com.google.gerrit.common.Nullable;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.Change;
 | 
			
		||||
 | 
			
		||||
public interface ChangeReportFormatter {
 | 
			
		||||
  public static class Input {
 | 
			
		||||
    private final Change change;
 | 
			
		||||
    private String subject;
 | 
			
		||||
    private Boolean draft;
 | 
			
		||||
    private Boolean edit;
 | 
			
		||||
    private Boolean isPrivate;
 | 
			
		||||
    private Boolean wip;
 | 
			
		||||
  @AutoValue
 | 
			
		||||
  public abstract static class Input {
 | 
			
		||||
    public abstract Change change();
 | 
			
		||||
 | 
			
		||||
    public Input(Change change) {
 | 
			
		||||
      this.change = change;
 | 
			
		||||
    @Nullable
 | 
			
		||||
    public abstract String subject();
 | 
			
		||||
 | 
			
		||||
    @Nullable
 | 
			
		||||
    public abstract Boolean isDraft();
 | 
			
		||||
 | 
			
		||||
    @Nullable
 | 
			
		||||
    public abstract Boolean isEdit();
 | 
			
		||||
 | 
			
		||||
    @Nullable
 | 
			
		||||
    public abstract Boolean isPrivate();
 | 
			
		||||
 | 
			
		||||
    @Nullable
 | 
			
		||||
    public abstract Boolean isWorkInProgress();
 | 
			
		||||
 | 
			
		||||
    public static Builder builder() {
 | 
			
		||||
      return new AutoValue_ChangeReportFormatter_Input.Builder();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Input setPrivate(boolean isPrivate) {
 | 
			
		||||
      this.isPrivate = isPrivate;
 | 
			
		||||
      return this;
 | 
			
		||||
    }
 | 
			
		||||
    @AutoValue.Builder
 | 
			
		||||
    public abstract static class Builder {
 | 
			
		||||
      public abstract Builder setChange(Change val);
 | 
			
		||||
 | 
			
		||||
    public Input setDraft(boolean draft) {
 | 
			
		||||
      this.draft = draft;
 | 
			
		||||
      return this;
 | 
			
		||||
    }
 | 
			
		||||
      public abstract Builder setSubject(String val);
 | 
			
		||||
 | 
			
		||||
    public Input setEdit(boolean edit) {
 | 
			
		||||
      this.edit = edit;
 | 
			
		||||
      return this;
 | 
			
		||||
    }
 | 
			
		||||
      public abstract Builder setIsDraft(Boolean val);
 | 
			
		||||
 | 
			
		||||
    public Input setWorkInProgress(boolean wip) {
 | 
			
		||||
      this.wip = wip;
 | 
			
		||||
      return this;
 | 
			
		||||
    }
 | 
			
		||||
      public abstract Builder setIsEdit(Boolean val);
 | 
			
		||||
 | 
			
		||||
    public Input setSubject(String subject) {
 | 
			
		||||
      this.subject = subject;
 | 
			
		||||
      return this;
 | 
			
		||||
    }
 | 
			
		||||
      public abstract Builder setIsPrivate(Boolean val);
 | 
			
		||||
 | 
			
		||||
    public Change getChange() {
 | 
			
		||||
      return change;
 | 
			
		||||
    }
 | 
			
		||||
      public abstract Builder setIsWorkInProgress(Boolean val);
 | 
			
		||||
 | 
			
		||||
    public String getSubject() {
 | 
			
		||||
      return subject == null ? change.getSubject() : subject;
 | 
			
		||||
    }
 | 
			
		||||
      abstract Change change();
 | 
			
		||||
 | 
			
		||||
    public boolean isDraft() {
 | 
			
		||||
      return draft == null ? Change.Status.DRAFT == change.getStatus() : draft;
 | 
			
		||||
    }
 | 
			
		||||
      abstract String subject();
 | 
			
		||||
 | 
			
		||||
    public boolean isEdit() {
 | 
			
		||||
      return edit == null ? false : edit;
 | 
			
		||||
    }
 | 
			
		||||
      abstract Boolean isDraft();
 | 
			
		||||
 | 
			
		||||
    public boolean isPrivate() {
 | 
			
		||||
      return isPrivate == null ? change.isPrivate() : isPrivate;
 | 
			
		||||
    }
 | 
			
		||||
      abstract Boolean isEdit();
 | 
			
		||||
 | 
			
		||||
    public boolean isWorkInProgress() {
 | 
			
		||||
      return wip == null ? change.isWorkInProgress() : wip;
 | 
			
		||||
      abstract Boolean isPrivate();
 | 
			
		||||
 | 
			
		||||
      abstract Boolean isWorkInProgress();
 | 
			
		||||
 | 
			
		||||
      abstract Input autoBuild();
 | 
			
		||||
 | 
			
		||||
      public Input build() {
 | 
			
		||||
        setChange(change());
 | 
			
		||||
        setSubject(subject() == null ? change().getSubject() : subject());
 | 
			
		||||
        setIsDraft(isDraft() == null ? Change.Status.DRAFT == change().getStatus() : isDraft());
 | 
			
		||||
        setIsEdit(isEdit() == null ? false : isEdit());
 | 
			
		||||
        setIsPrivate(isPrivate() == null ? change().isPrivate() : isPrivate());
 | 
			
		||||
        setIsWorkInProgress(
 | 
			
		||||
            isWorkInProgress() == null ? change().isWorkInProgress() : isWorkInProgress());
 | 
			
		||||
        return autoBuild();
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -39,16 +39,16 @@ public class DefaultChangeReportFormatter implements ChangeReportFormatter {
 | 
			
		||||
  @Override
 | 
			
		||||
  public String changeClosed(ChangeReportFormatter.Input input) {
 | 
			
		||||
    return String.format(
 | 
			
		||||
        "change %s closed", ChangeUtil.formatChangeUrl(canonicalWebUrl, input.getChange()));
 | 
			
		||||
        "change %s closed", ChangeUtil.formatChangeUrl(canonicalWebUrl, input.change()));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private String formatChangeUrl(String url, Input input) {
 | 
			
		||||
    StringBuilder m =
 | 
			
		||||
        new StringBuilder()
 | 
			
		||||
            .append("  ")
 | 
			
		||||
            .append(ChangeUtil.formatChangeUrl(url, input.getChange()))
 | 
			
		||||
            .append(ChangeUtil.formatChangeUrl(url, input.change()))
 | 
			
		||||
            .append(" ")
 | 
			
		||||
            .append(ChangeUtil.cropSubject(input.getSubject()));
 | 
			
		||||
            .append(ChangeUtil.cropSubject(input.subject()));
 | 
			
		||||
    if (input.isDraft()) {
 | 
			
		||||
      m.append(" [DRAFT]");
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -605,7 +605,9 @@ class ReceiveCommits {
 | 
			
		||||
      addMessage("");
 | 
			
		||||
      addMessage("New Changes:");
 | 
			
		||||
      for (CreateRequest c : created) {
 | 
			
		||||
        addMessage(changeFormatter.newChange(new ChangeReportFormatter.Input(c.change)));
 | 
			
		||||
        addMessage(
 | 
			
		||||
            changeFormatter.newChange(
 | 
			
		||||
                ChangeReportFormatter.Input.builder().setChange(c.change).build()));
 | 
			
		||||
      }
 | 
			
		||||
      addMessage("");
 | 
			
		||||
    }
 | 
			
		||||
@@ -657,12 +659,14 @@ class ReceiveCommits {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        ChangeReportFormatter.Input input =
 | 
			
		||||
            new ChangeReportFormatter.Input(u.notes.getChange())
 | 
			
		||||
            ChangeReportFormatter.Input.builder()
 | 
			
		||||
                .setChange(u.notes.getChange())
 | 
			
		||||
                .setSubject(subject)
 | 
			
		||||
                .setDraft(u.replaceOp != null && u.replaceOp.getPatchSet().isDraft())
 | 
			
		||||
                .setEdit(edit)
 | 
			
		||||
                .setPrivate(isPrivate)
 | 
			
		||||
                .setWorkInProgress(wip);
 | 
			
		||||
                .setIsDraft(u.replaceOp != null && u.replaceOp.getPatchSet().isDraft())
 | 
			
		||||
                .setIsEdit(edit)
 | 
			
		||||
                .setIsPrivate(isPrivate)
 | 
			
		||||
                .setIsWorkInProgress(wip)
 | 
			
		||||
                .build();
 | 
			
		||||
        addMessage(changeFormatter.changeUpdated(input));
 | 
			
		||||
      }
 | 
			
		||||
      addMessage("");
 | 
			
		||||
@@ -1678,7 +1682,10 @@ class ReceiveCommits {
 | 
			
		||||
  private boolean requestReplace(
 | 
			
		||||
      ReceiveCommand cmd, boolean checkMergedInto, Change change, RevCommit newCommit) {
 | 
			
		||||
    if (change.getStatus().isClosed()) {
 | 
			
		||||
      reject(cmd, changeFormatter.changeClosed(new ChangeReportFormatter.Input(change)));
 | 
			
		||||
      reject(
 | 
			
		||||
          cmd,
 | 
			
		||||
          changeFormatter.changeClosed(
 | 
			
		||||
              ChangeReportFormatter.Input.builder().setChange(change).build()));
 | 
			
		||||
      return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user