Replace com.google.common.base.Function with java.util.function.Function

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=179249159
This commit is contained in:
guyben 2017-12-15 15:41:05 -08:00 committed by Ben McIlwain
parent d538dca2e0
commit 8157928a35
53 changed files with 424 additions and 399 deletions

View file

@ -15,6 +15,7 @@
package google.registry.backup;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.Iterators.peekingIterator;
import static google.registry.backup.BackupUtils.createDeserializingIterator;
import static google.registry.model.ofy.ObjectifyService.ofy;
@ -25,8 +26,6 @@ import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.EntityTranslator;
import com.google.appengine.tools.cloudstorage.GcsFileMetadata;
import com.google.appengine.tools.cloudstorage.GcsService;
import com.google.common.base.Function;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.Lists;
import com.google.common.collect.PeekingIterator;
import com.googlecode.objectify.Key;
@ -50,8 +49,8 @@ import java.nio.channels.Channels;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.stream.Stream;
import javax.inject.Inject;
import org.joda.time.DateTime;
@ -117,15 +116,18 @@ public class RestoreCommitLogsAction implements Runnable {
}
// Restore the CommitLogCheckpointRoot and CommitLogBuckets.
saveOfy(
FluentIterable.from(bucketTimestamps.entrySet())
.transform(
(Function<Entry<Integer, DateTime>, ImmutableObject>)
entry ->
new CommitLogBucket.Builder()
.setBucketNum(entry.getKey())
.setLastWrittenTime(entry.getValue())
.build())
.append(CommitLogCheckpointRoot.create(lastCheckpoint.getCheckpointTime())));
Stream.concat(
bucketTimestamps
.entrySet()
.stream()
.map(
entry ->
new CommitLogBucket.Builder()
.setBucketNum(entry.getKey())
.setLastWrittenTime(entry.getValue())
.build()),
Stream.of(CommitLogCheckpointRoot.create(lastCheckpoint.getCheckpointTime())))
.collect(toImmutableList()));
logger.info("Restore complete");
}

View file

