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