Convert PatchSetApproval to AutoValue

The public API of PatchSetApproval remains the same with respect to
nullability: getTag is a non-nullable Optional, and getRealAccountId
falls back to getAccountId if setRealAccountId was never called. In the
old implementation, these fields were nullable internally, due to
ReviewDb constraints; AutoValue has no such constraints, so they are
plain non-nullable fields. Instead, populating the default values is
done via logic in the builder.

The no-arg defensive copy method is no longer required, since
PatchSetApproval is immutable. copyWithPatchSet is still useful as a
shortcut, because swapping out just the PatchSet.Id nested in the
PatchSetApproval.Key is annoying.

Leave method names the same so that substantive code changes are easier
to review.

Change-Id: I342f87e9a7cd209afa6e4a6d0158a1f3a5d11360
This commit is contained in:
Dave Borowitz
2019-04-30 11:16:53 -07:00
parent f0f4c50b57
commit bbbcc59d7e
16 changed files with 239 additions and 297 deletions

View File

@@ -62,7 +62,6 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Predicate;
@@ -338,12 +337,7 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
public ImmutableListMultimap<PatchSet.Id, PatchSetApproval> getApprovals() {
if (approvals == null) {
ImmutableListMultimap.Builder<PatchSet.Id, PatchSetApproval> b =
ImmutableListMultimap.builder();
for (Map.Entry<PatchSet.Id, PatchSetApproval> e : state.approvals()) {
b.put(e.getKey(), e.getValue().copy());
}
approvals = b.build();
approvals = ImmutableListMultimap.copyOf(state.approvals());
}
return approvals;
}