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
This commit is contained in:
nickfelt 2017-04-05 17:27:21 -07:00 committed by Ben McIlwain
parent 4606b1d08e
commit 2be31e79ef

View file

@ -406,6 +406,16 @@ public class DeleteContactsAndHostsAction implements Runnable {
abstract boolean isSuperuser(); abstract boolean isSuperuser();
abstract TaskHandle task(); abstract TaskHandle task();
@AutoValue.Builder
abstract static class Builder {
abstract Builder setKey(Key<? extends EppResource> 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<DeletionRequest> createFromTask(TaskHandle task, DateTime now) static Optional<DeletionRequest> createFromTask(TaskHandle task, DateTime now)
throws Exception { throws Exception {
ImmutableMap<String, String> params = ImmutableMap.copyOf(task.extractParams()); ImmutableMap<String, String> params = ImmutableMap.copyOf(task.extractParams());
@ -422,14 +432,15 @@ public class DeleteContactsAndHostsAction implements Runnable {
return Optional.absent(); return Optional.absent();
} }
return Optional.<DeletionRequest>of( return Optional.<DeletionRequest>of(
new AutoValue_DeleteContactsAndHostsAction_DeletionRequest( new AutoValue_DeleteContactsAndHostsAction_DeletionRequest.Builder()
resourceKey, .setKey(resourceKey)
resource.getUpdateAutoTimestamp().getTimestamp(), .setLastUpdateTime(resource.getUpdateAutoTimestamp().getTimestamp())
checkNotNull( .setRequestingClientId(checkNotNull(
params.get(PARAM_REQUESTING_CLIENT_ID), "Requesting client id not specified"), params.get(PARAM_REQUESTING_CLIENT_ID), "Requesting client id not specified"))
Boolean.valueOf( .setIsSuperuser(Boolean.valueOf(
checkNotNull(params.get(PARAM_IS_SUPERUSER), "Is superuser not specified")), checkNotNull(params.get(PARAM_IS_SUPERUSER), "Is superuser not specified")))
task)); .setTask(task)
.build());
} }
} }