Remove unnecessary explicit generic type declarations

They can be inferred correctly even in Java 7, and display as
compiler warnings in IntelliJ.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=173451087
This commit is contained in:
mcilwain 2017-10-25 14:35:29 -07:00 committed by jianglai
parent 0fdc189e9c
commit eed2e0c45f
20 changed files with 37 additions and 46 deletions

View file

@ -200,7 +200,7 @@ public class DeleteContactsAndHostsAction implements Runnable {
new DeleteEppResourceReducer(), new DeleteEppResourceReducer(),
ImmutableList.of( ImmutableList.of(
// Add an extra shard that maps over a null domain. See the mapper code for why. // Add an extra shard that maps over a null domain. See the mapper code for why.
new NullInput<DomainBase>(), new NullInput<>(),
EppResourceInputs.createEntityInput(DomainBase.class))))); EppResourceInputs.createEntityInput(DomainBase.class)))));
} catch (Throwable t) { } catch (Throwable t) {
logger.severefmt(t, "Error while kicking off mapreduce to delete contacts/hosts"); logger.severefmt(t, "Error while kicking off mapreduce to delete contacts/hosts");

View file

@ -113,7 +113,7 @@ public class ExpandRecurringBillingEventsAction implements Runnable {
new ExpandRecurringBillingEventsReducer(isDryRun, persistedCursorTime), new ExpandRecurringBillingEventsReducer(isDryRun, persistedCursorTime),
// Add an extra shard that maps over a null recurring event (see the mapper for why). // Add an extra shard that maps over a null recurring event (see the mapper for why).
ImmutableList.of( ImmutableList.of(
new NullInput<Recurring>(), new NullInput<>(),
createChildEntityInput( createChildEntityInput(
ImmutableSet.<Class<? extends DomainResource>>of(DomainResource.class), ImmutableSet.<Class<? extends DomainResource>>of(DomainResource.class),
ImmutableSet.<Class<? extends Recurring>>of(Recurring.class)))))); ImmutableSet.<Class<? extends Recurring>>of(Recurring.class))))));

View file

