mirror of
https://github.com/google/nomulus.git
synced 2025-05-17 01:47:14 +02:00
Replace command.applyTo() with inlined builder operations
These are much easier to understand. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=137446273
This commit is contained in:
parent
b84d7f1fb5
commit
1dbc5f6bb0
28 changed files with 489 additions and 426 deletions
|
@ -14,7 +14,6 @@
|
|||
|
||||
package google.registry.model.host;
|
||||
|
||||
import static com.google.common.collect.Sets.intersection;
|
||||
import static google.registry.util.CollectionUtils.nullSafeImmutableCopy;
|
||||
import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy;
|
||||
|
||||
|
@ -37,27 +36,9 @@ public class HostCommand {
|
|||
@XmlTransient
|
||||
abstract static class HostCreateOrChange extends AbstractSingleResourceCommand
|
||||
implements ResourceCreateOrChange<HostResource.Builder> {
|
||||
/** IP Addresses for this host. Can be null if this is an external host. */
|
||||
@XmlElement(name = "addr")
|
||||
Set<InetAddress> inetAddresses;
|
||||
|
||||
public ImmutableSet<InetAddress> getInetAddresses() {
|
||||
return nullSafeImmutableCopy(inetAddresses);
|
||||
}
|
||||
|
||||
public String getFullyQualifiedHostName() {
|
||||
return getTargetId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyTo(HostResource.Builder builder) {
|
||||
if (getFullyQualifiedHostName() != null) {
|
||||
builder.setFullyQualifiedHostName(getFullyQualifiedHostName());
|
||||
}
|
||||
if (getInetAddresses() != null) {
|
||||
builder.setInetAddresses(getInetAddresses());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -67,7 +48,15 @@ public class HostCommand {
|
|||
@XmlType(propOrder = {"targetId", "inetAddresses" })
|
||||
@XmlRootElement
|
||||
public static class Create
|
||||
extends HostCreateOrChange implements ResourceCreateOrChange<HostResource.Builder> {}
|
||||
extends HostCreateOrChange implements ResourceCreateOrChange<HostResource.Builder> {
|
||||
/** IP Addresses for this host. Can be null if this is an external host. */
|
||||
@XmlElement(name = "addr")
|
||||
Set<InetAddress> inetAddresses;
|
||||
|
||||
public ImmutableSet<InetAddress> getInetAddresses() {
|
||||
return nullSafeImmutableCopy(inetAddresses);
|
||||
}
|
||||
}
|
||||
|
||||
/** A delete command for a {@link HostResource}. */
|
||||
@XmlRootElement
|
||||
|
@ -124,18 +113,6 @@ public class HostCommand {
|
|||
}
|
||||
|
||||
/** The inner change type on a host update command. */
|
||||
@XmlType(propOrder = {"targetId", "inetAddresses" })
|
||||
public static class Change extends HostCreateOrChange {}
|
||||
|
||||
@Override
|
||||
public void applyTo(HostResource.Builder builder) throws AddRemoveSameValueException {
|
||||
super.applyTo(builder);
|
||||
if (!intersection(getInnerAdd().getInetAddresses(), getInnerRemove().getInetAddresses())
|
||||
.isEmpty()) {
|
||||
throw new AddRemoveSameValueException();
|
||||
}
|
||||
builder.addInetAddresses(getInnerAdd().getInetAddresses());
|
||||
builder.removeInetAddresses(getInnerRemove().getInetAddresses());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue