Migrate Guava Predicates.notNull to Objects.nonNull

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=179569444
This commit is contained in:
mcilwain 2017-12-19 10:10:20 -08:00 committed by Ben McIlwain
parent 633eb3179a
commit 0bb2e12a8a
7 changed files with 15 additions and 16 deletions

View file

@ -18,7 +18,6 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.ImmutableList.toImmutableList; import static com.google.common.collect.ImmutableList.toImmutableList;
import static google.registry.model.EppResourceUtils.projectResourceOntoBuilderAtTime; import static google.registry.model.EppResourceUtils.projectResourceOntoBuilderAtTime;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.googlecode.objectify.annotation.Entity; import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.IgnoreSave; import com.googlecode.objectify.annotation.IgnoreSave;
@ -31,6 +30,7 @@ import google.registry.model.annotations.ExternalMessagingName;
import google.registry.model.annotations.ReportedOn; import google.registry.model.annotations.ReportedOn;
import google.registry.model.contact.PostalInfo.Type; import google.registry.model.contact.PostalInfo.Type;
import google.registry.model.transfer.TransferData; import google.registry.model.transfer.TransferData;
import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Stream; import java.util.stream.Stream;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
@ -175,7 +175,7 @@ public class ContactResource extends EppResource implements
@XmlElement(name = "postalInfo") @XmlElement(name = "postalInfo")
public ImmutableList<PostalInfo> getPostalInfosAsList() { public ImmutableList<PostalInfo> getPostalInfosAsList() {
return Stream.of(localizedPostalInfo, internationalizedPostalInfo) return Stream.of(localizedPostalInfo, internationalizedPostalInfo)
.filter(Predicates.notNull()) .filter(Objects::nonNull)
.collect(toImmutableList()); .collect(toImmutableList());
} }

View file

