Run automatic Java 8 conversion over codebase

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=171174380
This commit is contained in:
mcilwain 2017-10-05 10:48:38 -07:00 committed by Ben McIlwain
parent 44df5da771
commit 5edb7935ed
190 changed files with 2312 additions and 3096 deletions

View file

@ -14,8 +14,7 @@
package google.registry.flows.domain;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.getOnlyElement;
import static com.google.common.collect.MoreCollectors.onlyElement;
import static google.registry.flows.FlowUtils.validateClientIsLoggedIn;
import static google.registry.flows.ResourceFlowUtils.verifyResourceDoesNotExist;
import static google.registry.flows.domain.DomainFlowUtils.cloneAndLinkReferences;
@ -39,6 +38,7 @@ import static google.registry.util.DateTimeUtils.leapSafeAddYears;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Streams;
import com.google.common.net.InternetDomainName;
import com.googlecode.objectify.Key;
import dagger.Lazy;
@ -212,7 +212,10 @@ public class DomainAllocateFlow implements TransactionalFlow {
private <T extends ImmutableObject> T getOnly(
Iterable<? extends ImmutableObject> objects, Class<T> clazz) {
return getOnlyElement(filter(objects, clazz));
return Streams.stream(objects)
.filter(clazz::isInstance)
.map(clazz::cast)
.collect(onlyElement());
}
private void verifyIsSuperuser() throws OnlySuperuserCanAllocateException {

View file

@ -14,6 +14,7 @@
package google.registry.flows.domain;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.Iterables.getOnlyElement;
import static google.registry.flows.FlowUtils.persistEntityChanges;
import static google.registry.flows.FlowUtils.validateClientIsLoggedIn;
@ -43,8 +44,6 @@ import static google.registry.model.index.DomainApplicationIndex.loadActiveAppli
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.model.registry.label.ReservedList.matchesAnchorTenantReservation;
import com.google.common.base.Function;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.net.InternetDomainName;
@ -94,7 +93,6 @@ import google.registry.model.registry.Registry;
import google.registry.model.registry.Registry.TldState;
import google.registry.model.reporting.HistoryEntry;
import google.registry.model.reporting.IcannReportingTypes.ActivityReportField;
import google.registry.model.smd.AbstractSignedMark;
import google.registry.model.smd.EncodedSignedMark;
import javax.inject.Inject;
import org.joda.time.DateTime;
@ -244,32 +242,31 @@ public final class DomainApplicationCreateFlow implements TransactionalFlow {
.setDomainName(domainName)
.setYears(years)
.build());
DomainApplication newApplication = new DomainApplication.Builder()
.setCreationTrid(trid)
.setCreationClientId(clientId)
.setPersistedCurrentSponsorClientId(clientId)
.setRepoId(createDomainRepoId(ObjectifyService.allocateId(), tld))
.setLaunchNotice(launchCreate == null ? null : launchCreate.getNotice())
.setIdnTableName(idnTableName)
.setPhase(launchCreate.getPhase())
.setPeriod(command.getPeriod())
.setApplicationStatus(ApplicationStatus.VALIDATED)
.addStatusValue(StatusValue.PENDING_CREATE)
.setDsData(secDnsCreate == null ? null : secDnsCreate.getDsData())
.setRegistrant(command.getRegistrant())
.setAuthInfo(command.getAuthInfo())
.setFullyQualifiedDomainName(targetId)
.setNameservers(command.getNameservers())
.setContacts(command.getContacts())
.setEncodedSignedMarks(FluentIterable
.from(launchCreate.getSignedMarks())
.transform(new Function<AbstractSignedMark, EncodedSignedMark>() {
@Override
public EncodedSignedMark apply(AbstractSignedMark abstractSignedMark) {
return (EncodedSignedMark) abstractSignedMark;
}})
.toList())
.build();
DomainApplication newApplication =
new DomainApplication.Builder()
.setCreationTrid(trid)
.setCreationClientId(clientId)
.setPersistedCurrentSponsorClientId(clientId)
.setRepoId(createDomainRepoId(ObjectifyService.allocateId(), tld))
.setLaunchNotice(launchCreate == null ? null : launchCreate.getNotice())
.setIdnTableName(idnTableName)
.setPhase(launchCreate.getPhase())
.setPeriod(command.getPeriod())
.setApplicationStatus(ApplicationStatus.VALIDATED)
.addStatusValue(StatusValue.PENDING_CREATE)
.setDsData(secDnsCreate == null ? null : secDnsCreate.getDsData())
.setRegistrant(command.getRegistrant())
.setAuthInfo(command.getAuthInfo())
.setFullyQualifiedDomainName(targetId)
.setNameservers(command.getNameservers())
.setContacts(command.getContacts())
.setEncodedSignedMarks(
launchCreate
.getSignedMarks()
.stream()
.map(abstractSignedMark -> (EncodedSignedMark) abstractSignedMark)
.collect(toImmutableList()))
.build();
HistoryEntry historyEntry =
buildHistoryEntry(newApplication.getRepoId(), command.getPeriod(), now);
ImmutableSet.Builder<ImmutableObject> entitiesToSave = new ImmutableSet.Builder<>();

View file

@ -28,8 +28,6 @@ import static google.registry.model.registry.label.ReservationType.getTypeOfHigh
import static google.registry.pricing.PricingEngineProxy.isDomainPremium;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
@ -46,7 +44,6 @@ import google.registry.flows.annotations.ReportingSpec;
import google.registry.flows.custom.DomainCheckFlowCustomLogic;
import google.registry.flows.custom.DomainCheckFlowCustomLogic.BeforeResponseParameters;
import google.registry.flows.custom.DomainCheckFlowCustomLogic.BeforeResponseReturnData;
import google.registry.model.domain.DomainApplication;
import google.registry.model.domain.DomainCommand.Check;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.fee.FeeCheckCommandExtension;
@ -176,12 +173,9 @@ public final class DomainCheckFlow implements Flow {
}
Registry registry = Registry.get(domainName.parent().toString());
if (PENDING_ALLOCATION_TLD_STATES.contains(registry.getTldState(now))
&& FluentIterable.from(loadActiveApplicationsByDomainName(domainName.toString(), now))
.anyMatch(new Predicate<DomainApplication>() {
@Override
public boolean apply(DomainApplication input) {
return !input.getApplicationStatus().isFinalStatus();
}})) {
&& loadActiveApplicationsByDomainName(domainName.toString(), now)
.stream()
.anyMatch(input -> !input.getApplicationStatus().isFinalStatus())) {
return Optional.of("Pending allocation");
}
ImmutableSet<ReservationType> reservationTypes = getReservationTypes(domainName);

View file

@ -41,13 +41,12 @@ import static google.registry.util.DomainNameUtils.ACE_PREFIX;
import com.google.common.base.CharMatcher;
import com.google.common.base.Joiner;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.base.Splitter;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.google.common.collect.Streams;
import com.google.common.net.InternetDomainName;
import com.googlecode.objectify.Key;
import google.registry.flows.EppException;
@ -940,24 +939,22 @@ public class DomainFlowUtils {
.order("modificationTime")
.list();
Optional<HistoryEntry> entryToCancel =
FluentIterable.from(recentHistoryEntries)
.filter(
new Predicate<HistoryEntry>() {
@Override
public boolean apply(HistoryEntry historyEntry) {
// Look for add and renew transaction records that have yet to be reported
for (DomainTransactionRecord record :
historyEntry.getDomainTransactionRecords()) {
if (cancelableFields.contains(record.getReportField())
&& record.getReportingTime().isAfter(now)) {
return true;
}
}
return false;
}
})
// We only want to cancel out the most recent add or renewal
.last();
Optional.fromJavaUtil(
Streams.findLast(
recentHistoryEntries
.stream()
.filter(
historyEntry -> {
// Look for add and renew transaction records that have yet to be reported
for (DomainTransactionRecord record :
historyEntry.getDomainTransactionRecords()) {
if (cancelableFields.contains(record.getReportField())
&& record.getReportingTime().isAfter(now)) {
return true;
}
}
return false;
})));
ImmutableSet.Builder<DomainTransactionRecord> recordsBuilder = new ImmutableSet.Builder<>();
if (entryToCancel.isPresent()) {
for (DomainTransactionRecord record : entryToCancel.get().getDomainTransactionRecords()) {

View file

@ -14,8 +14,8 @@
package google.registry.flows.domain;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.getOnlyElement;
import static com.google.common.collect.MoreCollectors.onlyElement;
import static google.registry.util.DateTimeUtils.END_OF_TIME;
import com.google.common.base.Optional;
@ -61,14 +61,29 @@ public final class DomainTransferUtils {
if (transferPeriod.getValue() != 0) {
// Unless superuser sets period to 0, add a transfer billing event.
transferDataBuilder.setServerApproveBillingEvent(
Key.create(getOnlyElement(filter(serverApproveEntities, BillingEvent.OneTime.class))));
Key.create(
serverApproveEntities
.stream()
.filter(BillingEvent.OneTime.class::isInstance)
.map(BillingEvent.OneTime.class::cast)
.collect(onlyElement())));
}
return transferDataBuilder
.setTransferStatus(TransferStatus.PENDING)
.setServerApproveAutorenewEvent(Key.create(
getOnlyElement(filter(serverApproveEntities, BillingEvent.Recurring.class))))
.setServerApproveAutorenewPollMessage(Key.create(
getOnlyElement(filter(serverApproveEntities, PollMessage.Autorenew.class))))
.setServerApproveAutorenewEvent(
Key.create(
serverApproveEntities
.stream()
.filter(BillingEvent.Recurring.class::isInstance)
.map(BillingEvent.Recurring.class::cast)
.collect(onlyElement())))
.setServerApproveAutorenewPollMessage(
Key.create(
serverApproveEntities
.stream()
.filter(PollMessage.Autorenew.class::isInstance)
.map(PollMessage.Autorenew.class::cast)
.collect(onlyElement())))
.setServerApproveEntities(serverApproveEntityKeys.build())
.setTransferPeriod(transferPeriod)
.build();

View file

@ -14,7 +14,7 @@
package google.registry.flows.domain;
import static com.google.common.collect.Iterables.concat;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static google.registry.util.CollectionUtils.nullToEmpty;
import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy;
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
@ -26,6 +26,7 @@ import google.registry.model.domain.fee.BaseFee;
import google.registry.model.domain.fee.BaseFee.FeeType;
import google.registry.model.domain.fee.Credit;
import google.registry.model.domain.fee.Fee;
import java.util.stream.Stream;
import org.joda.money.CurrencyUnit;
import org.joda.money.Money;
@ -102,7 +103,7 @@ public class FeesAndCredits extends ImmutableObject implements Buildable {
/** Returns all fees and credits for the event. */
public ImmutableList<BaseFee> getFeesAndCredits() {
return ImmutableList.copyOf(concat(getFees(), getCredits()));
return Stream.concat(getFees().stream(), getCredits().stream()).collect(toImmutableList());
}
@Override