Always use the constructor to make Immutable Collection Builders

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=135359669
This commit is contained in:
mcilwain 2016-10-06 08:09:47 -07:00 committed by Ben McIlwain
parent 79387f5d1e
commit b65b855067
16 changed files with 29 additions and 32 deletions

View file

@ -66,7 +66,7 @@ import org.joda.time.DateTime;
* <p>The cursor used throughout this mapreduce (overridden if necessary using the parameter * <p>The cursor used throughout this mapreduce (overridden if necessary using the parameter
* {@code cursorTime}) represents the inclusive lower bound on the range of billing times that will * {@code cursorTime}) represents the inclusive lower bound on the range of billing times that will
* be expanded as a result of the job (the exclusive upper bound being the execution time of the * be expanded as a result of the job (the exclusive upper bound being the execution time of the
* job). * job).
*/ */
@Action(path = "/_dr/task/expandRecurringBillingEvents") @Action(path = "/_dr/task/expandRecurringBillingEvents")
public class ExpandRecurringBillingEventsAction implements Runnable { public class ExpandRecurringBillingEventsAction implements Runnable {
@ -101,7 +101,7 @@ public class ExpandRecurringBillingEventsAction implements Runnable {
.runMapreduce( .runMapreduce(
new ExpandRecurringBillingEventsMapper(isDryRun, cursorTime, clock.nowUtc()), new ExpandRecurringBillingEventsMapper(isDryRun, cursorTime, clock.nowUtc()),
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<Recurring>(),
createChildEntityInput( createChildEntityInput(
@ -142,7 +142,7 @@ public class ExpandRecurringBillingEventsAction implements Runnable {
@Override @Override
public Integer run() { public Integer run() {
ImmutableSet.Builder<OneTime> syntheticOneTimesBuilder = ImmutableSet.Builder<OneTime> syntheticOneTimesBuilder =
ImmutableSet.<OneTime>builder(); new ImmutableSet.Builder<>();
final Registry tld = Registry.get(getTldFromDomainName(recurring.getTargetId())); final Registry tld = Registry.get(getTldFromDomainName(recurring.getTargetId()));
// Determine the complete set of times at which this recurring event should occur // Determine the complete set of times at which this recurring event should occur
@ -224,7 +224,7 @@ public class ExpandRecurringBillingEventsAction implements Runnable {
.filter(Range.closedOpen(cursorTime, executeTime)) .filter(Range.closedOpen(cursorTime, executeTime))
.toSet(); .toSet();
} }
/** /**
* Determines an {@link ImmutableSet} of {@link DateTime}s that have already been persisted * Determines an {@link ImmutableSet} of {@link DateTime}s that have already been persisted
* for a given recurring billing event. * for a given recurring billing event.
@ -252,7 +252,7 @@ public class ExpandRecurringBillingEventsAction implements Runnable {
/** /**
* "Reducer" to advance the cursor after all map jobs have been completed. The NullInput into the * "Reducer" to advance the cursor after all map jobs have been completed. The NullInput into the
* mapper will cause the mapper to emit one timestamp pair (current cursor and execution time), * mapper will cause the mapper to emit one timestamp pair (current cursor and execution time),
* and the cursor will be advanced (and the timestamps logged) at the end of a successful * and the cursor will be advanced (and the timestamps logged) at the end of a successful
* mapreduce. * mapreduce.
*/ */
public static class ExpandRecurringBillingEventsReducer public static class ExpandRecurringBillingEventsReducer
@ -294,7 +294,7 @@ public class ExpandRecurringBillingEventsAction implements Runnable {
} }
if (!isDryRun) { if (!isDryRun) {
ofy().save().entity(Cursor.createGlobal(RECURRING_BILLING, executionTime)); ofy().save().entity(Cursor.createGlobal(RECURRING_BILLING, executionTime));
} }
} }
}); });
} }

View file

