mirror of
https://github.com/google/nomulus.git
synced 2025-08-01 23:42:12 +02:00
Convert a couple of @AutoValue classes to Java 15 Records (#2327)
This is the start of a long and low priority migration, but for now I wanted to do a couple of them just to see what it looks like. This also demonstrates the pattern for use of an @AutoBuilder to replace an @AutoValue.Builder. See https://github.com/google/auto/blob/main/value/userguide/records.md#builders for full details on that.
This commit is contained in:
parent
1f516e34b6
commit
670941bec8
2 changed files with 16 additions and 38 deletions
|
@ -14,6 +14,7 @@
|
|||
|
||||
package google.registry.flows.custom;
|
||||
|
||||
import com.google.auto.value.AutoBuilder;
|
||||
import com.google.auto.value.AutoValue;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import google.registry.flows.EppException;
|
||||
|
@ -81,30 +82,23 @@ public class DomainRenewFlowCustomLogic extends BaseFlowCustomLogic {
|
|||
}
|
||||
|
||||
/** A class to encapsulate parameters for a call to {@link #afterValidation}. */
|
||||
@AutoValue
|
||||
public abstract static class AfterValidationParameters extends ImmutableObject {
|
||||
|
||||
public abstract Domain existingDomain();
|
||||
|
||||
public abstract int years();
|
||||
|
||||
public abstract DateTime now();
|
||||
public record AfterValidationParameters(Domain existingDomain, int years, DateTime now) {
|
||||
|
||||
public static Builder newBuilder() {
|
||||
return new AutoValue_DomainRenewFlowCustomLogic_AfterValidationParameters.Builder();
|
||||
return new AutoBuilder_DomainRenewFlowCustomLogic_AfterValidationParameters_Builder();
|
||||
}
|
||||
|
||||
/** Builder for {@link AfterValidationParameters}. */
|
||||
@AutoValue.Builder
|
||||
public abstract static class Builder {
|
||||
@AutoBuilder
|
||||
public interface Builder {
|
||||
|
||||
public abstract Builder setExistingDomain(Domain existingDomain);
|
||||
Builder setExistingDomain(Domain existingDomain);
|
||||
|
||||
public abstract Builder setYears(int years);
|
||||
Builder setYears(int years);
|
||||
|
||||
public abstract Builder setNow(DateTime now);
|
||||
Builder setNow(DateTime now);
|
||||
|
||||
public abstract AfterValidationParameters build();
|
||||
AfterValidationParameters build();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@ import static google.registry.persistence.transaction.TransactionManagerFactory.
|
|||
import static google.registry.util.DateTimeUtils.isAtOrAfter;
|
||||
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
|
@ -129,26 +128,11 @@ public class Lock extends ImmutableObject implements Serializable {
|
|||
return String.format("%s-%s", scope, resourceName);
|
||||
}
|
||||
|
||||
@AutoValue
|
||||
abstract static class AcquireResult {
|
||||
public abstract DateTime transactionTime();
|
||||
|
||||
@Nullable
|
||||
public abstract Lock existingLock();
|
||||
|
||||
@Nullable
|
||||
public abstract Lock newLock();
|
||||
|
||||
public abstract LockState lockState();
|
||||
|
||||
public static AcquireResult create(
|
||||
DateTime transactionTime,
|
||||
@Nullable Lock existingLock,
|
||||
@Nullable Lock newLock,
|
||||
LockState lockState) {
|
||||
return new AutoValue_Lock_AcquireResult(transactionTime, existingLock, newLock, lockState);
|
||||
}
|
||||
}
|
||||
record AcquireResult(
|
||||
DateTime transactionTime,
|
||||
@Nullable Lock existingLock,
|
||||
@Nullable Lock newLock,
|
||||
LockState lockState) {}
|
||||
|
||||
private static void logAcquireResult(AcquireResult acquireResult) {
|
||||
try {
|
||||
|
@ -204,13 +188,13 @@ public class Lock extends ImmutableObject implements Serializable {
|
|||
lockState = LockState.TIMED_OUT;
|
||||
} else {
|
||||
lockState = LockState.IN_USE;
|
||||
return AcquireResult.create(now, lock, null, lockState);
|
||||
return new AcquireResult(now, lock, null, lockState);
|
||||
}
|
||||
|
||||
Lock newLock = create(resourceName, scope, now, leaseLength);
|
||||
tm().put(newLock);
|
||||
|
||||
return AcquireResult.create(now, lock, newLock, lockState);
|
||||
return new AcquireResult(now, lock, newLock, lockState);
|
||||
};
|
||||
AcquireResult acquireResult = tm().transact(lockAcquirer);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue