From ec55aa5361f71d86682817252054cbaf2caf9c7c Mon Sep 17 00:00:00 2001 From: mcilwain Date: Tue, 7 Feb 2017 10:06:28 -0800 Subject: [PATCH] Resolve some Guava 20 TODOs (mostly unnecessary asList() calls) ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=146799536 --- java/google/registry/model/ModelUtils.java | 3 +-- java/google/registry/model/ofy/AugmentedDeleter.java | 3 +-- .../model/ofy/TimestampInversionException.java | 4 +--- .../registry/tools/CreateAuctionCreditsCommand.java | 3 +-- .../google/registry/tools/server/VerifyOteAction.java | 3 +-- java/google/registry/util/FormattingLogger.java | 4 +--- java/google/registry/util/Retrier.java | 11 +---------- javatests/google/registry/flows/FlowTestCase.java | 9 +++------ .../flows/domain/DomainTransferApproveFlowTest.java | 3 +-- .../flows/domain/DomainTransferRequestFlowTest.java | 3 +-- .../google/registry/testing/DatastoreHelper.java | 7 +++---- javatests/google/registry/tools/CommandTestCase.java | 6 +++--- 12 files changed, 18 insertions(+), 41 deletions(-) diff --git a/java/google/registry/model/ModelUtils.java b/java/google/registry/model/ModelUtils.java index 95d5814d1..676820c12 100644 --- a/java/google/registry/model/ModelUtils.java +++ b/java/google/registry/model/ModelUtils.java @@ -21,7 +21,6 @@ import static com.google.common.collect.Iterables.all; import static com.google.common.collect.Lists.newArrayList; import static com.google.common.collect.Maps.transformValues; import static com.google.common.collect.Sets.newLinkedHashSet; -import static java.util.Arrays.asList; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; @@ -93,7 +92,7 @@ public class ModelUtils { Iterable body; if (clazz.isEnum()) { stringBuilder.append("enum "); - body = FluentIterable.from(asList(clazz.getEnumConstants())); + body = FluentIterable.from(clazz.getEnumConstants()); } else { stringBuilder.append("class "); body = FluentIterable.from(getAllFields(clazz).values()) diff --git a/java/google/registry/model/ofy/AugmentedDeleter.java b/java/google/registry/model/ofy/AugmentedDeleter.java index a426c2e0b..fbf23c1cf 100644 --- a/java/google/registry/model/ofy/AugmentedDeleter.java +++ b/java/google/registry/model/ofy/AugmentedDeleter.java @@ -16,7 +16,6 @@ package google.registry.model.ofy; import static com.googlecode.objectify.ObjectifyService.ofy; import static google.registry.util.ObjectifyUtils.OBJECTS_TO_KEYS; -import static java.util.Arrays.asList; import com.google.common.base.Functions; import com.google.common.collect.FluentIterable; @@ -45,7 +44,7 @@ abstract class AugmentedDeleter implements Deleter { @Override public Result entities(Object... entities) { - handleDeletion(FluentIterable.from(asList(entities)).transform(OBJECTS_TO_KEYS)); + handleDeletion(FluentIterable.from(entities).transform(OBJECTS_TO_KEYS)); return delegate.entities(entities); } diff --git a/java/google/registry/model/ofy/TimestampInversionException.java b/java/google/registry/model/ofy/TimestampInversionException.java index 7e6f94923..c7effcab1 100644 --- a/java/google/registry/model/ofy/TimestampInversionException.java +++ b/java/google/registry/model/ofy/TimestampInversionException.java @@ -14,8 +14,6 @@ package google.registry.model.ofy; -import static java.util.Arrays.asList; - import com.google.common.base.Joiner; import com.google.common.base.Predicate; import com.google.common.collect.FluentIterable; @@ -50,7 +48,7 @@ class TimestampInversionException extends RuntimeException { "Timestamp inversion between transaction time (%s) and %s", transactionTime, problem), - getFileAndLine(FluentIterable.from(asList(new Exception().getStackTrace())) + getFileAndLine(FluentIterable.from(new Exception().getStackTrace()) .firstMatch(new Predicate() { @Override public boolean apply(StackTraceElement element) { diff --git a/java/google/registry/tools/CreateAuctionCreditsCommand.java b/java/google/registry/tools/CreateAuctionCreditsCommand.java index 6cc917342..adcd4a263 100644 --- a/java/google/registry/tools/CreateAuctionCreditsCommand.java +++ b/java/google/registry/tools/CreateAuctionCreditsCommand.java @@ -19,7 +19,6 @@ import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static google.registry.model.registry.Registries.assertTldExists; -import static java.util.Arrays.asList; import static org.joda.time.DateTimeZone.UTC; import com.beust.jcommander.Parameter; @@ -108,7 +107,7 @@ final class CreateAuctionCreditsCommand extends MutatingCommand { CURRENCY_CODE; public static List getHeaders() { - return FluentIterable.from(asList(values())) + return FluentIterable.from(values()) .transform(new Function() { @Override public String apply(CsvHeader header) { diff --git a/java/google/registry/tools/server/VerifyOteAction.java b/java/google/registry/tools/server/VerifyOteAction.java index d89283348..8e982af22 100644 --- a/java/google/registry/tools/server/VerifyOteAction.java +++ b/java/google/registry/tools/server/VerifyOteAction.java @@ -21,7 +21,6 @@ import static google.registry.flows.picker.FlowPicker.getFlowClass; import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.util.CollectionUtils.isNullOrEmpty; import static google.registry.util.DomainNameUtils.ACE_PREFIX; -import static java.util.Arrays.asList; import com.google.common.base.Ascii; import com.google.common.base.Function; @@ -229,7 +228,7 @@ public class VerifyOteAction implements Runnable, JsonAction { UNCLASSIFIED_FLOWS(0, Predicates.alwaysFalse()); /** The number of StatTypes with a non-zero requirement. */ - private static final int NUM_REQUIREMENTS = FluentIterable.from(asList(values())) + private static final int NUM_REQUIREMENTS = FluentIterable.from(values()) .filter(new Predicate() { @Override public boolean apply(@Nonnull StatType statType) { diff --git a/java/google/registry/util/FormattingLogger.java b/java/google/registry/util/FormattingLogger.java index 6ce12a7cf..9fbe834f1 100644 --- a/java/google/registry/util/FormattingLogger.java +++ b/java/google/registry/util/FormattingLogger.java @@ -14,8 +14,6 @@ package google.registry.util; -import static java.util.Arrays.asList; - import com.google.common.base.Predicate; import com.google.common.collect.FluentIterable; import java.util.logging.Handler; @@ -38,7 +36,7 @@ public class FormattingLogger { private void log(Level level, Throwable cause, String msg) { StackTraceElement callerFrame = FluentIterable - .from(asList(new Exception().getStackTrace())) + .from(new Exception().getStackTrace()) .firstMatch(new Predicate() { @Override public boolean apply(StackTraceElement frame) { diff --git a/java/google/registry/util/Retrier.java b/java/google/registry/util/Retrier.java index 82090a403..052e0a2ab 100644 --- a/java/google/registry/util/Retrier.java +++ b/java/google/registry/util/Retrier.java @@ -15,6 +15,7 @@ package google.registry.util; import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Throwables.throwIfUnchecked; import static com.google.common.collect.Iterables.any; import static com.google.common.math.IntMath.pow; import static google.registry.util.PredicateUtils.supertypeOf; @@ -103,14 +104,4 @@ public class Retrier implements Serializable { return any(retryables, supertypeOf(e.getClass())); }}); } - - // TODO(user): Replace with Throwables.throwIfUnchecked - private static void throwIfUnchecked(Throwable throwable) { - if (throwable instanceof RuntimeException) { - throw (RuntimeException) throwable; - } - if (throwable instanceof Error) { - throw (Error) throwable; - } - } } diff --git a/javatests/google/registry/flows/FlowTestCase.java b/javatests/google/registry/flows/FlowTestCase.java index 11780be36..bb9f212a6 100644 --- a/javatests/google/registry/flows/FlowTestCase.java +++ b/javatests/google/registry/flows/FlowTestCase.java @@ -24,7 +24,6 @@ import static google.registry.testing.DatastoreHelper.getPollMessages; import static google.registry.util.ResourceUtils.readResourceUtf8; import static google.registry.xml.XmlTestUtils.assertXmlEquals; import static java.nio.charset.StandardCharsets.UTF_8; -import static java.util.Arrays.asList; import static org.joda.time.DateTimeZone.UTC; import com.google.common.base.Function; @@ -33,6 +32,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.collect.Maps; +import com.google.common.collect.ObjectArrays; import google.registry.config.RegistryConfig.ConfigModule.TmchCaMode; import google.registry.flows.EppTestComponent.FakesAndMocksModule; import google.registry.flows.picker.FlowPicker; @@ -268,7 +268,7 @@ public abstract class FlowTestCase extends ShardableTestCase { }}; // Ordering is irrelevant but duplicates should be considered independently. assertThat(FluentIterable.from(pollMessages).transform(idStripper)) - .containsExactlyElementsIn(FluentIterable.from(asList(expected)).transform(idStripper)); + .containsExactlyElementsIn(FluentIterable.from(expected).transform(idStripper)); } private EppOutput runFlowInternal(CommitMode commitMode, UserPrivileges userPrivileges) @@ -318,10 +318,7 @@ public abstract class FlowTestCase extends ShardableTestCase { CommitMode commitMode, UserPrivileges userPrivileges, String xml, String... ignoredPaths) throws Exception { // Always ignore the server trid, since it's generated and meaningless to flow correctness. - // TODO(user): Remove asList() - String[] ignoredPathsPlusTrid = FluentIterable.from(asList(ignoredPaths)) - .append("epp.response.trID.svTRID") - .toArray(String.class); + String[] ignoredPathsPlusTrid = ObjectArrays.concat(ignoredPaths, "epp.response.trID.svTRID"); EppOutput output = runFlowInternal(commitMode, userPrivileges); if (output.isResponse()) { assertThat(output.isSuccess()).isTrue(); diff --git a/javatests/google/registry/flows/domain/DomainTransferApproveFlowTest.java b/javatests/google/registry/flows/domain/DomainTransferApproveFlowTest.java index e8c19c644..c696718f3 100644 --- a/javatests/google/registry/flows/domain/DomainTransferApproveFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainTransferApproveFlowTest.java @@ -29,7 +29,6 @@ import static google.registry.testing.DomainResourceSubject.assertAboutDomains; import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries; import static google.registry.testing.HostResourceSubject.assertAboutHosts; import static google.registry.util.DateTimeUtils.START_OF_TIME; -import static java.util.Arrays.asList; import static org.joda.money.CurrencyUnit.USD; import com.google.common.base.Function; @@ -177,7 +176,7 @@ public class DomainTransferApproveFlowTest .build(); assertBillingEventsForResource( domain, - FluentIterable.from(asList(expectedCancellationBillingEvents)) + FluentIterable.from(expectedCancellationBillingEvents) .transform(new Function() { @Override public Cancellation apply(Builder builder) { diff --git a/javatests/google/registry/flows/domain/DomainTransferRequestFlowTest.java b/javatests/google/registry/flows/domain/DomainTransferRequestFlowTest.java index 81e98b8e8..3bfe4385d 100644 --- a/javatests/google/registry/flows/domain/DomainTransferRequestFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainTransferRequestFlowTest.java @@ -28,7 +28,6 @@ import static google.registry.testing.GenericEppResourceSubject.assertAboutEppRe import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries; import static google.registry.testing.HostResourceSubject.assertAboutHosts; import static google.registry.util.DateTimeUtils.START_OF_TIME; -import static java.util.Arrays.asList; import static org.joda.money.CurrencyUnit.EUR; import static org.joda.money.CurrencyUnit.USD; @@ -212,7 +211,7 @@ public class DomainTransferRequestFlowTest .setPeriodYears(registrationYears) .setParent(historyEntryTransferRequest) .build(); - assertBillingEvents(FluentIterable.from(asList(extraExpectedBillingEvents)) + assertBillingEvents(FluentIterable.from(extraExpectedBillingEvents) .transform(new Function() { @Override public BillingEvent apply(Builder builder) { diff --git a/javatests/google/registry/testing/DatastoreHelper.java b/javatests/google/registry/testing/DatastoreHelper.java index 4e0e29d10..8bcc5568a 100644 --- a/javatests/google/registry/testing/DatastoreHelper.java +++ b/javatests/google/registry/testing/DatastoreHelper.java @@ -35,7 +35,6 @@ import static google.registry.util.DateTimeUtils.START_OF_TIME; import static google.registry.util.DomainNameUtils.ACE_PREFIX_REGEX; import static google.registry.util.DomainNameUtils.getTldFromDomainName; import static google.registry.util.ResourceUtils.readResourceUtf8; -import static java.util.Arrays.asList; import static org.joda.money.CurrencyUnit.USD; import com.google.common.base.Ascii; @@ -626,7 +625,7 @@ public class DatastoreHelper { public static void assertBillingEvents(BillingEvent... expected) throws Exception { assertThat(FluentIterable.from(getBillingEvents()).transform(BILLING_EVENT_ID_STRIPPER)) .containsExactlyElementsIn( - FluentIterable.from(asList(expected)).transform(BILLING_EVENT_ID_STRIPPER)); + FluentIterable.from(expected).transform(BILLING_EVENT_ID_STRIPPER)); } /** Assert that the expected billing events set is exactly the one found in the fake datastore. */ @@ -643,7 +642,7 @@ public class DatastoreHelper { EppResource resource, BillingEvent... expected) throws Exception { assertThat(FluentIterable.from(getBillingEvents(resource)).transform(BILLING_EVENT_ID_STRIPPER)) .containsExactlyElementsIn( - FluentIterable.from(asList(expected)).transform(BILLING_EVENT_ID_STRIPPER)); + FluentIterable.from(expected).transform(BILLING_EVENT_ID_STRIPPER)); } /** Assert that there are no billing events. */ @@ -664,7 +663,7 @@ public class DatastoreHelper { throws Exception { assertThat(FluentIterable.from(getPollMessages(resource)).transform(POLL_MESSAGE_ID_STRIPPER)) .containsExactlyElementsIn( - FluentIterable.from(asList(expected)).transform(POLL_MESSAGE_ID_STRIPPER)); + FluentIterable.from(expected).transform(POLL_MESSAGE_ID_STRIPPER)); } /** Helper to effectively erase the poll message ID to facilitate comparison. */ diff --git a/javatests/google/registry/tools/CommandTestCase.java b/javatests/google/registry/tools/CommandTestCase.java index cab10ccfa..33483461c 100644 --- a/javatests/google/registry/tools/CommandTestCase.java +++ b/javatests/google/registry/tools/CommandTestCase.java @@ -14,6 +14,7 @@ package google.registry.tools; +import static com.google.common.collect.Iterables.toArray; import static com.google.common.truth.Truth.assertThat; import static google.registry.model.ofy.ObjectifyService.ofy; import static java.nio.charset.StandardCharsets.UTF_8; @@ -21,7 +22,6 @@ import static java.nio.charset.StandardCharsets.UTF_8; import com.beust.jcommander.JCommander; import com.google.common.base.Joiner; import com.google.common.base.Splitter; -import com.google.common.collect.FluentIterable; import com.google.common.collect.ObjectArrays; import com.google.common.io.Files; import com.google.common.reflect.TypeToken; @@ -114,7 +114,7 @@ public abstract class CommandTestCase { /** Writes the data to a temporary file and then returns a path to the file. */ String writeToNamedTmpFile(String filename, Iterable data) throws IOException { - return writeToNamedTmpFile(filename, FluentIterable.from(data).toArray(String.class)); + return writeToNamedTmpFile(filename, toArray(data, String.class)); } /** Writes the data to a temporary file and then returns a path to the file. */ @@ -129,7 +129,7 @@ public abstract class CommandTestCase { /** Writes the data to a temporary file and then returns a path to the file. */ String writeToTmpFile(Iterable data) throws IOException { - return writeToNamedTmpFile("tmp_file", FluentIterable.from(data).toArray(String.class)); + return writeToNamedTmpFile("tmp_file", toArray(data, String.class)); } /** Returns a path to a known good certificate file. */