ChangeJson: Extract a method for checking ListChangesOptions
Makes it more likely for multiple flag checks to fit on a single line. Change-Id: I0eda3270e6fc1e45db85dfb551f9297328d5f97b
This commit is contained in:
@@ -206,8 +206,7 @@ public class ChangeJson {
|
||||
|
||||
public List<List<ChangeInfo>> formatList2(List<List<ChangeData>> in)
|
||||
throws OrmException {
|
||||
accountLoader =
|
||||
accountLoaderFactory.create(options.contains(DETAILED_ACCOUNTS));
|
||||
accountLoader = accountLoaderFactory.create(has(DETAILED_ACCOUNTS));
|
||||
List<List<ChangeInfo>> res = Lists.newArrayListWithCapacity(in.size());
|
||||
for (List<ChangeData> changes : in) {
|
||||
ChangeData.ensureChangeLoaded(db, changes);
|
||||
@@ -219,6 +218,10 @@ public class ChangeJson {
|
||||
return res;
|
||||
}
|
||||
|
||||
private boolean has(ListChangesOption option) {
|
||||
return options.contains(option);
|
||||
}
|
||||
|
||||
private List<ChangeInfo> toChangeInfo(List<ChangeData> changes)
|
||||
throws OrmException {
|
||||
List<ChangeInfo> info = Lists.newArrayListWithCapacity(changes.size());
|
||||
@@ -245,15 +248,14 @@ public class ChangeJson {
|
||||
out._sortkey = in.getSortKey();
|
||||
out.starred = user.getStarredChanges().contains(in.getId()) ? true : null;
|
||||
out.reviewed = in.getStatus().isOpen() && isChangeReviewed(cd) ? true : null;
|
||||
out.labels = labelsFor(cd, options.contains(LABELS),
|
||||
options.contains(DETAILED_LABELS));
|
||||
if (out.labels != null && options.contains(DETAILED_LABELS)) {
|
||||
out.labels = labelsFor(cd, has(LABELS), has(DETAILED_LABELS));
|
||||
if (out.labels != null && has(DETAILED_LABELS)) {
|
||||
out.permitted_labels = permittedLabels(cd);
|
||||
out.removable_reviewers = removableReviewers(cd, out.labels.values());
|
||||
}
|
||||
out.finish();
|
||||
|
||||
if (options.contains(ALL_REVISIONS) || options.contains(CURRENT_REVISION)
|
||||
if (has(ALL_REVISIONS) || has(CURRENT_REVISION)
|
||||
|| cd.getLimitedPatchSets() != null) {
|
||||
out.revisions = revisions(cd);
|
||||
if (out.revisions != null) {
|
||||
@@ -683,7 +685,7 @@ public class ChangeJson {
|
||||
}
|
||||
|
||||
Collection<PatchSet> src;
|
||||
if (cd.getLimitedPatchSets() != null || options.contains(ALL_REVISIONS)) {
|
||||
if (cd.getLimitedPatchSets() != null || has(ALL_REVISIONS)) {
|
||||
src = cd.patches(db);
|
||||
} else {
|
||||
src = Collections.singletonList(cd.currentPatchSet(db));
|
||||
@@ -705,8 +707,7 @@ public class ChangeJson {
|
||||
out.draft = in.isDraft() ? true : null;
|
||||
out.fetch = makeFetchMap(cd, in);
|
||||
|
||||
if (options.contains(ALL_COMMITS)
|
||||
|| (out.isCurrent && options.contains(CURRENT_COMMIT))) {
|
||||
if (has(ALL_COMMITS) || (out.isCurrent && has(CURRENT_COMMIT))) {
|
||||
try {
|
||||
PatchSetInfo info = patchSetInfoFactory.get(db.get(), in.getId());
|
||||
out.commit = new CommitInfo();
|
||||
@@ -727,8 +728,7 @@ public class ChangeJson {
|
||||
}
|
||||
}
|
||||
|
||||
if (options.contains(ALL_FILES)
|
||||
|| (out.isCurrent && options.contains(CURRENT_FILES))) {
|
||||
if (has(ALL_FILES) || (out.isCurrent && has(CURRENT_FILES))) {
|
||||
PatchList list;
|
||||
try {
|
||||
list = patchListCache.get(cd.change(db), in);
|
||||
|
||||
Reference in New Issue
Block a user