SubmitTypeRecord: Make fields final and document them
These are never assigned after construction, so just make them final to avoid confusion, and populate them directly using static factory methods. Change-Id: I57a8dbd07dcdaa0ac37a9f68d5e4849df30dea4d
This commit is contained in:
parent
37dcf0092e
commit
44fd0aca3b
@ -32,15 +32,29 @@ public class SubmitTypeRecord {
|
||||
}
|
||||
|
||||
public static SubmitTypeRecord OK(SubmitType type) {
|
||||
SubmitTypeRecord r = new SubmitTypeRecord();
|
||||
r.status = Status.OK;
|
||||
r.type = type;
|
||||
return r;
|
||||
return new SubmitTypeRecord(Status.OK, type, null);
|
||||
}
|
||||
|
||||
public Status status;
|
||||
public SubmitType type;
|
||||
public String errorMessage;
|
||||
public static SubmitTypeRecord error(String err) {
|
||||
return new SubmitTypeRecord(SubmitTypeRecord.Status.RULE_ERROR, null, err);
|
||||
}
|
||||
|
||||
/** Status enum value of the record. */
|
||||
public final Status status;
|
||||
|
||||
/** Submit type of the record; never null if {@link #status} is {@code OK}. */
|
||||
public final SubmitType type;
|
||||
|
||||
/**
|
||||
* Submit type of the record; always null if {@link #status} is {@code OK}.
|
||||
*/
|
||||
public final String errorMessage;
|
||||
|
||||
private SubmitTypeRecord(Status status, SubmitType type, String errorMessage) {
|
||||
this.status = status;
|
||||
this.type = type;
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
@ -73,14 +73,7 @@ public class SubmitRuleEvaluator {
|
||||
}
|
||||
|
||||
public static SubmitTypeRecord defaultTypeError() {
|
||||
return createTypeError(DEFAULT_MSG);
|
||||
}
|
||||
|
||||
public static SubmitTypeRecord createTypeError(String err) {
|
||||
SubmitTypeRecord rec = new SubmitTypeRecord();
|
||||
rec.status = SubmitTypeRecord.Status.RULE_ERROR;
|
||||
rec.errorMessage = err;
|
||||
return rec;
|
||||
return SubmitTypeRecord.error(DEFAULT_MSG);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -386,15 +379,17 @@ public class SubmitRuleEvaluator {
|
||||
try {
|
||||
if (control.getChange().getStatus() == Change.Status.DRAFT
|
||||
&& !control.isDraftVisible(cd.db(), cd)) {
|
||||
return createTypeError("Patch set " + patchSet.getId() + " not found");
|
||||
return SubmitTypeRecord.error(
|
||||
"Patch set " + patchSet.getId() + " not found");
|
||||
}
|
||||
if (patchSet.isDraft() && !control.isDraftVisible(cd.db(), cd)) {
|
||||
return createTypeError("Patch set " + patchSet.getId() + " not found");
|
||||
return SubmitTypeRecord.error(
|
||||
"Patch set " + patchSet.getId() + " not found");
|
||||
}
|
||||
} catch (OrmException err) {
|
||||
String msg = "Cannot read patch set " + patchSet.getId();
|
||||
log.error(msg, err);
|
||||
return createTypeError(msg);
|
||||
return SubmitTypeRecord.error(msg);
|
||||
}
|
||||
|
||||
List<Term> results;
|
||||
@ -446,7 +441,7 @@ public class SubmitRuleEvaluator {
|
||||
}
|
||||
return defaultTypeError();
|
||||
} else {
|
||||
return createTypeError(err);
|
||||
return SubmitTypeRecord.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user