@ -51,7 +51,6 @@ import com.google.api.services.bigquery.model.TableFieldSchema;
import com.google.api.services.bigquery.model.TableReference;
import com.google.api.services.bigquery.model.TableRow;
import com.google.api.services.bigquery.model.ViewDefinition;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableTable;
import com.google.common.io.BaseEncoding;
@ -359,36 +358,33 @@ public class BigqueryConnection implements AutoCloseable {
}
/**
* A function that updates the specified Bigquery table to reflect the metadata from the input
* DestinationTable, passing the same DestinationTable through as the output. If the specified
* table does not already exist, it will be inserted into the dataset.
* Updates the specified Bigquery table to reflect the metadata from the input.
*
* <p>Returns the input DestinationTable. If the specified table does not already exist, it will
* be inserted into the dataset.
*
* <p>Clients can call this function directly to update a table on demand, or can pass it to
* Futures.transform() to update a table produced as the asynchronous result of a load or query
* job (e.g. to add a description to it).
*/
private class UpdateTableFunction implements Function<DestinationTable, DestinationTable> {
@Override
public DestinationTable apply(final DestinationTable destinationTable) {
Table table = destinationTable.getTable();
TableReference ref = table.getTableReference();
try {
if (checkTableExists(ref.getDatasetId(), ref.getTableId())) {
// Make sure to use patch() rather than update(). The former changes only those properties
// which are specified, while the latter would change everything, blanking out unspecified
// properties.
bigquery.tables()
.patch(ref.getProjectId(), ref.getDatasetId(), ref.getTableId(), table)
.execute();
} else {
bigquery.tables()
.insert(ref.getProjectId(), ref.getDatasetId(), table)
.execute();
}
return destinationTable;
} catch (IOException e) {
throw BigqueryJobFailureException.create(e);
private DestinationTable updateTable(final DestinationTable destinationTable) {
Table table = destinationTable.getTable();
TableReference ref = table.getTableReference();
try {
if (checkTableExists(ref.getDatasetId(), ref.getTableId())) {
// Make sure to use patch() rather than update(). The former changes only those properties
// which are specified, while the latter would change everything, blanking out unspecified
// properties.
bigquery
.tables()
.patch(ref.getProjectId(), ref.getDatasetId(), ref.getTableId(), table)
.execute();
} else {
bigquery.tables().insert(ref.getProjectId(), ref.getDatasetId(), table).execute();
}
return destinationTable;
} catch (IOException e) {
throw BigqueryJobFailureException.create(e);
}
}
@ -408,7 +404,7 @@ public class BigqueryConnection implements AutoCloseable {
.setSourceFormat(sourceFormat.toString())
.setSourceUris(ImmutableList.copyOf(sourceUris))
.setDestinationTable(dest.getTableReference())));
return transform(runJobToCompletion(job, dest), new UpdateTableFunction(), directExecutor());
return transform(runJobToCompletion(job, dest), this::updateTable, directExecutor());
}
/**
@ -421,11 +417,9 @@ public class BigqueryConnection implements AutoCloseable {
DestinationTable dest) {
if (dest.type == TableType.VIEW) {
// Use Futures.transform() rather than calling apply() directly so that any exceptions thrown
// by calling UpdateTableFunction will be propagated on the get() call, not from here.
// by calling updateTable will be propagated on the get() call, not from here.
return transform(
Futures.immediateFuture(dest.withQuery(querySql)),
new UpdateTableFunction(),
directExecutor());
Futures.immediateFuture(dest.withQuery(querySql)), this::updateTable, directExecutor());
} else {
Job job = new Job()
.setConfiguration(new JobConfiguration()
@ -434,7 +428,7 @@ public class BigqueryConnection implements AutoCloseable {
.setDefaultDataset(getDataset())
.setWriteDisposition(dest.getWriteDisposition().toString())
.setDestinationTable(dest.getTableReference())));
return transform(runJobToCompletion(job, dest), new UpdateTableFunction(), directExecutor());
return transform(runJobToCompletion(job, dest), this::updateTable, directExecutor());
}
}

View file

@ -20,7 +20,6 @@ import com.google.api.client.json.JsonFactory;
import com.google.api.services.bigquery.Bigquery;
import com.google.api.services.bigquery.BigqueryScopes;
import com.google.api.services.bigquery.model.TableFieldSchema;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import dagger.Module;
import dagger.Provides;
@ -28,6 +27,7 @@ import dagger.multibindings.Multibinds;
import google.registry.config.RegistryConfig.Config;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
/** Dagger module for Google {@link Bigquery} connection objects. */
@Module

View file

@ -18,12 +18,12 @@ import com.google.api.client.googleapis.extensions.appengine.auth.oauth2.AppIden
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.services.dataflow.Dataflow;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;
import dagger.Module;
import dagger.Provides;
import google.registry.config.RegistryConfig.Config;
import java.util.Set;
import java.util.function.Function;
/** Module for dependencies required by monthly billing actions. */
@Module

View file

@ -19,7 +19,6 @@ import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.services.dns.Dns;
import com.google.api.services.dns.DnsScopes;
import com.google.common.base.Function;
import com.google.common.util.concurrent.RateLimiter;
import dagger.Module;
import dagger.Provides;
@ -30,6 +29,7 @@ import google.registry.config.RegistryConfig.Config;
import google.registry.dns.writer.DnsWriter;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import javax.inject.Named;
/** Dagger module for Google Cloud DNS service connection objects. */

View file

@ -19,11 +19,11 @@ import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.services.drive.Drive;
import com.google.api.services.drive.DriveScopes;
import com.google.common.base.Function;
import dagger.Module;
import dagger.Provides;
import google.registry.config.RegistryConfig.Config;
import java.util.Set;
import java.util.function.Function;
/** Dagger module for Google {@link Drive} service connection objects. */
@Module

View file

@ -24,7 +24,6 @@ import static google.registry.model.domain.DomainResource.extendRegistrationWith
import static google.registry.model.index.ForeignKeyIndex.loadAndGetKey;
import static google.registry.model.ofy.ObjectifyService.ofy;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
@ -67,6 +66,7 @@ import google.registry.model.transfer.TransferStatus;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import org.joda.time.DateTime;
/** Static utility functions for resource flows. */

View file

@ -19,12 +19,12 @@ import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.services.cloudkms.v1.CloudKMS;
import com.google.api.services.cloudkms.v1.CloudKMSScopes;
import com.google.common.base.Function;
import dagger.Binds;
import dagger.Module;
import dagger.Provides;
import google.registry.config.RegistryConfig.Config;
import java.util.Set;
import java.util.function.Function;
/** Dagger module for Cloud KMS connection objects. */
@Module

View file

@ -19,7 +19,6 @@ import static com.google.appengine.api.taskqueue.QueueFactory.getQueue;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.Lists.partition;
import static com.google.common.collect.Lists.transform;
import static google.registry.security.XsrfTokenManager.X_CSRF_TOKEN;
import static google.registry.util.FormattingLogger.getLoggerForCallerClass;
import static google.registry.util.ResourceUtils.readResourceUtf8;
@ -27,7 +26,6 @@ import static java.util.Arrays.asList;
import static org.joda.time.DateTimeZone.UTC;
import com.google.appengine.api.taskqueue.TaskOptions;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterators;
import google.registry.config.RegistryEnvironment;
@ -41,6 +39,7 @@ import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.function.Function;
import javax.inject.Inject;
import org.joda.time.DateTime;
@ -235,15 +234,17 @@ public class LoadTestAction implements Runnable {
// Do successful creates on random names
tasks.addAll(
createTasks(
transform(
createNumCopies(xmlContactCreateTmpl, successfulContactCreatesPerSecond),
randomNameReplacer("%contact%", MAX_CONTACT_LENGTH)),
createNumCopies(xmlContactCreateTmpl, successfulContactCreatesPerSecond)
.stream()
.map(randomNameReplacer("%contact%", MAX_CONTACT_LENGTH))
.collect(toImmutableList()),
startSecond));
tasks.addAll(
createTasks(
transform(
createNumCopies(xmlHostCreateTmpl, successfulHostCreatesPerSecond),
randomNameReplacer("%host%", ARBITRARY_VALID_HOST_LENGTH)),
createNumCopies(xmlHostCreateTmpl, successfulHostCreatesPerSecond)
.stream()
.map(randomNameReplacer("%host%", ARBITRARY_VALID_HOST_LENGTH))
.collect(toImmutableList()),
startSecond));
tasks.addAll(
createTasks(

View file

@ -21,7 +21,6 @@ import static google.registry.util.DateTimeUtils.isAtOrAfter;
import static google.registry.util.DateTimeUtils.isBeforeOrAt;
import static google.registry.util.DateTimeUtils.latestOf;
import com.google.common.base.Function;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.Result;
import com.googlecode.objectify.cmd.Query;
@ -44,6 +43,7 @@ import google.registry.util.FormattingLogger;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import java.util.function.Function;
import javax.annotation.Nullable;
import org.joda.time.DateTime;
import org.joda.time.Interval;

View file

@ -14,15 +14,14 @@
package google.registry.model;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Maps.transformValues;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static java.util.stream.Collectors.toCollection;
import static java.util.stream.Collectors.toList;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.collect.Maps;
import com.googlecode.objectify.Key;
@ -34,6 +33,7 @@ import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NavigableMap;
@ -125,8 +125,7 @@ public abstract class ImmutableObject implements Cloneable {
Field field = entry.getKey();
Object value = entry.getValue();
sortedFields.put(
field.getName(),
field.isAnnotationPresent(DoNotHydrate.class) ? value : HYDRATOR.apply(value));
field.getName(), field.isAnnotationPresent(DoNotHydrate.class) ? value : hydrate(value));
}
return toStringHelper(sortedFields);
}
@ -141,54 +140,60 @@ public abstract class ImmutableObject implements Cloneable {
}
/** Helper function to recursively hydrate an ImmutableObject. */
private static final Function<Object, Object> HYDRATOR =
new Function<Object, Object>() {
@Override
public Object apply(Object value) {
if (value instanceof Key) {
return apply(ofy().load().key((Key<?>) value).now());
} else if (value instanceof Map) {
return transformValues((Map<?, ?>) value, this);
} else if (value instanceof Collection) {
return transform((Collection<?>) value, this);
} else if (value instanceof ImmutableObject) {
return ((ImmutableObject) value).toHydratedString();
}
return value;
}};
private static final Object hydrate(Object value) {
if (value instanceof Key) {
return hydrate(ofy().load().key((Key<?>) value).now());
} else if (value instanceof Map) {
return transformValues((Map<?, ?>) value, ImmutableObject::hydrate);
} else if (value instanceof Collection) {
return transform((Collection<?>) value, ImmutableObject::hydrate);
} else if (value instanceof ImmutableObject) {
return ((ImmutableObject) value).toHydratedString();
}
return value;
}
/** Helper function to recursively convert a ImmutableObject to a Map of generic objects. */
private static final Function<Object, Object> TO_MAP_HELPER =
new Function<Object, Object>() {
@Override
public Object apply(Object o) {
if (o == null) {
return null;
} else if (o instanceof ImmutableObject) {
// LinkedHashMap to preserve field ordering and because ImmutableMap forbids null
// values.
Map<String, Object> result = new LinkedHashMap<>();
for (Entry<Field, Object> entry : ModelUtils.getFieldValues(o).entrySet()) {
result.put(entry.getKey().getName(), apply(entry.getValue()));
}
return result;
} else if (o instanceof Map) {
return Maps.transformValues((Map<?, ?>) o, this);
} else if (o instanceof Set) {
return ((Set<?>) o).stream().map(this).collect(toImmutableSet());
} else if (o instanceof Collection) {
return ((Collection<?>) o).stream().map(this).collect(toImmutableList());
} else if (o instanceof Number || o instanceof Boolean) {
return o;
} else {
return o.toString();
}
}
};
private static Object toMapRecursive(Object o) {
if (o == null) {
return null;
} else if (o instanceof ImmutableObject) {
// LinkedHashMap to preserve field ordering and because ImmutableMap forbids null
// values.
Map<String, Object> result = new LinkedHashMap<>();
for (Entry<Field, Object> entry : ModelUtils.getFieldValues(o).entrySet()) {
result.put(entry.getKey().getName(), toMapRecursive(entry.getValue()));
}
return result;
} else if (o instanceof Map) {
return Maps.transformValues((Map<?, ?>) o, ImmutableObject::toMapRecursive);
} else if (o instanceof Set) {
return ((Set<?>) o)
.stream()
.map(ImmutableObject::toMapRecursive)
// We can't use toImmutableSet here, because values can be null (especially since the
// original ImmutableObject might have been the result of a cloneEmptyToNull call).
//
// We can't use toSet either, because we want to preserve order. So we use LinkedHashSet
// instead.
.collect(toCollection(LinkedHashSet::new));
} else if (o instanceof Collection) {
return ((Collection<?>) o)
.stream()
.map(ImmutableObject::toMapRecursive)
// We can't use toImmutableList here, because values can be null (especially since the
// original ImmutableObject might have been the result of a cloneEmptyToNull call).
.collect(toList());
} else if (o instanceof Number || o instanceof Boolean) {
return o;
} else {
return o.toString();
}
}
/** Returns a map of all object fields (including sensitive data) that's used to produce diffs. */
@SuppressWarnings("unchecked")
public Map<String, Object> toDiffableFieldMap() {
return (Map<String, Object>) TO_MAP_HELPER.apply(this);
return (Map<String, Object>) toMapRecursive(this);
}
}

View file

@ -16,7 +16,6 @@ package google.registry.model;
import static com.google.common.collect.ImmutableList.toImmutableList;
import com.google.common.base.Functions;
import com.google.common.collect.Streams;
import java.util.Collections;
import java.util.LinkedHashMap;
@ -67,7 +66,7 @@ public final class JsonMapBuilder {
name,
value == null
? Collections.EMPTY_LIST
: Streams.stream(value).map(Functions.toStringFunction()).collect(toImmutableList()));
: Streams.stream(value).map(Object::toString).collect(toImmutableList()));
return this;
}

View file

@ -17,12 +17,11 @@ package google.registry.model;
import static com.google.common.base.Predicates.instanceOf;
import static com.google.common.base.Predicates.isNull;
import static com.google.common.base.Predicates.or;
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.stream.Collectors.toCollection;
import static java.util.stream.Collectors.toList;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Predicate;
import com.google.common.cache.CacheBuilder;
@ -44,42 +43,48 @@ import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.AbstractList;
import java.util.ArrayDeque;
import java.util.Collection;
import java.util.Deque;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Stream;
/** A collection of static methods that deal with reflection on model classes. */
public class ModelUtils {
/** Caches all instance fields on an object, including non-public and inherited fields. */
private static final LoadingCache<Class<?>, ImmutableMap<String, Field>> ALL_FIELDS_CACHE =
CacheBuilder.newBuilder().build(new CacheLoader<Class<?>, ImmutableMap<String, Field>>() {
@Override
public ImmutableMap<String, Field> load(Class<?> clazz) {
Deque<Class<?>> hierarchy = new LinkedList<>();
// Walk the hierarchy up to but not including ImmutableObject (to ignore hashCode).
for (; clazz != ImmutableObject.class; clazz = clazz.getSuperclass()) {
// Add to the front, so that shadowed fields show up later in the list.
// This will mean that getFieldValues will show the most derived value.
hierarchy.addFirst(clazz);
}
Map<String, Field> fields = new LinkedHashMap<>();
for (Class<?> hierarchyClass : hierarchy) {
// Don't use hierarchyClass.getFields() because it only picks up public fields.
for (Field field : hierarchyClass.getDeclaredFields()) {
if (!Modifier.isStatic(field.getModifiers())) {
field.setAccessible(true);
fields.put(field.getName(), field);
CacheBuilder.newBuilder()
.build(
new CacheLoader<Class<?>, ImmutableMap<String, Field>>() {
@Override
public ImmutableMap<String, Field> load(Class<?> clazz) {
Deque<Class<?>> hierarchy = new ArrayDeque<>();
// Walk the hierarchy up to but not including ImmutableObject (to ignore
// hashCode).
for (; clazz != ImmutableObject.class; clazz = clazz.getSuperclass()) {
// Add to the front, so that shadowed fields show up later in the list.
// This will mean that getFieldValues will show the most derived value.
hierarchy.addFirst(clazz);
}
Map<String, Field> fields = new LinkedHashMap<>();
for (Class<?> hierarchyClass : hierarchy) {
// Don't use hierarchyClass.getFields() because it only picks up public fields.
for (Field field : hierarchyClass.getDeclaredFields()) {
if (!Modifier.isStatic(field.getModifiers())) {
field.setAccessible(true);
fields.put(field.getName(), field);
}
}
}
return ImmutableMap.copyOf(fields);
}
}
}
return ImmutableMap.copyOf(fields);
}});
});
/** Lists all instance fields on an object, including non-public and inherited fields. */
static Map<String, Field> getAllFields(Class<?> clazz) {
@ -208,53 +213,55 @@ public class ModelUtils {
}
/** Functional helper for {@link #cloneEmptyToNull}. */
private static final Function<Object, ?> CLONE_EMPTY_TO_NULL =
new Function<Object, Object>() {
@Override
public Object apply(Object obj) {
if (obj instanceof ImmutableSortedMap) {
// ImmutableSortedMapTranslatorFactory handles empty for us. If the object is null, then
// its on-save hook can't run.
return obj;
}
if ("".equals(obj)
|| (obj instanceof Collection && ((Collection<?>) obj).isEmpty())
|| (obj instanceof Map && ((Map<?, ?>) obj).isEmpty())
|| (obj != null && obj.getClass().isArray() && Array.getLength(obj) == 0)) {
return null;
}
Predicate<Object> immutableObjectOrNull = or(isNull(), instanceOf(ImmutableObject.class));
if ((obj instanceof Set || obj instanceof List)
&& Streams.stream((Iterable<?>) obj).allMatch(immutableObjectOrNull)) {
// Recurse into sets and lists, but only if they contain ImmutableObjects.
FluentIterable<?> fluent = FluentIterable.from((Iterable<?>) obj).transform(this);
return (obj instanceof List) ? newArrayList(fluent) : newLinkedHashSet(fluent);
}
if (obj instanceof Map
&& ((Map<?, ?>) obj).values().stream().allMatch(immutableObjectOrNull)) {
// Recurse into maps with ImmutableObject values.
return transformValues((Map<?, ?>) obj, this);
}
if (obj instanceof ImmutableObject) {
// Recurse on the fields of an ImmutableObject.
ImmutableObject copy = ImmutableObject.clone((ImmutableObject) obj);
for (Field field : getAllFields(obj.getClass()).values()) {
Object oldValue = getFieldValue(obj, field);
Object newValue = apply(oldValue);
if (!Objects.equals(oldValue, newValue)) {
setFieldValue(copy, field, newValue);
}
}
return copy;
}
return obj;
private static Object cloneEmptyToNullRecursive(Object obj) {
if (obj instanceof ImmutableSortedMap) {
// ImmutableSortedMapTranslatorFactory handles empty for us. If the object is null, then
// its on-save hook can't run.
return obj;
}
if (obj == null
|| obj.equals("")
|| (obj instanceof Collection && ((Collection<?>) obj).isEmpty())
|| (obj instanceof Map && ((Map<?, ?>) obj).isEmpty())
|| (obj.getClass().isArray() && Array.getLength(obj) == 0)) {
return null;
}
Predicate<Object> immutableObjectOrNull = or(isNull(), instanceOf(ImmutableObject.class));
if ((obj instanceof Set || obj instanceof List)
&& Streams.stream((Iterable<?>) obj).allMatch(immutableObjectOrNull)) {
// Recurse into sets and lists, but only if they contain ImmutableObjects.
Stream<?> stream =
Streams.stream((Iterable<?>) obj).map(ModelUtils::cloneEmptyToNullRecursive);
// We can't use toImmutable(List/Set) because the values can be null.
// We can't use toSet because we have to preserve order in the Set.
// So we use toList (accepts null) and LinkedHashSet (preserves order and accepts null)
return (obj instanceof List)
? stream.collect(toList())
: stream.collect(toCollection(LinkedHashSet::new));
}
if (obj instanceof Map && ((Map<?, ?>) obj).values().stream().allMatch(immutableObjectOrNull)) {
// Recurse into maps with ImmutableObject values.
return transformValues((Map<?, ?>) obj, ModelUtils::cloneEmptyToNullRecursive);
}
if (obj instanceof ImmutableObject) {
// Recurse on the fields of an ImmutableObject.
ImmutableObject copy = ImmutableObject.clone((ImmutableObject) obj);
for (Field field : getAllFields(obj.getClass()).values()) {
Object oldValue = getFieldValue(obj, field);
Object newValue = cloneEmptyToNullRecursive(oldValue);
if (!Objects.equals(oldValue, newValue)) {
setFieldValue(copy, field, newValue);
}
};
}
return copy;
}
return obj;
}
/** Returns a clone of the object and sets empty collections, arrays, maps and strings to null. */
@SuppressWarnings("unchecked")
protected static <T extends ImmutableObject> T cloneEmptyToNull(T obj) {
return (T) CLONE_EMPTY_TO_NULL.apply(obj);
return (T) cloneEmptyToNullRecursive(obj);
}
@VisibleForTesting

View file

@ -15,10 +15,9 @@
package google.registry.model.ofy;
import static com.googlecode.objectify.ObjectifyService.ofy;
import static google.registry.util.ObjectifyUtils.OBJECTS_TO_KEYS;
import com.google.common.base.Functions;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.Result;
@ -38,13 +37,13 @@ abstract class AugmentedDeleter implements Deleter {
@Override
public Result<Void> entities(Iterable<?> entities) {
handleDeletion(Iterables.transform(entities, OBJECTS_TO_KEYS));
handleDeletion(Iterables.transform(entities, Key::create));
return delegate.entities(entities);
}
@Override
public Result<Void> entities(Object... entities) {
handleDeletion(FluentIterable.from(entities).transform(OBJECTS_TO_KEYS));
handleDeletion(FluentIterable.from(entities).transform(Key::create));
return delegate.entities(entities);
}
@ -65,11 +64,8 @@ abstract class AugmentedDeleter implements Deleter {
// Magic to convert the type Iterable<? extends Key<?>> (a family of types which allows for
// homogeneous iterables of a fixed Key<T> type, e.g. List<Key<Lock>>, and is convenient for
// callers) into the type Iterable<Key<?>> (a concrete type of heterogeneous keys, which is
// convenient for users). We do this by passing each key through the identity function
// parameterized for Key<?>, which erases any homogeneous typing on the iterable.
// See: http://www.angelikalanger.com/GenericsFAQ/FAQSections/TypeArguments.html#FAQ104
Iterable<Key<?>> retypedKeys = Iterables.transform(keys, Functions.<Key<?>>identity());
handleDeletion(retypedKeys);
// convenient for users).
handleDeletion(ImmutableList.<Key<?>>copyOf(keys));
return delegate.keys(keys);
}

View file

@ -25,7 +25,6 @@ import static google.registry.model.ofy.CommitLogBucket.loadBucket;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.util.DateTimeUtils.isBeforeOrAt;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.googlecode.objectify.Key;
@ -153,9 +152,7 @@ class CommitLoggedWork<R> extends VoidWork {
mutations =
union(info.getSaves(), untouchedRootsWithTouchedChildren)
.stream()
.map(
(Function<Object, ImmutableObject>)
(Object saveEntity) -> CommitLogMutation.create(manifestKey, saveEntity))
.map(entity -> (ImmutableObject) CommitLogMutation.create(manifestKey, entity))
.collect(toImmutableSet());
ofy().saveWithoutBackup()
.entities(new ImmutableSet.Builder<>()

View file

@ -21,7 +21,6 @@ import static com.google.common.collect.Maps.uniqueIndex;
import static com.googlecode.objectify.ObjectifyService.ofy;
import static google.registry.config.RegistryConfig.getBaseOfyRetryDuration;
import static google.registry.util.CollectionUtils.union;
import static google.registry.util.ObjectifyUtils.OBJECTS_TO_KEYS;
import com.google.appengine.api.datastore.DatastoreFailureException;
import com.google.appengine.api.datastore.DatastoreTimeoutException;
@ -170,7 +169,7 @@ public class Ofy {
assertInTransaction();
checkState(Streams.stream(entities).allMatch(notNull()), "Can't save a null entity.");
checkProhibitedAnnotations(entities, NotBackedUp.class, VirtualEntity.class);
ImmutableMap<Key<?>, ?> keysToEntities = uniqueIndex(entities, OBJECTS_TO_KEYS);
ImmutableMap<Key<?>, ?> keysToEntities = uniqueIndex(entities, Key::create);
TRANSACTION_INFO.get().putSaves(keysToEntities);
}
};

View file

@ -14,7 +14,6 @@
package google.registry.model.ofy;
import static com.google.common.base.Functions.constant;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.collect.Maps.filterValues;
@ -76,7 +75,7 @@ class TransactionInfo {
void putDeletes(Iterable<Key<?>> keys) {
assertNotReadOnly();
changesBuilder.putAll(toMap(keys, constant(TransactionInfo.Delete.SENTINEL)));
changesBuilder.putAll(toMap(keys, k -> TransactionInfo.Delete.SENTINEL));
}
ImmutableSet<Key<?>> getTouchedKeys() {

View file

@ -14,13 +14,11 @@
package google.registry.model.registrar;
import static com.google.common.base.Functions.toStringFunction;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.collect.Sets.difference;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.util.CollectionUtils.nullToEmptyImmutableSortedCopy;
import static google.registry.util.ObjectifyUtils.OBJECTS_TO_KEYS;
import static java.util.stream.Collectors.joining;
import com.google.common.base.Enums;
@ -171,7 +169,7 @@ public class RegistrarContact extends ImmutableObject implements Jsonifiable {
.type(RegistrarContact.class)
.ancestor(registrar)
.keys()),
contacts.stream().map(OBJECTS_TO_KEYS).collect(toImmutableSet())));
contacts.stream().map(Key::create).collect(toImmutableSet())));
ofy().save().entities(contacts);
}
});
@ -272,7 +270,7 @@ public class RegistrarContact extends ImmutableObject implements Jsonifiable {
.put("emailAddress", emailAddress)
.put("phoneNumber", phoneNumber)
.put("faxNumber", faxNumber)
.put("types", getTypes().stream().map(toStringFunction()).collect(joining(",")))
.put("types", getTypes().stream().map(Object::toString).collect(joining(",")))
.put("visibleInWhoisAsAdmin", visibleInWhoisAsAdmin)
.put("visibleInWhoisAsTech", visibleInWhoisAsTech)
.put("visibleInDomainWhoisAsAbuse", visibleInDomainWhoisAsAbuse)

View file

@ -15,11 +15,10 @@
package google.registry.monitoring.metrics.contrib;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.ImmutableList.toImmutableList;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Ordering;
import com.google.common.truth.FailureMetadata;
import com.google.common.truth.Subject;
@ -63,15 +62,13 @@ abstract class AbstractMetricSubject<T, S extends AbstractMetricSubject<T, S>>
*/
protected final Set<ImmutableList<String>> expectedNondefaultLabelTuples = new HashSet<>();
/**
* Function to convert a metric point to a nice string representation for use in error messages.
*/
protected final Function<MetricPoint<T>, String> metricPointConverter =
metricPoint ->
String.format(
"%s => %s",
Joiner.on(':').join(metricPoint.labelValues()),
getMessageRepresentation(metricPoint.value()));
/** Converts a metric point to a nice string representation for use in error messages. */
protected String convertMetricPoint(MetricPoint<T> metricPoint) {
return String.format(
"%s => %s",
Joiner.on(':').join(metricPoint.labelValues()),
getMessageRepresentation(metricPoint.value()));
}
protected AbstractMetricSubject(FailureMetadata metadata, Metric<T> actual) {
super(metadata, checkNotNull(actual));
@ -101,9 +98,11 @@ abstract class AbstractMetricSubject<T, S extends AbstractMetricSubject<T, S>>
"has a value for labels",
Joiner.on(':').join(labels),
"has labeled values",
Lists.transform(
Ordering.<MetricPoint<T>>natural().sortedCopy(actual().getTimestampedValues()),
metricPointConverter));
Ordering.<MetricPoint<T>>natural()
.sortedCopy(actual().getTimestampedValues())
.stream()
.map(this::convertMetricPoint)
.collect(toImmutableList()));
}
if (!metricPoint.value().equals(value)) {
failWithBadResults(
@ -129,9 +128,11 @@ abstract class AbstractMetricSubject<T, S extends AbstractMetricSubject<T, S>>
"has a value for labels",
Joiner.on(':').join(labels),
"has labeled values",
Lists.transform(
Ordering.<MetricPoint<T>>natural().sortedCopy(actual().getTimestampedValues()),
metricPointConverter));
Ordering.<MetricPoint<T>>natural()
.sortedCopy(actual().getTimestampedValues())
.stream()
.map(this::convertMetricPoint)
.collect(toImmutableList()));
}
if (hasDefaultValue(metricPoint)) {
failWithBadResults(
@ -169,9 +170,11 @@ abstract class AbstractMetricSubject<T, S extends AbstractMetricSubject<T, S>>
"has",
"no other nondefault values",
"has labeled values",
Lists.transform(
Ordering.<MetricPoint<T>>natural().sortedCopy(actual().getTimestampedValues()),
metricPointConverter));
Ordering.<MetricPoint<T>>natural()
.sortedCopy(actual().getTimestampedValues())
.stream()
.map(this::convertMetricPoint)
.collect(toImmutableList()));
}
return andChainer();
}

View file

@ -21,7 +21,6 @@ import com.google.api.services.monitoring.v3.Monitoring;
import com.google.api.services.monitoring.v3.MonitoringScopes;
import com.google.api.services.monitoring.v3.model.MonitoredResource;
import com.google.appengine.api.modules.ModulesService;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import dagger.Module;
@ -31,6 +30,7 @@ import google.registry.monitoring.metrics.MetricReporter;
import google.registry.monitoring.metrics.MetricWriter;
import google.registry.monitoring.metrics.stackdriver.StackdriverWriter;
import java.util.Set;
import java.util.function.Function;
import org.joda.time.Duration;
/** Dagger module for Google Stackdriver service connection objects. */

View file

@ -21,15 +21,12 @@ import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.util.CollectionUtils.union;
import static google.registry.util.DomainNameUtils.ACE_PREFIX;
import com.google.common.base.Functions;
import com.google.common.base.Predicates;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.google.common.collect.Ordering;
import com.google.common.collect.Streams;
import com.google.common.net.InetAddresses;
import com.googlecode.objectify.Key;
import google.registry.config.RdapNoticeDescriptor;
@ -59,7 +56,9 @@ import java.net.URI;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Stream;
import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -1091,16 +1090,17 @@ public class RdapJsonFormatter {
*/
private static ImmutableList<String> makeStatusValueList(
ImmutableSet<StatusValue> statusValues, boolean isDeleted) {
FluentIterable<RdapStatus> iterable =
FluentIterable.from(statusValues)
.transform(Functions.forMap(statusToRdapStatusMap, RdapStatus.OBSCURED));
Stream<RdapStatus> stream =
statusValues
.stream()
.map(status -> statusToRdapStatusMap.getOrDefault(status, RdapStatus.OBSCURED));
if (isDeleted) {
iterable =
iterable
.filter(Predicates.not(Predicates.equalTo(RdapStatus.ACTIVE)))
.append(RdapStatus.REMOVED);
stream =
Stream.concat(
stream.filter(rdapStatus -> !Objects.equals(rdapStatus, RdapStatus.ACTIVE)),
Stream.of(RdapStatus.REMOVED));
}
return Streams.stream(iterable)
return stream
.map(RdapStatus::getDisplayName)
.collect(toImmutableSortedSet(Ordering.natural()))
.asList();

View file

@ -22,7 +22,6 @@ import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
import static org.joda.time.DateTimeZone.UTC;
import com.google.common.base.Ascii;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;
import com.google.common.net.InternetDomainName;
import com.googlecode.objectify.Key;
@ -59,6 +58,7 @@ import java.security.NoSuchAlgorithmException;
import java.security.ProviderException;
import java.security.SecureRandom;
import java.util.Random;
import java.util.function.Function;
import org.joda.time.DateTime;
/** Utility class that converts an {@link XjcRdeDomainElement} into a {@link DomainResource}. */

View file

@ -16,6 +16,7 @@ package google.registry.reporting;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Strings.isNullOrEmpty;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static google.registry.reporting.IcannReportingModule.MANIFEST_FILE_NAME;
import static java.nio.charset.StandardCharsets.UTF_8;
@ -119,7 +120,7 @@ public class IcannReportingStager {
return fields
.stream()
.map((schema) -> schema.getName().replace('_', '-'))
.collect(ImmutableList.toImmutableList());
.collect(toImmutableList());
}
/** Creates and stores activity reports on GCS, returns a list of files stored. */
@ -183,7 +184,7 @@ public class IcannReportingStager {
// Ignore TLD, Registrar name and IANA id
.skip(3)
.map((Object o) -> Integer.parseInt(o.toString()))
.collect(Collectors.toList());
.collect(toImmutableList());
checkState(
rowVals.size() == totals.size(),
"Number of elements in totals not equal to number of elements in row!");

View file

@ -33,7 +33,6 @@ import com.google.appengine.api.urlfetch.URLFetchService;
import com.google.appengine.api.urlfetch.URLFetchServiceFactory;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;
import dagger.Binds;
import dagger.Module;
@ -43,6 +42,7 @@ import google.registry.keyring.api.KeyModule.Key;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Set;
import java.util.function.Function;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;

View file

@ -15,7 +15,7 @@
package google.registry.request;
import com.google.auto.value.AutoValue;
import com.google.common.base.Function;
import java.util.function.Function;
/**
* Mapping of an {@link Action} to a {@link Runnable} instantiator for request handling.

View file

@ -17,7 +17,6 @@ package google.registry.request;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Throwables.throwIfUnchecked;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.Ordering;
import java.lang.reflect.InvocationTargetException;
@ -25,6 +24,7 @@ import java.lang.reflect.Method;
import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;
import java.util.function.Function;
/**
* Path prefix request router.

View file

@ -24,7 +24,6 @@ import static org.joda.time.DateTimeZone.UTC;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import com.google.common.base.Function;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Iterables;
@ -43,6 +42,7 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Stream;
import org.joda.money.BigMoney;
import org.joda.money.CurrencyUnit;

View file

@ -15,9 +15,9 @@
package google.registry.tools;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.util.FormattingLogger.getLoggerForCallerClass;
import static java.util.stream.Collectors.toList;
import static org.joda.time.DateTimeZone.UTC;
import com.beust.jcommander.Parameters;
@ -64,7 +64,8 @@ public class LockDomainCommand extends LockOrUnlockDomainCommand {
"addNameservers", ImmutableList.of(),
"addAdmins", ImmutableList.of(),
"addTechs", ImmutableList.of(),
"addStatuses", statusesToAdd.stream().map(StatusValue::getXmlName).collect(toList()),
"addStatuses",
statusesToAdd.stream().map(StatusValue::getXmlName).collect(toImmutableList()),
"remove", false,
"removeNameservers", ImmutableList.of(),
"removeAdmins", ImmutableList.of(),

View file

@ -16,7 +16,6 @@ package google.registry.tools;
import static com.google.common.base.CaseFormat.UPPER_CAMEL;
import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE;
import static com.google.common.base.Functions.toStringFunction;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
@ -227,6 +226,6 @@ public abstract class MutatingCommand extends ConfirmingCommand implements Remot
protected String prompt() {
return changedEntitiesMap.isEmpty()
? "No entity changes to apply."
: changedEntitiesMap.values().stream().map(toStringFunction()).collect(joining("\n"));
: changedEntitiesMap.values().stream().map(Object::toString).collect(joining("\n"));
}
}

View file

@ -17,7 +17,6 @@ package google.registry.tools;
import static java.util.stream.Collectors.joining;
import com.beust.jcommander.Parameters;
import com.google.common.base.Functions;
import com.google.common.collect.ComparisonChain;
import com.google.common.collect.Ordering;
import google.registry.rde.PendingDeposit;
@ -49,7 +48,7 @@ final class PendingEscrowCommand implements RemoteApiCommand {
SORTER
.sortedCopy(checker.getTldsAndWatermarksPendingDepositForRdeAndBrda().values())
.stream()
.map(Functions.toStringFunction())
.map(Object::toString)
.collect(joining("\n")));
}
}

View file

@ -15,9 +15,9 @@
package google.registry.tools;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.util.FormattingLogger.getLoggerForCallerClass;
import static java.util.stream.Collectors.toList;
import static org.joda.time.DateTimeZone.UTC;
import com.beust.jcommander.Parameters;
@ -71,7 +71,7 @@ public class UnlockDomainCommand extends LockOrUnlockDomainCommand {
"removeAdmins", ImmutableList.of(),
"removeTechs", ImmutableList.of(),
"removeStatuses",
statusesToRemove.stream().map(StatusValue::getXmlName).collect(toList()),
statusesToRemove.stream().map(StatusValue::getXmlName).collect(toImmutableList()),
"change", false));
}
}

View file

@ -18,8 +18,6 @@ import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import com.google.common.base.Function;
import com.google.common.base.Functions;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
@ -42,6 +40,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Stream;
import javax.inject.Inject;
@ -187,7 +186,7 @@ public abstract class ListObjectsAction<T extends ImmutableObject> implements Ru
// Next, add to the mapping all the aliases, with their values defined as whatever was in the
// map under the aliased field's original name.
fieldMap.putAll(
Maps.transformValues(getFieldAliases(), Functions.forMap(new HashMap<>(fieldMap))));
new HashMap<>(Maps.transformValues(getFieldAliases(), value -> fieldMap.get(value))));
Set<String> expectedFields = ImmutableSortedSet.copyOf(fieldMap.keySet());
for (String field : fields) {
checkArgument(fieldMap.containsKey(field),
@ -235,8 +234,7 @@ public abstract class ListObjectsAction<T extends ImmutableObject> implements Ru
if (isHeaderRowInUse(data)) {
// Add a row of headers (column names mapping to themselves).
Map<String, String> headerRow =
Maps.asMap(data.columnKeySet(), Functions.identity());
Map<String, String> headerRow = Maps.asMap(data.columnKeySet(), key -> key);
lines.add(rowFormatter.apply(headerRow));
// Add a row of separator lines (column names mapping to '-' * column width).

View file

@ -22,8 +22,6 @@ import static com.google.common.collect.ImmutableSet.toImmutableSet;
import com.google.common.base.Ascii;
import com.google.common.base.CharMatcher;
import com.google.common.base.Function;
import com.google.common.base.Functions;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
@ -36,6 +34,7 @@ import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import javax.annotation.Detainted;
import javax.annotation.Nullable;
import javax.annotation.Tainted;
@ -137,7 +136,7 @@ public final class FormField<I, O> {
/** Returns an optional form field named {@code name} with a specific {@code inputType}. */
public static <T> Builder<T, T> named(String name, Class<T> typeIn) {
checkArgument(!name.isEmpty());
return new Builder<>(name, checkNotNull(typeIn), typeIn, Functions.identity());
return new Builder<>(name, checkNotNull(typeIn), typeIn, x -> x);
}
/**
@ -445,8 +444,8 @@ public final class FormField<I, O> {
* @see #transform(Function)
*/
public <T> Builder<I, T> transform(Class<T> newType, Function<O, T> transform) {
return new Builder<>(name, typeIn, checkNotNull(newType),
Functions.compose(checkNotNull(transform), converter));
return new Builder<>(
name, typeIn, checkNotNull(newType), this.converter.andThen(checkNotNull(transform)));
}
/**
@ -456,7 +455,7 @@ public final class FormField<I, O> {
* which {@code transform} is expected to conform.
*/
public Builder<I, O> transform(Function<O, O> transform) {
this.converter = Functions.compose(checkNotNull(transform), converter);
this.converter = this.converter.andThen(checkNotNull(transform));
return this;
}

View file

@ -20,7 +20,6 @@ import static com.google.common.collect.Range.closed;
import static google.registry.util.DomainNameUtils.canonicalizeDomainName;
import com.google.common.base.Ascii;
import com.google.common.base.Function;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
import com.google.common.net.InternetDomainName;
@ -38,6 +37,7 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
/** Form fields for validating input for the {@code Registrar} class. */
public final class RegistrarFormFields {

View file

@ -14,7 +14,6 @@
package google.registry.ui.server.registrar;
import static com.google.common.base.Functions.toStringFunction;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static google.registry.security.JsonResponseHelper.Status.ERROR;
import static google.registry.security.JsonResponseHelper.Status.SUCCESS;
@ -118,7 +117,7 @@ public final class RegistrarPaymentSetupAction implements Runnable, JsonAction {
accountIds
.keySet()
.stream()
.map(toStringFunction())
.map(Object::toString)
.collect(toImmutableList()))));
}
}

View file

@ -21,7 +21,6 @@ import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.util.concurrent.Executors.newFixedThreadPool;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.UncheckedExecutionException;
import com.google.common.util.concurrent.Uninterruptibles;
@ -32,6 +31,7 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadFactory;
import java.util.function.Function;
/** Utilities for multithreaded operations in App Engine requests. */
public final class Concurrent {

View file

@ -1,24 +0,0 @@
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.util;
import com.google.common.base.Function;
import com.googlecode.objectify.Key;
/** Utilities for working with Objectify. */
public class ObjectifyUtils {
public static final Function<Object, Key<?>> OBJECTS_TO_KEYS = Key::create;
}

View file

@ -19,7 +19,6 @@ import static com.google.common.base.Strings.isNullOrEmpty;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.html.HtmlEscapers.htmlEscaper;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import google.registry.model.eppcommon.Address;
import google.registry.util.Idn;
@ -27,6 +26,7 @@ import google.registry.xml.UtcDateTimeAdapter;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import javax.annotation.Nullable;
import org.joda.time.DateTime;