@ -16,7 +16,6 @@ package google.registry.model.ofy;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Predicates.notNull;
import static com.google.common.collect.Maps.uniqueIndex; import static com.google.common.collect.Maps.uniqueIndex;
import static com.googlecode.objectify.ObjectifyService.ofy; import static com.googlecode.objectify.ObjectifyService.ofy;
import static google.registry.config.RegistryConfig.getBaseOfyRetryDuration; import static google.registry.config.RegistryConfig.getBaseOfyRetryDuration;
@ -135,7 +134,7 @@ public class Ofy {
@Override @Override
protected void handleDeletion(Iterable<Key<?>> keys) { protected void handleDeletion(Iterable<Key<?>> keys) {
assertInTransaction(); assertInTransaction();
checkState(Streams.stream(keys).allMatch(notNull()), "Can't delete a null key."); checkState(Streams.stream(keys).allMatch(Objects::nonNull), "Can't delete a null key.");
checkProhibitedAnnotations(keys, NotBackedUp.class, VirtualEntity.class); checkProhibitedAnnotations(keys, NotBackedUp.class, VirtualEntity.class);
TRANSACTION_INFO.get().putDeletes(keys); TRANSACTION_INFO.get().putDeletes(keys);
} }
@ -167,7 +166,8 @@ public class Ofy {
@Override @Override
protected void handleSave(Iterable<?> entities) { protected void handleSave(Iterable<?> entities) {
assertInTransaction(); assertInTransaction();
checkState(Streams.stream(entities).allMatch(notNull()), "Can't save a null entity."); checkState(
Streams.stream(entities).allMatch(Objects::nonNull), "Can't save a null entity.");
checkProhibitedAnnotations(entities, NotBackedUp.class, VirtualEntity.class); checkProhibitedAnnotations(entities, NotBackedUp.class, VirtualEntity.class);
ImmutableMap<Key<?>, ?> keysToEntities = uniqueIndex(entities, Key::create); ImmutableMap<Key<?>, ?> keysToEntities = uniqueIndex(entities, Key::create);
TRANSACTION_INFO.get().putSaves(keysToEntities); TRANSACTION_INFO.get().putSaves(keysToEntities);

View file

@ -16,7 +16,6 @@ package google.registry.tools;
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 com.google.common.base.Predicates.notNull;
import static com.google.common.base.Strings.nullToEmpty; import static com.google.common.base.Strings.nullToEmpty;
import static com.google.common.collect.Maps.filterValues; import static com.google.common.collect.Maps.filterValues;
import static com.google.common.io.Resources.getResource; import static com.google.common.io.Resources.getResource;
@ -45,6 +44,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
/** A command to execute an epp command. */ /** A command to execute an epp command. */
abstract class EppToolCommand extends ConfirmingCommand implements ServerSideCommand { abstract class EppToolCommand extends ConfirmingCommand implements ServerSideCommand {
@ -145,7 +145,7 @@ abstract class EppToolCommand extends ConfirmingCommand implements ServerSideCom
params.put("superuser", superuser); params.put("superuser", superuser);
params.put("xml", URLEncoder.encode(command.xml, UTF_8.toString())); params.put("xml", URLEncoder.encode(command.xml, UTF_8.toString()));
String requestBody = String requestBody =
Joiner.on('&').withKeyValueSeparator("=").join(filterValues(params, notNull())); Joiner.on('&').withKeyValueSeparator("=").join(filterValues(params, Objects::nonNull));
responses.add(nullToEmpty(connection.send( responses.add(nullToEmpty(connection.send(
"/_dr/epptool", "/_dr/epptool",
ImmutableMap.<String, String>of(), ImmutableMap.<String, String>of(),

View file

@ -14,7 +14,6 @@
package google.registry.tools; package google.registry.tools;
import static com.google.common.base.Predicates.notNull;
import static com.google.common.util.concurrent.Futures.addCallback; import static com.google.common.util.concurrent.Futures.addCallback;
import static com.google.common.util.concurrent.MoreExecutors.directExecutor; import static com.google.common.util.concurrent.MoreExecutors.directExecutor;
@ -30,6 +29,7 @@ import google.registry.export.ExportConstants;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
/** Command to load Datastore snapshots into Bigquery. */ /** Command to load Datastore snapshots into Bigquery. */
@Parameters(separators = " =", commandDescription = "Load Datastore snapshot into Bigquery") @Parameters(separators = " =", commandDescription = "Load Datastore snapshot into Bigquery")
@ -120,7 +120,7 @@ final class LoadSnapshotCommand extends BigqueryCommand {
} }
// Block on the completion of all the load jobs. // Block on the completion of all the load jobs.
List<?> results = Futures.successfulAsList(loadJobs.values()).get(); List<?> results = Futures.successfulAsList(loadJobs.values()).get();
int numSucceeded = (int) results.stream().filter(notNull()).count(); int numSucceeded = (int) results.stream().filter(Objects::nonNull).count();
System.err.printf( System.err.printf(
"All load jobs have terminated: %d/%d successful.\n", "All load jobs have terminated: %d/%d successful.\n",
numSucceeded, loadJobs.size()); numSucceeded, loadJobs.size());

View file

@ -15,7 +15,6 @@
package google.registry.tools; package google.registry.tools;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Predicates.notNull;
import static com.google.common.collect.ImmutableSet.toImmutableSet; import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static google.registry.model.registrar.Registrar.loadByClientId; import static google.registry.model.registrar.Registrar.loadByClientId;
import static google.registry.util.PreconditionsUtils.checkArgumentPresent; import static google.registry.util.PreconditionsUtils.checkArgumentPresent;
@ -35,6 +34,7 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Objects;
/** Command to verify that a registrar has passed OT&amp;E. */ /** Command to verify that a registrar has passed OT&amp;E. */
@Parameters( @Parameters(
@ -118,7 +118,7 @@ final class VerifyOteCommand implements ServerSideCommand {
// If it matches, provide the shortened name, and otherwise return null. // If it matches, provide the shortened name, and otherwise return null.
return name.equals(replacedName) ? null : replacedName; return name.equals(replacedName) ? null : replacedName;
}) })
.filter(notNull()) .filter(Objects::nonNull)
.collect(toImmutableSet()); .collect(toImmutableSet());
} }
} }

View file

@ -15,7 +15,6 @@
package google.registry.tools.server; package google.registry.tools.server;
import static com.google.appengine.tools.cloudstorage.GcsServiceFactory.createGcsService; import static com.google.appengine.tools.cloudstorage.GcsServiceFactory.createGcsService;
import static com.google.common.base.Predicates.notNull;
import static com.google.common.collect.ImmutableList.toImmutableList; import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.Iterators.filter; import static com.google.common.collect.Iterators.filter;
import static com.google.common.io.BaseEncoding.base16; import static com.google.common.io.BaseEncoding.base16;
@ -58,6 +57,7 @@ import java.net.InetAddress;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import javax.inject.Inject; import javax.inject.Inject;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.joda.time.Duration; import org.joda.time.Duration;
@ -255,7 +255,8 @@ public class GenerateZoneFilesAction implements Runnable, JsonActionRunner.JsonA
Writer osWriter = new OutputStreamWriter(gcsOutput, UTF_8); Writer osWriter = new OutputStreamWriter(gcsOutput, UTF_8);
PrintWriter writer = new PrintWriter(osWriter)) { PrintWriter writer = new PrintWriter(osWriter)) {
writer.printf(HEADER_FORMAT, tld); writer.printf(HEADER_FORMAT, tld);
for (Iterator<String> stanzaIter = filter(stanzas, notNull()); stanzaIter.hasNext(); ) { for (Iterator<String> stanzaIter = filter(stanzas, Objects::nonNull);
stanzaIter.hasNext(); ) {
writer.println(stanzaIter.next()); writer.println(stanzaIter.next());
getContext().incrementCounter(stanzaCounter); getContext().incrementCounter(stanzaCounter);
} }

View file

@ -14,8 +14,6 @@
package google.registry.util; package google.registry.util;
import static com.google.common.base.Predicates.notNull;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
@ -111,7 +109,7 @@ public final class DiffUtils {
ImmutableSortedMap.Builder<Integer, Object> builder = ImmutableSortedMap.Builder<Integer, Object> builder =
new ImmutableSortedMap.Builder<>(Ordering.natural()); new ImmutableSortedMap.Builder<>(Ordering.natural());
int i = 0; int i = 0;
for (Object item : Iterables.filter(iterable, notNull())) { for (Object item : Iterables.filter(iterable, Objects::nonNull)) {
builder.put(i++, item); builder.put(i++, item);
} }
return builder.build(); return builder.build();