Resolve some Guava 20 TODOs (mostly unnecessary asList() calls)

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=146799536
This commit is contained in:
mcilwain 2017-02-07 10:06:28 -08:00 committed by Ben McIlwain
parent f212a53232
commit ec55aa5361
12 changed files with 18 additions and 41 deletions

View file

@ -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.Lists.newArrayList;
import static com.google.common.collect.Maps.transformValues; import static com.google.common.collect.Maps.transformValues;
import static com.google.common.collect.Sets.newLinkedHashSet; import static com.google.common.collect.Sets.newLinkedHashSet;
import static java.util.Arrays.asList;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function; import com.google.common.base.Function;
@ -93,7 +92,7 @@ public class ModelUtils {
Iterable<?> body; Iterable<?> body;
if (clazz.isEnum()) { if (clazz.isEnum()) {
stringBuilder.append("enum "); stringBuilder.append("enum ");
body = FluentIterable.from(asList(clazz.getEnumConstants())); body = FluentIterable.from(clazz.getEnumConstants());
} else { } else {
stringBuilder.append("class "); stringBuilder.append("class ");
body = FluentIterable.from(getAllFields(clazz).values()) body = FluentIterable.from(getAllFields(clazz).values())

View file

@ -16,7 +16,6 @@ package google.registry.model.ofy;
import static com.googlecode.objectify.ObjectifyService.ofy; import static com.googlecode.objectify.ObjectifyService.ofy;
import static google.registry.util.ObjectifyUtils.OBJECTS_TO_KEYS; 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.base.Functions;
import com.google.common.collect.FluentIterable; import com.google.common.collect.FluentIterable;
@ -45,7 +44,7 @@ abstract class AugmentedDeleter implements Deleter {
@Override @Override
public Result<Void> entities(Object... entities) { public Result<Void> entities(Object... entities) {
handleDeletion(FluentIterable.from(asList(entities)).transform(OBJECTS_TO_KEYS)); handleDeletion(FluentIterable.from(entities).transform(OBJECTS_TO_KEYS));
return delegate.entities(entities); return delegate.entities(entities);
} }

View file

@ -14,8 +14,6 @@
package google.registry.model.ofy; package google.registry.model.ofy;
import static java.util.Arrays.asList;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable; import com.google.common.collect.FluentIterable;
@ -50,7 +48,7 @@ class TimestampInversionException extends RuntimeException {
"Timestamp inversion between transaction time (%s) and %s", "Timestamp inversion between transaction time (%s) and %s",
transactionTime, transactionTime,
problem), problem),
getFileAndLine(FluentIterable.from(asList(new Exception().getStackTrace())) getFileAndLine(FluentIterable.from(new Exception().getStackTrace())
.firstMatch(new Predicate<StackTraceElement>() { .firstMatch(new Predicate<StackTraceElement>() {
@Override @Override
public boolean apply(StackTraceElement element) { public boolean apply(StackTraceElement element) {

View file

@ -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.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static google.registry.model.registry.Registries.assertTldExists; import static google.registry.model.registry.Registries.assertTldExists;
import static java.util.Arrays.asList;
import static org.joda.time.DateTimeZone.UTC; import static org.joda.time.DateTimeZone.UTC;
import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameter;
@ -108,7 +107,7 @@ final class CreateAuctionCreditsCommand extends MutatingCommand {
CURRENCY_CODE; CURRENCY_CODE;
public static List<String> getHeaders() { public static List<String> getHeaders() {
return FluentIterable.from(asList(values())) return FluentIterable.from(values())
.transform(new Function<CsvHeader, String>() { .transform(new Function<CsvHeader, String>() {
@Override @Override
public String apply(CsvHeader header) { public String apply(CsvHeader header) {

View file

@ -21,7 +21,6 @@ import static google.registry.flows.picker.FlowPicker.getFlowClass;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.util.CollectionUtils.isNullOrEmpty; import static google.registry.util.CollectionUtils.isNullOrEmpty;
import static google.registry.util.DomainNameUtils.ACE_PREFIX; 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.Ascii;
import com.google.common.base.Function; import com.google.common.base.Function;
@ -229,7 +228,7 @@ public class VerifyOteAction implements Runnable, JsonAction {
UNCLASSIFIED_FLOWS(0, Predicates.<EppInput>alwaysFalse()); UNCLASSIFIED_FLOWS(0, Predicates.<EppInput>alwaysFalse());
/** The number of StatTypes with a non-zero requirement. */ /** 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<StatType>() { .filter(new Predicate<StatType>() {
@Override @Override
public boolean apply(@Nonnull StatType statType) { public boolean apply(@Nonnull StatType statType) {

View file

@ -14,8 +14,6 @@
package google.registry.util; package google.registry.util;
import static java.util.Arrays.asList;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable; import com.google.common.collect.FluentIterable;
import java.util.logging.Handler; import java.util.logging.Handler;
@ -38,7 +36,7 @@ public class FormattingLogger {
private void log(Level level, Throwable cause, String msg) { private void log(Level level, Throwable cause, String msg) {
StackTraceElement callerFrame = FluentIterable StackTraceElement callerFrame = FluentIterable
.from(asList(new Exception().getStackTrace())) .from(new Exception().getStackTrace())
.firstMatch(new Predicate<StackTraceElement>() { .firstMatch(new Predicate<StackTraceElement>() {
@Override @Override
public boolean apply(StackTraceElement frame) { public boolean apply(StackTraceElement frame) {

View file

@ -15,6 +15,7 @@
package google.registry.util; package google.registry.util;
import static com.google.common.base.Preconditions.checkArgument; 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.collect.Iterables.any;
import static com.google.common.math.IntMath.pow; import static com.google.common.math.IntMath.pow;
import static google.registry.util.PredicateUtils.supertypeOf; import static google.registry.util.PredicateUtils.supertypeOf;
@ -103,14 +104,4 @@ public class Retrier implements Serializable {
return any(retryables, supertypeOf(e.getClass())); 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;
}
}
} }

View file

@ -24,7 +24,6 @@ import static google.registry.testing.DatastoreHelper.getPollMessages;
import static google.registry.util.ResourceUtils.readResourceUtf8; import static google.registry.util.ResourceUtils.readResourceUtf8;
import static google.registry.xml.XmlTestUtils.assertXmlEquals; import static google.registry.xml.XmlTestUtils.assertXmlEquals;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Arrays.asList;
import static org.joda.time.DateTimeZone.UTC; import static org.joda.time.DateTimeZone.UTC;
import com.google.common.base.Function; 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.ImmutableSet;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.ObjectArrays;
import google.registry.config.RegistryConfig.ConfigModule.TmchCaMode; import google.registry.config.RegistryConfig.ConfigModule.TmchCaMode;
import google.registry.flows.EppTestComponent.FakesAndMocksModule; import google.registry.flows.EppTestComponent.FakesAndMocksModule;
import google.registry.flows.picker.FlowPicker; import google.registry.flows.picker.FlowPicker;
@ -268,7 +268,7 @@ public abstract class FlowTestCase<F extends Flow> extends ShardableTestCase {
}}; }};
// Ordering is irrelevant but duplicates should be considered independently. // Ordering is irrelevant but duplicates should be considered independently.
assertThat(FluentIterable.from(pollMessages).transform(idStripper)) 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) private EppOutput runFlowInternal(CommitMode commitMode, UserPrivileges userPrivileges)
@ -318,10 +318,7 @@ public abstract class FlowTestCase<F extends Flow> extends ShardableTestCase {
CommitMode commitMode, UserPrivileges userPrivileges, String xml, String... ignoredPaths) CommitMode commitMode, UserPrivileges userPrivileges, String xml, String... ignoredPaths)
throws Exception { throws Exception {
// Always ignore the server trid, since it's generated and meaningless to flow correctness. // Always ignore the server trid, since it's generated and meaningless to flow correctness.
// TODO(user): Remove asList() String[] ignoredPathsPlusTrid = ObjectArrays.concat(ignoredPaths, "epp.response.trID.svTRID");
String[] ignoredPathsPlusTrid = FluentIterable.from(asList(ignoredPaths))
.append("epp.response.trID.svTRID")
.toArray(String.class);
EppOutput output = runFlowInternal(commitMode, userPrivileges); EppOutput output = runFlowInternal(commitMode, userPrivileges);
if (output.isResponse()) { if (output.isResponse()) {
assertThat(output.isSuccess()).isTrue(); assertThat(output.isSuccess()).isTrue();

View file

@ -29,7 +29,6 @@ import static google.registry.testing.DomainResourceSubject.assertAboutDomains;
import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries; import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries;
import static google.registry.testing.HostResourceSubject.assertAboutHosts; import static google.registry.testing.HostResourceSubject.assertAboutHosts;
import static google.registry.util.DateTimeUtils.START_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static java.util.Arrays.asList;
import static org.joda.money.CurrencyUnit.USD; import static org.joda.money.CurrencyUnit.USD;
import com.google.common.base.Function; import com.google.common.base.Function;
@ -177,7 +176,7 @@ public class DomainTransferApproveFlowTest
.build(); .build();
assertBillingEventsForResource( assertBillingEventsForResource(
domain, domain,
FluentIterable.from(asList(expectedCancellationBillingEvents)) FluentIterable.from(expectedCancellationBillingEvents)
.transform(new Function<BillingEvent.Cancellation.Builder, BillingEvent>() { .transform(new Function<BillingEvent.Cancellation.Builder, BillingEvent>() {
@Override @Override
public Cancellation apply(Builder builder) { public Cancellation apply(Builder builder) {

View file

@ -28,7 +28,6 @@ import static google.registry.testing.GenericEppResourceSubject.assertAboutEppRe
import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries; import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries;
import static google.registry.testing.HostResourceSubject.assertAboutHosts; import static google.registry.testing.HostResourceSubject.assertAboutHosts;
import static google.registry.util.DateTimeUtils.START_OF_TIME; 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.EUR;
import static org.joda.money.CurrencyUnit.USD; import static org.joda.money.CurrencyUnit.USD;
@ -212,7 +211,7 @@ public class DomainTransferRequestFlowTest
.setPeriodYears(registrationYears) .setPeriodYears(registrationYears)
.setParent(historyEntryTransferRequest) .setParent(historyEntryTransferRequest)
.build(); .build();
assertBillingEvents(FluentIterable.from(asList(extraExpectedBillingEvents)) assertBillingEvents(FluentIterable.from(extraExpectedBillingEvents)
.transform(new Function<BillingEvent.Cancellation.Builder, BillingEvent>() { .transform(new Function<BillingEvent.Cancellation.Builder, BillingEvent>() {
@Override @Override
public BillingEvent apply(Builder builder) { public BillingEvent apply(Builder builder) {

View file

@ -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.ACE_PREFIX_REGEX;
import static google.registry.util.DomainNameUtils.getTldFromDomainName; import static google.registry.util.DomainNameUtils.getTldFromDomainName;
import static google.registry.util.ResourceUtils.readResourceUtf8; import static google.registry.util.ResourceUtils.readResourceUtf8;
import static java.util.Arrays.asList;
import static org.joda.money.CurrencyUnit.USD; import static org.joda.money.CurrencyUnit.USD;
import com.google.common.base.Ascii; import com.google.common.base.Ascii;
@ -626,7 +625,7 @@ public class DatastoreHelper {
public static void assertBillingEvents(BillingEvent... expected) throws Exception { public static void assertBillingEvents(BillingEvent... expected) throws Exception {
assertThat(FluentIterable.from(getBillingEvents()).transform(BILLING_EVENT_ID_STRIPPER)) assertThat(FluentIterable.from(getBillingEvents()).transform(BILLING_EVENT_ID_STRIPPER))
.containsExactlyElementsIn( .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. */ /** 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 { EppResource resource, BillingEvent... expected) throws Exception {
assertThat(FluentIterable.from(getBillingEvents(resource)).transform(BILLING_EVENT_ID_STRIPPER)) assertThat(FluentIterable.from(getBillingEvents(resource)).transform(BILLING_EVENT_ID_STRIPPER))
.containsExactlyElementsIn( .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. */ /** Assert that there are no billing events. */
@ -664,7 +663,7 @@ public class DatastoreHelper {
throws Exception { throws Exception {
assertThat(FluentIterable.from(getPollMessages(resource)).transform(POLL_MESSAGE_ID_STRIPPER)) assertThat(FluentIterable.from(getPollMessages(resource)).transform(POLL_MESSAGE_ID_STRIPPER))
.containsExactlyElementsIn( .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. */ /** Helper to effectively erase the poll message ID to facilitate comparison. */

View file

@ -14,6 +14,7 @@
package google.registry.tools; package google.registry.tools;
import static com.google.common.collect.Iterables.toArray;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static java.nio.charset.StandardCharsets.UTF_8; 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.beust.jcommander.JCommander;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ObjectArrays; import com.google.common.collect.ObjectArrays;
import com.google.common.io.Files; import com.google.common.io.Files;
import com.google.common.reflect.TypeToken; import com.google.common.reflect.TypeToken;
@ -114,7 +114,7 @@ public abstract class CommandTestCase<C extends Command> {
/** Writes the data to a temporary file and then returns a path to the file. */ /** Writes the data to a temporary file and then returns a path to the file. */
String writeToNamedTmpFile(String filename, Iterable<String> data) throws IOException { String writeToNamedTmpFile(String filename, Iterable<String> 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. */ /** Writes the data to a temporary file and then returns a path to the file. */
@ -129,7 +129,7 @@ public abstract class CommandTestCase<C extends Command> {
/** Writes the data to a temporary file and then returns a path to the file. */ /** Writes the data to a temporary file and then returns a path to the file. */
String writeToTmpFile(Iterable<String> data) throws IOException { String writeToTmpFile(Iterable<String> 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. */ /** Returns a path to a known good certificate file. */