From 2c96633a20caaa846cffb732099a50b1f6490029 Mon Sep 17 00:00:00 2001 From: guyben Date: Wed, 20 Dec 2017 12:06:39 -0800 Subject: [PATCH] Replace Stream.concat with Streams.concat Stream.concat only accepts 2 parameters. Streams.concat on the other hand accepts any number of parameters. Moving to Streams.concat for all uses (2 or more) makes sense for uniformity and convenience reasons. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=179716648 --- java/google/registry/backup/RestoreCommitLogsAction.java | 3 ++- java/google/registry/flows/domain/FeesAndCredits.java | 4 ++-- java/google/registry/model/domain/DomainBase.java | 4 ++-- java/google/registry/model/ofy/ObjectifyService.java | 4 ++-- .../registry/tools/server/KillAllCommitLogsAction.java | 3 ++- java/google/registry/tools/server/ListObjectsAction.java | 5 +++-- .../registry/flows/domain/DomainTransferApproveFlowTest.java | 5 +++-- .../registry/flows/domain/DomainTransferRequestFlowTest.java | 5 +++-- .../google/registry/model/domain/DomainResourceTest.java | 4 ++-- 9 files changed, 21 insertions(+), 16 deletions(-) diff --git a/java/google/registry/backup/RestoreCommitLogsAction.java b/java/google/registry/backup/RestoreCommitLogsAction.java index 2a504962e..72ad1db9c 100644 --- a/java/google/registry/backup/RestoreCommitLogsAction.java +++ b/java/google/registry/backup/RestoreCommitLogsAction.java @@ -28,6 +28,7 @@ import com.google.appengine.tools.cloudstorage.GcsFileMetadata; import com.google.appengine.tools.cloudstorage.GcsService; import com.google.common.collect.Lists; import com.google.common.collect.PeekingIterator; +import com.google.common.collect.Streams; import com.googlecode.objectify.Key; import com.googlecode.objectify.Result; import com.googlecode.objectify.util.ResultNow; @@ -116,7 +117,7 @@ public class RestoreCommitLogsAction implements Runnable { } // Restore the CommitLogCheckpointRoot and CommitLogBuckets. saveOfy( - Stream.concat( + Streams.concat( bucketTimestamps .entrySet() .stream() diff --git a/java/google/registry/flows/domain/FeesAndCredits.java b/java/google/registry/flows/domain/FeesAndCredits.java index e9daa7d84..8b85c0d89 100644 --- a/java/google/registry/flows/domain/FeesAndCredits.java +++ b/java/google/registry/flows/domain/FeesAndCredits.java @@ -20,13 +20,13 @@ import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy; import static google.registry.util.PreconditionsUtils.checkArgumentNotNull; import com.google.common.collect.ImmutableList; +import com.google.common.collect.Streams; import google.registry.model.Buildable; import google.registry.model.ImmutableObject; 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; @@ -103,7 +103,7 @@ public class FeesAndCredits extends ImmutableObject implements Buildable { /** Returns all fees and credits for the event. */ public ImmutableList getFeesAndCredits() { - return Stream.concat(getFees().stream(), getCredits().stream()).collect(toImmutableList()); + return Streams.concat(getFees().stream(), getCredits().stream()).collect(toImmutableList()); } @Override diff --git a/java/google/registry/model/domain/DomainBase.java b/java/google/registry/model/domain/DomainBase.java index e777ed50d..637855ea1 100644 --- a/java/google/registry/model/domain/DomainBase.java +++ b/java/google/registry/model/domain/DomainBase.java @@ -32,6 +32,7 @@ import static google.registry.util.PreconditionsUtils.checkArgumentNotNull; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.Ordering; +import com.google.common.collect.Streams; import com.googlecode.objectify.Key; import com.googlecode.objectify.annotation.Entity; import com.googlecode.objectify.annotation.IgnoreSave; @@ -46,7 +47,6 @@ import google.registry.model.domain.secdns.DelegationSignerData; import google.registry.model.host.HostResource; import java.util.Set; import java.util.function.Predicate; -import java.util.stream.Stream; /** Shared base class for {@link DomainResource} and {@link DomainApplication}. */ @ReportedOn @@ -250,7 +250,7 @@ public abstract class DomainBase extends EppResource { checkArgument(contacts.stream().noneMatch(IS_REGISTRANT), "Registrant cannot be a contact"); // Replace the non-registrant contacts inside allContacts. getInstance().allContacts = - Stream.concat( + Streams.concat( nullToEmpty(getInstance().allContacts).stream().filter(IS_REGISTRANT), contacts.stream()) .collect(toImmutableSet()); diff --git a/java/google/registry/model/ofy/ObjectifyService.java b/java/google/registry/model/ofy/ObjectifyService.java index f2ee8800a..bd1995d73 100644 --- a/java/google/registry/model/ofy/ObjectifyService.java +++ b/java/google/registry/model/ofy/ObjectifyService.java @@ -25,6 +25,7 @@ import com.google.appengine.api.datastore.DatastoreServiceFactory; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Streams; import com.googlecode.objectify.Key; import com.googlecode.objectify.Objectify; import com.googlecode.objectify.ObjectifyFactory; @@ -45,7 +46,6 @@ import google.registry.model.translators.InetAddressTranslatorFactory; import google.registry.model.translators.ReadableInstantUtcTranslatorFactory; import google.registry.model.translators.UpdateAutoTimestampTranslatorFactory; import java.util.concurrent.atomic.AtomicLong; -import java.util.stream.Stream; /** * An instance of Ofy, obtained via {@code #ofy()}, should be used to access all persistable @@ -140,7 +140,7 @@ public class ObjectifyService { // This is future-proofing for Objectify 5.x where the registration logic gets less lenient. for (Class clazz : - Stream.concat( + Streams.concat( entityClasses.stream().filter(hasAnnotation(Entity.class)), entityClasses.stream().filter(hasAnnotation(Entity.class).negate())) .collect(toImmutableSet())) { diff --git a/java/google/registry/tools/server/KillAllCommitLogsAction.java b/java/google/registry/tools/server/KillAllCommitLogsAction.java index 82262c8d1..fc3aa4e40 100644 --- a/java/google/registry/tools/server/KillAllCommitLogsAction.java +++ b/java/google/registry/tools/server/KillAllCommitLogsAction.java @@ -25,6 +25,7 @@ import com.google.appengine.tools.mapreduce.Mapper; import com.google.appengine.tools.mapreduce.inputs.InMemoryInput; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; +import com.google.common.collect.Streams; import com.googlecode.objectify.Key; import google.registry.config.RegistryEnvironment; import google.registry.mapreduce.MapreduceRunner; @@ -66,7 +67,7 @@ public class KillAllCommitLogsAction implements Runnable { Input> input = new InMemoryInput<>( Lists.partition( - Stream.concat( + Streams.concat( Stream.of(CommitLogCheckpointRoot.getKey()), CommitLogBucket.getAllBucketKeys().stream()) .collect(toImmutableList()), diff --git a/java/google/registry/tools/server/ListObjectsAction.java b/java/google/registry/tools/server/ListObjectsAction.java index d8e456e3c..83e59c855 100644 --- a/java/google/registry/tools/server/ListObjectsAction.java +++ b/java/google/registry/tools/server/ListObjectsAction.java @@ -29,6 +29,7 @@ import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.ImmutableTable; import com.google.common.collect.Maps; import com.google.common.collect.Ordering; +import com.google.common.collect.Streams; import google.registry.model.ImmutableObject; import google.registry.request.JsonResponse; import google.registry.request.Parameter; @@ -150,7 +151,7 @@ public abstract class ListObjectsAction implements Ru final ImmutableMap nameMapping = ((fullFieldNames != null) && fullFieldNames.isPresent() && fullFieldNames.get()) ? getFieldAliases() : getFieldAliases().inverse(); - return Stream.concat(getPrimaryKeyFields().stream(), fieldsToUse.stream()) + return Streams.concat(getPrimaryKeyFields().stream(), fieldsToUse.stream()) .map(field -> nameMapping.getOrDefault(field, field)) .collect(toImmutableSet()); } @@ -207,7 +208,7 @@ public abstract class ListObjectsAction implements Ru Maps.transformEntries( data.columnMap(), (columnName, columnValues) -> - Stream.concat( + Streams.concat( Stream.of(includingHeader ? columnName : ""), columnValues.values().stream()) .map(String::length) diff --git a/javatests/google/registry/flows/domain/DomainTransferApproveFlowTest.java b/javatests/google/registry/flows/domain/DomainTransferApproveFlowTest.java index 8ea2deec7..952240ce5 100644 --- a/javatests/google/registry/flows/domain/DomainTransferApproveFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainTransferApproveFlowTest.java @@ -41,6 +41,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.Ordering; +import com.google.common.collect.Streams; import com.googlecode.objectify.Key; import google.registry.flows.EppException; import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException; @@ -262,7 +263,7 @@ public class DomainTransferApproveFlowTest .build(); assertBillingEventsForResource( domain, - Stream.concat( + Streams.concat( Arrays.stream(expectedCancellationBillingEvents) .map(builder -> builder.setParent(historyEntryTransferApproved).build()), Stream.of( @@ -298,7 +299,7 @@ public class DomainTransferApproveFlowTest // for the gaining client that begins at the new expiration time. assertBillingEventsForResource( domain, - Stream.concat( + Streams.concat( Arrays.stream(expectedCancellationBillingEvents) .map(builder -> builder.setParent(historyEntryTransferApproved).build()), Stream.of( diff --git a/javatests/google/registry/flows/domain/DomainTransferRequestFlowTest.java b/javatests/google/registry/flows/domain/DomainTransferRequestFlowTest.java index c3c44c577..18d8e7b2f 100644 --- a/javatests/google/registry/flows/domain/DomainTransferRequestFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainTransferRequestFlowTest.java @@ -48,6 +48,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.Iterables; +import com.google.common.collect.Streams; import com.googlecode.objectify.Key; import google.registry.flows.EppException; import google.registry.flows.EppRequestSource; @@ -313,7 +314,7 @@ public class DomainTransferRequestFlowTest .collect(toImmutableSet()); // Assert that the billing events we constructed above actually exist in Datastore. ImmutableSet expectedBillingEvents = - Stream.concat( + Streams.concat( Stream.of(losingClientAutorenew, gainingClientAutorenew), optionalToStream(optionalTransferBillingEvent)) .collect(toImmutableSet()); @@ -332,7 +333,7 @@ public class DomainTransferRequestFlowTest // Assert that the full set of server-approve billing events is exactly the extra ones plus // the transfer billing event (if present) and the gaining client autorenew. ImmutableSet expectedServeApproveBillingEvents = - Stream.concat( + Streams.concat( Stream.of(gainingClientAutorenew), optionalToStream(optionalTransferBillingEvent)) .collect(toImmutableSet()); assertBillingEventsEqual( diff --git a/javatests/google/registry/model/domain/DomainResourceTest.java b/javatests/google/registry/model/domain/DomainResourceTest.java index 6de137efd..8154c7646 100644 --- a/javatests/google/registry/model/domain/DomainResourceTest.java +++ b/javatests/google/registry/model/domain/DomainResourceTest.java @@ -33,6 +33,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.Iterables; import com.google.common.collect.Ordering; +import com.google.common.collect.Streams; import com.googlecode.objectify.Key; import google.registry.model.EntityTestCase; import google.registry.model.billing.BillingEvent; @@ -51,7 +52,6 @@ import google.registry.model.registry.Registry; import google.registry.model.reporting.HistoryEntry; import google.registry.model.transfer.TransferData; import google.registry.model.transfer.TransferStatus; -import java.util.stream.Stream; import org.joda.money.Money; import org.joda.time.DateTime; import org.junit.Before; @@ -369,7 +369,7 @@ public class DomainResourceTest extends EntityTestCase { domain .asBuilder() .setGracePeriods( - Stream.concat(addGracePeriods.stream(), renewGracePeriods.stream()) + Streams.concat(addGracePeriods.stream(), renewGracePeriods.stream()) .collect(toImmutableSet())) .build(); assertThat(domain.getGracePeriodsOfType(GracePeriodStatus.ADD)).isEqualTo(addGracePeriods);