@ -88,7 +88,7 @@ public class DomainAllocateFlow extends DomainCreateOrAllocateFlow {
protected final void setDomainCreateOrAllocateProperties(Builder builder) { protected final void setDomainCreateOrAllocateProperties(Builder builder) {
boolean sunrushAddGracePeriod = isNullOrEmpty(command.getNameservers()); boolean sunrushAddGracePeriod = isNullOrEmpty(command.getNameservers());
Registry registry = Registry.get(getTld()); Registry registry = Registry.get(getTld());
ImmutableSet.Builder<Flag> billingFlagsBuilder = ImmutableSet.builder(); ImmutableSet.Builder<Flag> billingFlagsBuilder = new ImmutableSet.Builder<>();
if (!application.getEncodedSignedMarks().isEmpty()) { if (!application.getEncodedSignedMarks().isEmpty()) {
billingFlagsBuilder.add(Flag.SUNRISE); billingFlagsBuilder.add(Flag.SUNRISE);
} else { } else {

View file

@ -71,7 +71,7 @@ class ChildEntityReader<R extends EppResource, I extends ImmutableObject> extend
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private ImmutableList<Class<? extends I>> expandPolymorphicClasses( private ImmutableList<Class<? extends I>> expandPolymorphicClasses(
ImmutableSet<Class<? extends I>> resourceClasses) { ImmutableSet<Class<? extends I>> resourceClasses) {
ImmutableList.Builder<Class<? extends I>> builder = ImmutableList.builder(); ImmutableList.Builder<Class<? extends I>> builder = new ImmutableList.Builder<>();
for (Class<? extends I> clazz : resourceClasses) { for (Class<? extends I> clazz : resourceClasses) {
if (clazz.isAnnotationPresent(Entity.class)) { if (clazz.isAnnotationPresent(Entity.class)) {
builder.add(clazz); builder.add(clazz);

View file

@ -79,7 +79,7 @@ public final class VirtualMetric<V> extends AbstractMetric<V> {
ImmutableList<MetricPoint<V>> getTimestampedValues(Instant timestamp) { ImmutableList<MetricPoint<V>> getTimestampedValues(Instant timestamp) {
ImmutableMap<ImmutableList<String>, V> values = valuesSupplier.get(); ImmutableMap<ImmutableList<String>, V> values = valuesSupplier.get();
ImmutableList.Builder<MetricPoint<V>> metricPoints = ImmutableList.builder(); ImmutableList.Builder<MetricPoint<V>> metricPoints = new ImmutableList.Builder<>();
for (Entry<ImmutableList<String>, V> entry : values.entrySet()) { for (Entry<ImmutableList<String>, V> entry : values.entrySet()) {
metricPoints.add( metricPoints.add(
MetricPoint.create(this, entry.getKey(), timestamp, timestamp, entry.getValue())); MetricPoint.create(this, entry.getKey(), timestamp, timestamp, entry.getValue()));

View file

@ -79,7 +79,7 @@ public abstract class EppMetric implements BigQueryMetric {
public ImmutableMap<String, String> getBigQueryRowEncoding() { public ImmutableMap<String, String> getBigQueryRowEncoding() {
// Create map builder, start with required values // Create map builder, start with required values
ImmutableMap.Builder<String, String> map = ImmutableMap.Builder<String, String> map =
ImmutableMap.<String, String>builder() new ImmutableMap.Builder<String, String>()
.put("requestId", getRequestId()) .put("requestId", getRequestId())
.put("startTime", toBigqueryTimestamp(getStartTimestamp())) .put("startTime", toBigqueryTimestamp(getStartTimestamp()))
.put("endTime", toBigqueryTimestamp(getEndTimestamp())) .put("endTime", toBigqueryTimestamp(getEndTimestamp()))

View file

@ -88,7 +88,7 @@ public final class LordnLog implements Iterable<Entry<String, LordnLog.Result>>
} }
} }
private static final Map<Integer, Result> RESULTS = ImmutableMap.<Integer, Result>builder() private static final Map<Integer, Result> RESULTS = new ImmutableMap.Builder<Integer, Result>()
.put(2000, new Result(2000, "OK")) .put(2000, new Result(2000, "OK"))
.put(2001, new Result(2001, "OK but not processed")) .put(2001, new Result(2001, "OK but not processed"))
.put(3601, new Result(3601, "TCN Acceptance Date after Registration Date")) .put(3601, new Result(3601, "TCN Acceptance Date after Registration Date"))

View file

@ -81,7 +81,7 @@ abstract class EppToolCommand extends ConfirmingCommand implements ServerSideCom
* EPP calls when invoking commands (i.e. domain check) with sets of domains across multiple TLDs. * EPP calls when invoking commands (i.e. domain check) with sets of domains across multiple TLDs.
*/ */
protected static Multimap<String, String> validateAndGroupDomainNamesByTld(List<String> names) { protected static Multimap<String, String> validateAndGroupDomainNamesByTld(List<String> names) {
ImmutableMultimap.Builder<String, String> builder = ImmutableMultimap.builder(); ImmutableMultimap.Builder<String, String> builder = new ImmutableMultimap.Builder<>();
for (String name : names) { for (String name : names) {
InternetDomainName tld = findTldForNameOrThrow(InternetDomainName.from(name)); InternetDomainName tld = findTldForNameOrThrow(InternetDomainName.from(name));
builder.put(tld.toString(), name); builder.put(tld.toString(), name);

View file

@ -45,13 +45,13 @@ public final class GetLrpTokenCommand implements RemoteApiCommand {
names = {"-h", "--history"}, names = {"-h", "--history"},
description = "Return expanded history entry (including domain application)") description = "Return expanded history entry (including domain application)")
private boolean includeHistory = false; private boolean includeHistory = false;
@Override @Override
public void run() throws Exception { public void run() throws Exception {
checkArgument( checkArgument(
(tokenString == null) == (assignee != null), (tokenString == null) == (assignee != null),
"Exactly one of either token or assignee must be specified."); "Exactly one of either token or assignee must be specified.");
ImmutableSet.Builder<LrpToken> tokensBuilder = ImmutableSet.builder(); ImmutableSet.Builder<LrpToken> tokensBuilder = new ImmutableSet.Builder<>();
if (tokenString != null) { if (tokenString != null) {
LrpToken token = ofy().load().key(Key.create(LrpToken.class, tokenString)).now(); LrpToken token = ofy().load().key(Key.create(LrpToken.class, tokenString)).now();
if (token != null) { if (token != null) {
@ -69,7 +69,7 @@ public final class GetLrpTokenCommand implements RemoteApiCommand {
System.out.println( System.out.println(
ofy().load().key(token.getRedemptionHistoryEntry()).now().toHydratedString()); ofy().load().key(token.getRedemptionHistoryEntry()).now().toHydratedString());
} }
} }
} else { } else {
System.out.println("Token not found."); System.out.println("Token not found.");
} }

View file

@ -74,7 +74,7 @@ abstract class ListObjectsCommand implements RemoteApiCommand, ServerSideCommand
@Override @Override
public void run() throws Exception { public void run() throws Exception {
ImmutableMap.Builder<String, Object> params = ImmutableMap.<String, Object>builder(); ImmutableMap.Builder<String, Object> params = new ImmutableMap.Builder<>();
if (fields != null) { if (fields != null) {
params.put(FIELDS_PARAM, fields); params.put(FIELDS_PARAM, fields);
} }

View file

@ -177,7 +177,7 @@ public abstract class ListObjectsAction<T extends ImmutableObject> implements Ru
*/ */
private ImmutableTable<T, String, String> private ImmutableTable<T, String, String>
extractData(ImmutableSet<String> fields, ImmutableSet<T> objects) { extractData(ImmutableSet<String> fields, ImmutableSet<T> objects) {
ImmutableTable.Builder<T, String, String> builder = ImmutableTable.builder(); ImmutableTable.Builder<T, String, String> builder = new ImmutableTable.Builder<>();
for (T object : objects) { for (T object : objects) {
Map<String, Object> fieldMap = new HashMap<>(); Map<String, Object> fieldMap = new HashMap<>();
// Base case of the mapping is to use ImmutableObject's toDiffableFieldMap(). // Base case of the mapping is to use ImmutableObject's toDiffableFieldMap().

View file

@ -213,8 +213,8 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
.setParent(historyEntry) .setParent(historyEntry)
.build(); .build();
ImmutableSet<BillingEvent> billingEvents = ImmutableSet.of( ImmutableSet.Builder<BillingEvent> expectedBillingEvents =
createBillingEvent, renewBillingEvent); new ImmutableSet.Builder<BillingEvent>().add(createBillingEvent).add(renewBillingEvent);
// If EAP is applied, a billing event for EAP should be present. // If EAP is applied, a billing event for EAP should be present.
if (!eapFee.isZero()) { if (!eapFee.isZero()) {
@ -229,12 +229,9 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
.setFlags(billingFlags) .setFlags(billingFlags)
.setParent(historyEntry) .setParent(historyEntry)
.build(); .build();
billingEvents = ImmutableSet.<BillingEvent>builder() expectedBillingEvents.add(eapBillingEvent);
.addAll(billingEvents)
.add(eapBillingEvent)
.build();
} }
assertBillingEvents(billingEvents); assertBillingEvents(expectedBillingEvents.build());
assertGracePeriods( assertGracePeriods(
domain.getGracePeriods(), domain.getGracePeriods(),

View file

@ -64,7 +64,7 @@ public class EppResourceIndexTest extends EntityTestCase {
*/ */
private ImmutableList<EppResourceIndex> getEppResourceIndexObjects() { private ImmutableList<EppResourceIndex> getEppResourceIndexObjects() {
int numBuckets = RegistryEnvironment.get().config().getEppResourceIndexBucketCount(); int numBuckets = RegistryEnvironment.get().config().getEppResourceIndexBucketCount();
ImmutableList.Builder<EppResourceIndex> indexEntities = ImmutableList.builder(); ImmutableList.Builder<EppResourceIndex> indexEntities = new ImmutableList.Builder<>();
for (int i = 0; i < numBuckets; i++) { for (int i = 0; i < numBuckets; i++) {
indexEntities.addAll(ofy().load() indexEntities.addAll(ofy().load()
.type(EppResourceIndex.class) .type(EppResourceIndex.class)

View file

@ -78,7 +78,7 @@ public class RdapActionBaseTest {
if (pathSearchString.equals("RuntimeException")) { if (pathSearchString.equals("RuntimeException")) {
throw new RuntimeException(); throw new RuntimeException();
} }
ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder(); ImmutableMap.Builder<String, Object> builder = new ImmutableMap.Builder<>();
builder.put("key", "value"); builder.put("key", "value");
RdapJsonFormatter.addTopLevelEntries( RdapJsonFormatter.addTopLevelEntries(
builder, builder,

View file

@ -468,7 +468,7 @@ public class RdapJsonFormatterTest {
@Test @Test
public void testTopLevel() throws Exception { public void testTopLevel() throws Exception {
ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder(); ImmutableMap.Builder<String, Object> builder = new ImmutableMap.Builder<>();
builder.put("key", "value"); builder.put("key", "value");
RdapJsonFormatter.addTopLevelEntries( RdapJsonFormatter.addTopLevelEntries(
builder, builder,
@ -481,7 +481,7 @@ public class RdapJsonFormatterTest {
@Test @Test
public void testTopLevel_withTermsOfService() throws Exception { public void testTopLevel_withTermsOfService() throws Exception {
ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder(); ImmutableMap.Builder<String, Object> builder = new ImmutableMap.Builder<>();
builder.put("key", "value"); builder.put("key", "value");
RdapJsonFormatter.addTopLevelEntries( RdapJsonFormatter.addTopLevelEntries(
builder, builder,
@ -494,7 +494,7 @@ public class RdapJsonFormatterTest {
@Test @Test
public void testTopLevel_domain() throws Exception { public void testTopLevel_domain() throws Exception {
ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder(); ImmutableMap.Builder<String, Object> builder = new ImmutableMap.Builder<>();
builder.put("key", "value"); builder.put("key", "value");
RdapJsonFormatter.addTopLevelEntries( RdapJsonFormatter.addTopLevelEntries(
builder, builder,
@ -507,7 +507,7 @@ public class RdapJsonFormatterTest {
@Test @Test
public void testTopLevel_domainWithTermsOfService() throws Exception { public void testTopLevel_domainWithTermsOfService() throws Exception {
ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder(); ImmutableMap.Builder<String, Object> builder = new ImmutableMap.Builder<>();
builder.put("key", "value"); builder.put("key", "value");
RdapJsonFormatter.addTopLevelEntries( RdapJsonFormatter.addTopLevelEntries(
builder, builder,

View file

@ -308,7 +308,7 @@ public class TaskQueueHelper {
if (info.getTagAsBytes() != null) { if (info.getTagAsBytes() != null) {
this.tag = new String(info.getTagAsBytes(), UTF_8); this.tag = new String(info.getTagAsBytes(), UTF_8);
} }
ImmutableMultimap.Builder<String, String> headerBuilder = ImmutableMultimap.builder(); ImmutableMultimap.Builder<String, String> headerBuilder = new ImmutableMultimap.Builder<>();
for (HeaderWrapper header : info.getHeaders()) { for (HeaderWrapper header : info.getHeaders()) {
// Lowercase header name for comparison since HTTP // Lowercase header name for comparison since HTTP
// header names are case-insensitive. // header names are case-insensitive.

View file

@ -79,7 +79,7 @@ public abstract class ListObjectsCommandTestCase<C extends ListObjectsCommand>
Optional<Boolean> printHeaderRow, Optional<Boolean> printHeaderRow,
Optional<Boolean> fullFieldNames) throws Exception { Optional<Boolean> fullFieldNames) throws Exception {
ImmutableMap.Builder<String, Object> params = ImmutableMap.<String, Object>builder(); ImmutableMap.Builder<String, Object> params = new ImmutableMap.Builder<>();
if (fields != null) { if (fields != null) {
params.put(FIELDS_PARAM, fields); params.put(FIELDS_PARAM, fields);
} }