@ -168,7 +168,7 @@ class MapreduceEntityCleanupUtil {
*/ */
private ImmutableSet<String> getPossibleIdsForPipelineJob( private ImmutableSet<String> getPossibleIdsForPipelineJob(
BaseDatastoreService datastore, String jobId) { BaseDatastoreService datastore, String jobId) {
return getPossibleIdsForPipelineJobRecur(datastore, jobId, new HashSet<String>()); return getPossibleIdsForPipelineJobRecur(datastore, jobId, new HashSet<>());
} }
/** /**

View file

@ -139,7 +139,7 @@ public class RefreshDnsOnHostRenameAction implements Runnable {
new RefreshDnsOnHostRenameReducer(refreshRequests, retrier), new RefreshDnsOnHostRenameReducer(refreshRequests, retrier),
// Add an extra NullInput so that the reducer always fires exactly once. // Add an extra NullInput so that the reducer always fires exactly once.
ImmutableList.of( ImmutableList.of(
new NullInput<DomainResource>(), createEntityInput(DomainResource.class))))); new NullInput<>(), createEntityInput(DomainResource.class)))));
} catch (Throwable t) { } catch (Throwable t) {
logger.severefmt(t, "Error while kicking off mapreduce to refresh DNS for renamed hosts."); logger.severefmt(t, "Error while kicking off mapreduce to refresh DNS for renamed hosts.");
} }

View file

@ -83,8 +83,7 @@ public class CloudDnsWriter extends BaseDnsWriter {
private final String projectId; private final String projectId;
private final String zoneName; private final String zoneName;
private final Dns dnsConnection; private final Dns dnsConnection;
private final HashMap<String, ImmutableSet<ResourceRecordSet>> desiredRecords = private final HashMap<String, ImmutableSet<ResourceRecordSet>> desiredRecords = new HashMap<>();
new HashMap<String, ImmutableSet<ResourceRecordSet>>();
@Inject @Inject
CloudDnsWriter( CloudDnsWriter(

View file

@ -37,6 +37,6 @@ class EppResourceEntityInput<R extends EppResource> extends EppResourceBaseInput
@Override @Override
protected InputReader<R> bucketToReader(Key<EppResourceIndexBucket> bucketKey) { protected InputReader<R> bucketToReader(Key<EppResourceIndexBucket> bucketKey) {
return new EppResourceEntityReader<R>(bucketKey, resourceClasses); return new EppResourceEntityReader<>(bucketKey, resourceClasses);
} }
} }

View file

@ -53,11 +53,10 @@ public final class EppResourceInputs {
public static <R extends EppResource> Input<R> createEntityInput( public static <R extends EppResource> Input<R> createEntityInput(
Class<? extends R> resourceClass, Class<? extends R> resourceClass,
Class<? extends R>... moreResourceClasses) { Class<? extends R>... moreResourceClasses) {
return new EppResourceEntityInput<R>( return new EppResourceEntityInput<>(
ImmutableSet.copyOf(asList(resourceClass, moreResourceClasses))); ImmutableSet.copyOf(asList(resourceClass, moreResourceClasses)));
} }
/** /**
* Returns a MapReduce {@link Input} that loads all {@link ImmutableObject} objects of a given * Returns a MapReduce {@link Input} that loads all {@link ImmutableObject} objects of a given
* type, including deleted resources, that are child entities of all {@link EppResource} objects * type, including deleted resources, that are child entities of all {@link EppResource} objects

View file

@ -171,8 +171,7 @@ public final class RegistrarCreditBalance extends ImmutableObject implements Bui
ofy().load().type(RegistrarCreditBalance.class).ancestor(registrarCredit)) { ofy().load().type(RegistrarCreditBalance.class).ancestor(registrarCredit)) {
// Create the submap at this key if it doesn't exist already. // Create the submap at this key if it doesn't exist already.
Map<DateTime, Money> submap = Map<DateTime, Money> submap =
Optional.ofNullable(map.get(balance.effectiveTime)) Optional.ofNullable(map.get(balance.effectiveTime)).orElse(new HashMap<>());
.orElse(new HashMap<DateTime, Money>());
submap.put(balance.writtenTime, balance.amount); submap.put(balance.writtenTime, balance.amount);
map.put(balance.effectiveTime, submap); map.put(balance.effectiveTime, submap);
} }

View file

@ -62,7 +62,7 @@ public class MetricReporter extends AbstractScheduledService {
writeInterval, writeInterval,
threadFactory, threadFactory,
MetricRegistryImpl.getDefault(), MetricRegistryImpl.getDefault(),
new ArrayBlockingQueue<Optional<ImmutableList<MetricPoint<?>>>>(1000)); new ArrayBlockingQueue<>(1000));
} }
@VisibleForTesting @VisibleForTesting

View file

@ -29,7 +29,7 @@ abstract class RdapResourcesAndIncompletenessWarningType<T extends EppResource>
static <S extends EppResource> RdapResourcesAndIncompletenessWarningType<S> create( static <S extends EppResource> RdapResourcesAndIncompletenessWarningType<S> create(
List<S> resources, IncompletenessWarningType incompletenessWarningType) { List<S> resources, IncompletenessWarningType incompletenessWarningType) {
return new AutoValue_RdapResourcesAndIncompletenessWarningType<S>( return new AutoValue_RdapResourcesAndIncompletenessWarningType<>(
resources, incompletenessWarningType); resources, incompletenessWarningType);
} }

View file

@ -237,7 +237,7 @@ public final class RdeStagingAction implements Runnable {
reducer, reducer,
ImmutableList.of( ImmutableList.of(
// Add an extra shard that maps over a null resource. See the mapper code for why. // Add an extra shard that maps over a null resource. See the mapper code for why.
new NullInput<EppResource>(), new NullInput<>(),
EppResourceInputs.createEntityInput(EppResource.class))))); EppResourceInputs.createEntityInput(EppResource.class)))));
} }

View file

@ -62,7 +62,7 @@ public class RemoveIpAddressCommand extends MutatingEppToolCommand {
continue; continue;
} }
ArrayList<SoyMapData> ipAddresses = new ArrayList<SoyMapData>(); ArrayList<SoyMapData> ipAddresses = new ArrayList<>();
for (InetAddress address : host.getInetAddresses()) { for (InetAddress address : host.getInetAddresses()) {
SoyMapData dataMap = new SoyMapData( SoyMapData dataMap = new SoyMapData(
"address", address.getHostAddress(), "address", address.getHostAddress(),

View file

@ -141,7 +141,7 @@ public class GenerateZoneFilesAction implements Runnable, JsonActionRunner.JsonA
tlds, exportTime, dnsDefaultATtl, dnsDefaultNsTtl, dnsDefaultDsTtl), tlds, exportTime, dnsDefaultATtl, dnsDefaultNsTtl, dnsDefaultDsTtl),
new GenerateBindFileReducer(bucket, exportTime, gcsBufferSize), new GenerateBindFileReducer(bucket, exportTime, gcsBufferSize),
ImmutableList.of( ImmutableList.of(
new NullInput<EppResource>(), new NullInput<>(),
createEntityInput(DomainResource.class))); createEntityInput(DomainResource.class)));
ImmutableList<String> filenames = ImmutableList<String> filenames =
tlds.stream() tlds.stream()

View file

@ -58,8 +58,7 @@ public final class ListDomainsAction extends ListObjectsAction<DomainResource> {
checkArgument(!tlds.isEmpty(), "Must specify TLDs to query"); checkArgument(!tlds.isEmpty(), "Must specify TLDs to query");
assertTldsExist(tlds); assertTldsExist(tlds);
ImmutableSortedSet.Builder<DomainResource> builder = ImmutableSortedSet.Builder<DomainResource> builder =
new ImmutableSortedSet.Builder<DomainResource>( new ImmutableSortedSet.Builder<>(comparing(DomainResource::getFullyQualifiedDomainName));
comparing(DomainResource::getFullyQualifiedDomainName));
for (List<String> batch : Lists.partition(tlds.asList(), MAX_NUM_SUBQUERIES)) { for (List<String> batch : Lists.partition(tlds.asList(), MAX_NUM_SUBQUERIES)) {
builder.addAll(queryNotDeleted(DomainResource.class, clock.nowUtc(), "tld in", batch)); builder.addAll(queryNotDeleted(DomainResource.class, clock.nowUtc(), "tld in", batch));
} }

View file

@ -359,7 +359,7 @@ public final class FormField<I, O> {
public Builder<I, O> matches(Pattern pattern, @Nullable String errorMessage) { public Builder<I, O> matches(Pattern pattern, @Nullable String errorMessage) {
checkState(CharSequence.class.isAssignableFrom(typeOut)); checkState(CharSequence.class.isAssignableFrom(typeOut));
return transform( return transform(
new MatchesFunction<O>(checkNotNull(pattern), Optional.ofNullable(errorMessage))); new MatchesFunction<>(checkNotNull(pattern), Optional.ofNullable(errorMessage)));
} }
/** Alias for {@link #matches(Pattern, String) matches(pattern, null)} */ /** Alias for {@link #matches(Pattern, String) matches(pattern, null)} */
@ -404,7 +404,7 @@ public final class FormField<I, O> {
checkState(CharSequence.class.isAssignableFrom(typeOut) checkState(CharSequence.class.isAssignableFrom(typeOut)
|| Collection.class.isAssignableFrom(typeOut) || Collection.class.isAssignableFrom(typeOut)
|| Number.class.isAssignableFrom(typeOut)); || Number.class.isAssignableFrom(typeOut));
return transform(new RangeFunction<O>(checkNotNull(range))); return transform(new RangeFunction<>(checkNotNull(range)));
} }
/** /**
@ -471,7 +471,7 @@ public final class FormField<I, O> {
public <C extends Enum<C>> Builder<I, C> asEnum(Class<C> enumClass) { public <C extends Enum<C>> Builder<I, C> asEnum(Class<C> enumClass) {
checkArgument(enumClass.isEnum()); checkArgument(enumClass.isEnum());
checkState(String.class.isAssignableFrom(typeOut)); checkState(String.class.isAssignableFrom(typeOut));
return transform(enumClass, new ToEnumFunction<O, C>(enumClass)); return transform(enumClass, new ToEnumFunction<>(enumClass));
} }
/** /**

View file

@ -33,7 +33,7 @@ public final class XmlToEnumMapper<T extends Enum<?>> {
* Creates a new {@link XmlToEnumMapper} from xml value to enum value. * Creates a new {@link XmlToEnumMapper} from xml value to enum value.
*/ */
public static <T extends Enum<?>> XmlToEnumMapper<T> create(T[] enumValues) { public static <T extends Enum<?>> XmlToEnumMapper<T> create(T[] enumValues) {
return new XmlToEnumMapper<T>(enumValues); return new XmlToEnumMapper<>(enumValues);
} }
private XmlToEnumMapper(T[] enumValues) { private XmlToEnumMapper(T[] enumValues) {

View file

@ -73,7 +73,7 @@ public class MapreduceEntityCleanupActionTest
private final FakeClock clock = new FakeClock(DateTime.now(UTC)); private final FakeClock clock = new FakeClock(DateTime.now(UTC));
private final FakeResponse response = new FakeResponse(); private final FakeResponse response = new FakeResponse();
private static final ImmutableList<List<String>> inputStrings = ImmutableList.<List<String>>of( private static final ImmutableList<List<String>> inputStrings = ImmutableList.of(
ImmutableList.of("a", "b", "c"), ImmutableList.of("a", "b", "c"),
ImmutableList.of("d", "e", "f", "g", "h"), ImmutableList.of("d", "e", "f", "g", "h"),
ImmutableList.of("i", "j", "k"), ImmutableList.of("i", "j", "k"),
@ -119,23 +119,19 @@ public class MapreduceEntityCleanupActionTest
} }
private void setAnyJobAndDaysOld(int daysOld) { private void setAnyJobAndDaysOld(int daysOld) {
setJobIdJobNameAndDaysOld( setJobIdJobNameAndDaysOld(Optional.empty(), Optional.empty(), Optional.of(daysOld));
Optional.<String>empty(), Optional.<String>empty(), Optional.<Integer>of(daysOld));
} }
private void setJobId(String jobId) { private void setJobId(String jobId) {
setJobIdJobNameAndDaysOld( setJobIdJobNameAndDaysOld(Optional.of(jobId), Optional.empty(), Optional.empty());
Optional.of(jobId), Optional.<String>empty(), Optional.<Integer>empty());
} }
private void setJobName(String jobName) { private void setJobName(String jobName) {
setJobIdJobNameAndDaysOld( setJobIdJobNameAndDaysOld(Optional.empty(), Optional.of(jobName), Optional.empty());
Optional.<String>empty(), Optional.of(jobName), Optional.<Integer>empty());
} }
private void setJobNameAndDaysOld(String jobName, int daysOld) { private void setJobNameAndDaysOld(String jobName, int daysOld) {
setJobIdJobNameAndDaysOld( setJobIdJobNameAndDaysOld(Optional.empty(), Optional.of(jobName), Optional.of(daysOld));
Optional.<String>empty(), Optional.of(jobName), Optional.<Integer>of(daysOld));
} }
private void setJobIdJobNameAndDaysOld( private void setJobIdJobNameAndDaysOld(
@ -144,9 +140,9 @@ public class MapreduceEntityCleanupActionTest
action = new MapreduceEntityCleanupAction( action = new MapreduceEntityCleanupAction(
jobId, jobId,
jobName, jobName,
Optional.<Integer>empty(), // numJobsToDelete Optional.empty(), // numJobsToDelete
daysOld, daysOld,
Optional.<Boolean>empty(), // force Optional.empty(), // force
mapreduceEntityCleanupUtil, mapreduceEntityCleanupUtil,
clock, clock,
DatastoreServiceFactory.getDatastoreService(), DatastoreServiceFactory.getDatastoreService(),

View file

@ -284,8 +284,7 @@ public class SessionUtilsTest {
@Test @Test
public void testHasAccessToRegistrar_accessRevoked_returnsFalse() throws Exception { public void testHasAccessToRegistrar_accessRevoked_returnsFalse() throws Exception {
RegistrarContact.updateContacts( RegistrarContact.updateContacts(loadRegistrar(DEFAULT_CLIENT_ID), new java.util.HashSet<>());
loadRegistrar(DEFAULT_CLIENT_ID), new java.util.HashSet<RegistrarContact>());
assertThat(SessionUtils.hasAccessToRegistrar(DEFAULT_CLIENT_ID, THE_REGISTRAR_GAE_USER_ID)) assertThat(SessionUtils.hasAccessToRegistrar(DEFAULT_CLIENT_ID, THE_REGISTRAR_GAE_USER_ID))
.isFalse(); .isFalse();
} }

View file

@ -62,10 +62,10 @@ public class DiffUtilsTest {
@Test @Test
public void test_emptyToNullCollection_doesntDisplay() { public void test_emptyToNullCollection_doesntDisplay() {
Map<String, Object> mapA = new HashMap<String, Object>(); Map<String, Object> mapA = new HashMap<>();
mapA.put("a", "jim"); mapA.put("a", "jim");
mapA.put("b", null); mapA.put("b", null);
Map<String, Object> mapB = new HashMap<String, Object>(); Map<String, Object> mapB = new HashMap<>();
mapB.put("a", "tim"); mapB.put("a", "tim");
mapB.put("b", ImmutableSet.of()); mapB.put("b", ImmutableSet.of());
// This ensures that it is not outputting a diff of b: null -> []. // This ensures that it is not outputting a diff of b: null -> [].

View file

@ -208,34 +208,34 @@ public class XmlTestUtils {
} }
set.add(simpleEntry.getValue()); set.add(simpleEntry.getValue());
} }
return new AbstractMap.SimpleEntry<String, Object>(mappedKey, set); return new AbstractMap.SimpleEntry<>(mappedKey, set);
} }
if (obj instanceof Number) { if (obj instanceof Number) {
return new AbstractMap.SimpleEntry<String, Object>(null, obj.toString()); return new AbstractMap.SimpleEntry<>(null, obj.toString());
} }
if (obj instanceof Boolean) { if (obj instanceof Boolean) {
return new AbstractMap.SimpleEntry<String, Object>(null, ((Boolean) obj) ? "1" : "0"); return new AbstractMap.SimpleEntry<>(null, ((Boolean) obj) ? "1" : "0");
} }
if (obj instanceof String) { if (obj instanceof String) {
// Turn stringified booleans into integers. Both are acceptable as xml boolean values, but // Turn stringified booleans into integers. Both are acceptable as xml boolean values, but
// we use "true" and "false" whereas the samples use "1" and "0". // we use "true" and "false" whereas the samples use "1" and "0".
if (obj.equals("true")) { if (obj.equals("true")) {
return new AbstractMap.SimpleEntry<String, Object>(null, "1"); return new AbstractMap.SimpleEntry<>(null, "1");
} }
if (obj.equals("false")) { if (obj.equals("false")) {
return new AbstractMap.SimpleEntry<String, Object>(null, "0"); return new AbstractMap.SimpleEntry<>(null, "0");
} }
String string = obj.toString(); String string = obj.toString();
// We use a slightly different datetime format (both legal) than the samples, so normalize // We use a slightly different datetime format (both legal) than the samples, so normalize
// both into Datetime objects. // both into Datetime objects.
try { try {
return new AbstractMap.SimpleEntry<String, Object>( return new AbstractMap.SimpleEntry<>(
null, ISODateTimeFormat.dateTime().parseDateTime(string).toDateTime(UTC)); null, ISODateTimeFormat.dateTime().parseDateTime(string).toDateTime(UTC));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
// It wasn't a DateTime. // It wasn't a DateTime.
} }
try { try {
return new AbstractMap.SimpleEntry<String, Object>( return new AbstractMap.SimpleEntry<>(
null, ISODateTimeFormat.dateTimeNoMillis().parseDateTime(string).toDateTime(UTC)); null, ISODateTimeFormat.dateTimeNoMillis().parseDateTime(string).toDateTime(UTC));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
// It wasn't a DateTime. // It wasn't a DateTime.
@ -243,12 +243,12 @@ public class XmlTestUtils {
try { try {
if (!InternetDomainName.isValid(string)) { if (!InternetDomainName.isValid(string)) {
// It's not a domain name, but it is an InetAddress. Ergo, it's an ip address. // It's not a domain name, but it is an InetAddress. Ergo, it's an ip address.
return new AbstractMap.SimpleEntry<String, Object>(null, InetAddresses.forString(string)); return new AbstractMap.SimpleEntry<>(null, InetAddresses.forString(string));
} }
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
// Not an ip address. // Not an ip address.
} }
return new AbstractMap.SimpleEntry<String, Object>(null, string); return new AbstractMap.SimpleEntry<>(null, string);
} }
return new AbstractMap.SimpleEntry<>(null, checkNotNull(obj)); return new AbstractMap.SimpleEntry<>(null, checkNotNull(obj));
} }