From 2be31e79ef6ecd1d58cb928a85156150c2b17e06 Mon Sep 17 00:00:00 2001 From: nickfelt Date: Wed, 5 Apr 2017 17:27:21 -0700 Subject: [PATCH] Convert DeletionRequest to use @AutoValue.Builder It has 5 parameters, which is pushing it for a static factory method, and we're anticipating adding more for work that Larry is doing. Using a builder is preferable here since it makes it harder to accidentally mis-order the parameters (since @AutoValue's generated constructor is sensitive to parameter ordering). ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=152328220 --- .../batch/DeleteContactsAndHostsAction.java | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/java/google/registry/batch/DeleteContactsAndHostsAction.java b/java/google/registry/batch/DeleteContactsAndHostsAction.java index 52ed03090..ffb5b47fb 100644 --- a/java/google/registry/batch/DeleteContactsAndHostsAction.java +++ b/java/google/registry/batch/DeleteContactsAndHostsAction.java @@ -406,6 +406,16 @@ public class DeleteContactsAndHostsAction implements Runnable { abstract boolean isSuperuser(); abstract TaskHandle task(); + @AutoValue.Builder + abstract static class Builder { + abstract Builder setKey(Key key); + abstract Builder setLastUpdateTime(DateTime lastUpdateTime); + abstract Builder setRequestingClientId(String requestingClientId); + abstract Builder setIsSuperuser(boolean isSuperuser); + abstract Builder setTask(TaskHandle task); + abstract DeletionRequest build(); + } + static Optional createFromTask(TaskHandle task, DateTime now) throws Exception { ImmutableMap params = ImmutableMap.copyOf(task.extractParams()); @@ -422,14 +432,15 @@ public class DeleteContactsAndHostsAction implements Runnable { return Optional.absent(); } return Optional.of( - new AutoValue_DeleteContactsAndHostsAction_DeletionRequest( - resourceKey, - resource.getUpdateAutoTimestamp().getTimestamp(), - checkNotNull( - params.get(PARAM_REQUESTING_CLIENT_ID), "Requesting client id not specified"), - Boolean.valueOf( - checkNotNull(params.get(PARAM_IS_SUPERUSER), "Is superuser not specified")), - task)); + new AutoValue_DeleteContactsAndHostsAction_DeletionRequest.Builder() + .setKey(resourceKey) + .setLastUpdateTime(resource.getUpdateAutoTimestamp().getTimestamp()) + .setRequestingClientId(checkNotNull( + params.get(PARAM_REQUESTING_CLIENT_ID), "Requesting client id not specified")) + .setIsSuperuser(Boolean.valueOf( + checkNotNull(params.get(PARAM_IS_SUPERUSER), "Is superuser not specified"))) + .setTask(task) + .build()); } }