ChangeData: Use java.util.Optional
Change-Id: I2cd9978e236d0060657d49a0c3ae402f6aac454c
This commit is contained in:
@@ -40,7 +40,6 @@ import static java.util.stream.Collectors.toList;
|
|||||||
import com.google.auto.value.AutoValue;
|
import com.google.auto.value.AutoValue;
|
||||||
import com.google.common.base.Joiner;
|
import com.google.common.base.Joiner;
|
||||||
import com.google.common.base.MoreObjects;
|
import com.google.common.base.MoreObjects;
|
||||||
import com.google.common.base.Optional;
|
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
import com.google.common.collect.FluentIterable;
|
import com.google.common.collect.FluentIterable;
|
||||||
import com.google.common.collect.HashBasedTable;
|
import com.google.common.collect.HashBasedTable;
|
||||||
@@ -137,6 +136,7 @@ import java.util.HashSet;
|
|||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
@@ -266,7 +266,7 @@ public class ChangeJson {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ChangeInfo format(ChangeData cd) throws OrmException {
|
public ChangeInfo format(ChangeData cd) throws OrmException {
|
||||||
return format(cd, Optional.<PatchSet.Id> absent(), true);
|
return format(cd, Optional.empty(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ChangeInfo format(ChangeData cd, Optional<PatchSet.Id> limitToPsId,
|
private ChangeInfo format(ChangeData cd, Optional<PatchSet.Id> limitToPsId,
|
||||||
@@ -356,7 +356,7 @@ public class ChangeJson {
|
|||||||
ChangeInfo i = out.get(cd.getId());
|
ChangeInfo i = out.get(cd.getId());
|
||||||
if (i == null) {
|
if (i == null) {
|
||||||
try {
|
try {
|
||||||
i = toChangeInfo(cd, Optional.<PatchSet.Id> absent());
|
i = toChangeInfo(cd, Optional.empty());
|
||||||
} catch (PatchListNotAvailableException | GpgException | OrmException
|
} catch (PatchListNotAvailableException | GpgException | OrmException
|
||||||
| IOException | RuntimeException e) {
|
| IOException | RuntimeException e) {
|
||||||
if (has(CHECK)) {
|
if (has(CHECK)) {
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import static java.nio.charset.StandardCharsets.UTF_8;
|
|||||||
import static java.util.stream.Collectors.toSet;
|
import static java.util.stream.Collectors.toSet;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Optional;
|
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
@@ -41,7 +40,6 @@ import com.google.gerrit.server.index.FieldType;
|
|||||||
import com.google.gerrit.server.index.SchemaUtil;
|
import com.google.gerrit.server.index.SchemaUtil;
|
||||||
import com.google.gerrit.server.notedb.ReviewerStateInternal;
|
import com.google.gerrit.server.notedb.ReviewerStateInternal;
|
||||||
import com.google.gerrit.server.query.change.ChangeData;
|
import com.google.gerrit.server.query.change.ChangeData;
|
||||||
import com.google.gerrit.server.query.change.ChangeData.ChangedLines;
|
|
||||||
import com.google.gerrit.server.query.change.ChangeQueryBuilder;
|
import com.google.gerrit.server.query.change.ChangeQueryBuilder;
|
||||||
import com.google.gerrit.server.query.change.ChangeStatusPredicate;
|
import com.google.gerrit.server.query.change.ChangeStatusPredicate;
|
||||||
import com.google.gwtorm.protobuf.CodecFactory;
|
import com.google.gwtorm.protobuf.CodecFactory;
|
||||||
@@ -632,10 +630,9 @@ public class ChangeField {
|
|||||||
@Override
|
@Override
|
||||||
public Integer get(ChangeData input, FillArgs args)
|
public Integer get(ChangeData input, FillArgs args)
|
||||||
throws OrmException {
|
throws OrmException {
|
||||||
Optional<ChangedLines> changedLines = input.changedLines();
|
return input.changedLines()
|
||||||
return changedLines.isPresent()
|
.map(c -> c.insertions + c.deletions)
|
||||||
? changedLines.get().insertions + changedLines.get().deletions
|
.orElse(null);
|
||||||
: null;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import static com.google.gerrit.server.ApprovalsUtil.sortApprovals;
|
|||||||
|
|
||||||
import com.google.auto.value.AutoValue;
|
import com.google.auto.value.AutoValue;
|
||||||
import com.google.common.base.MoreObjects;
|
import com.google.common.base.MoreObjects;
|
||||||
import com.google.common.base.Optional;
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.collect.FluentIterable;
|
import com.google.common.collect.FluentIterable;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
@@ -92,6 +91,7 @@ import java.util.HashSet;
|
|||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class ChangeData {
|
public class ChangeData {
|
||||||
@@ -611,12 +611,12 @@ public class ChangeData {
|
|||||||
Optional<PatchList> r = patchLists.get(psId);
|
Optional<PatchList> r = patchLists.get(psId);
|
||||||
if (r == null) {
|
if (r == null) {
|
||||||
if (!lazyLoad) {
|
if (!lazyLoad) {
|
||||||
return Optional.absent();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
r = Optional.of(patchListCache.get(c, ps));
|
r = Optional.of(patchListCache.get(c, ps));
|
||||||
} catch (PatchListNotAvailableException e) {
|
} catch (PatchListNotAvailableException e) {
|
||||||
r = Optional.absent();
|
r = Optional.empty();
|
||||||
}
|
}
|
||||||
patchLists.put(psId, r);
|
patchLists.put(psId, r);
|
||||||
}
|
}
|
||||||
@@ -631,12 +631,12 @@ public class ChangeData {
|
|||||||
Optional<DiffSummary> r = diffSummaries.get(psId);
|
Optional<DiffSummary> r = diffSummaries.get(psId);
|
||||||
if (r == null) {
|
if (r == null) {
|
||||||
if (!lazyLoad) {
|
if (!lazyLoad) {
|
||||||
return Optional.absent();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
r = Optional.of(patchListCache.getDiffSummary(c, ps));
|
r = Optional.of(patchListCache.getDiffSummary(c, ps));
|
||||||
} catch (PatchListNotAvailableException e) {
|
} catch (PatchListNotAvailableException e) {
|
||||||
r = Optional.absent();
|
r = Optional.empty();
|
||||||
}
|
}
|
||||||
diffSummaries.put(psId, r);
|
diffSummaries.put(psId, r);
|
||||||
}
|
}
|
||||||
@@ -646,24 +646,20 @@ public class ChangeData {
|
|||||||
private Optional<ChangedLines> computeChangedLines() throws OrmException {
|
private Optional<ChangedLines> computeChangedLines() throws OrmException {
|
||||||
Change c = change();
|
Change c = change();
|
||||||
if (c == null) {
|
if (c == null) {
|
||||||
return Optional.absent();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
PatchSet ps = currentPatchSet();
|
PatchSet ps = currentPatchSet();
|
||||||
if (ps == null) {
|
if (ps == null) {
|
||||||
return Optional.absent();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
Optional<PatchList> p = getPatchList(c, ps);
|
return getPatchList(c, ps).map(
|
||||||
if (!p.isPresent()) {
|
p -> new ChangedLines(p.getInsertions(), p.getDeletions()));
|
||||||
return Optional.absent();
|
|
||||||
}
|
|
||||||
return Optional.of(
|
|
||||||
new ChangedLines(p.get().getInsertions(), p.get().getDeletions()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<ChangedLines> changedLines() throws OrmException {
|
public Optional<ChangedLines> changedLines() throws OrmException {
|
||||||
if (changedLines == null) {
|
if (changedLines == null) {
|
||||||
if (!lazyLoad) {
|
if (!lazyLoad) {
|
||||||
return Optional.absent();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
changedLines = computeChangedLines();
|
changedLines = computeChangedLines();
|
||||||
}
|
}
|
||||||
@@ -675,7 +671,7 @@ public class ChangeData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setNoChangedLines() {
|
public void setNoChangedLines() {
|
||||||
changedLines = Optional.absent();
|
changedLines = Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Change.Id getId() {
|
public Change.Id getId() {
|
||||||
@@ -952,12 +948,9 @@ public class ChangeData {
|
|||||||
*/
|
*/
|
||||||
public Optional<PatchSetApproval> getSubmitApproval()
|
public Optional<PatchSetApproval> getSubmitApproval()
|
||||||
throws OrmException {
|
throws OrmException {
|
||||||
for (PatchSetApproval psa : currentApprovals()) {
|
return currentApprovals().stream()
|
||||||
if (psa.isLegacySubmit()) {
|
.filter(PatchSetApproval::isLegacySubmit)
|
||||||
return Optional.fromNullable(psa);
|
.findFirst();
|
||||||
}
|
|
||||||
}
|
|
||||||
return Optional.absent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReviewerSet reviewers() throws OrmException {
|
public ReviewerSet reviewers() throws OrmException {
|
||||||
|
|||||||
Reference in New Issue
Block a user