mirror of
https://github.com/google/nomulus.git
synced 2025-05-15 00:47:11 +02:00
Run automatic Java 8 conversion over codebase
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=171174380
This commit is contained in:
parent
44df5da771
commit
5edb7935ed
190 changed files with 2312 additions and 3096 deletions
|
@ -16,19 +16,18 @@ package google.registry.util;
|
|||
|
||||
import static com.google.appengine.api.ThreadManager.currentRequestThreadFactory;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.collect.ImmutableList.toImmutableList;
|
||||
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.FluentIterable;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.util.concurrent.UncheckedExecutionException;
|
||||
import com.google.common.util.concurrent.Uninterruptibles;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Future;
|
||||
|
@ -71,17 +70,13 @@ public final class Concurrent {
|
|||
// are not compatible with code that needs to interact with App Engine (such as Objectify),
|
||||
// which we often have in funk when calling Concurrent.transform().
|
||||
// For more info see: http://stackoverflow.com/questions/15976406
|
||||
return FluentIterable.from(items).transform(funk).toList();
|
||||
return items.stream().map(funk).collect(toImmutableList());
|
||||
}
|
||||
ExecutorService executor = newFixedThreadPool(threadCount, threadFactory);
|
||||
try {
|
||||
List<Future<B>> futures = new ArrayList<>();
|
||||
for (final A item : items) {
|
||||
futures.add(executor.submit(new Callable<B>() {
|
||||
@Override
|
||||
public B call() {
|
||||
return funk.apply(item);
|
||||
}}));
|
||||
futures.add(executor.submit(() -> funk.apply(item)));
|
||||
}
|
||||
ImmutableList.Builder<B> results = new ImmutableList.Builder<>();
|
||||
for (Future<B> future : futures) {
|
||||
|
|
|
@ -22,11 +22,7 @@ import com.google.common.base.Optional;
|
|||
public class DatastoreServiceUtils {
|
||||
|
||||
/** Helper function that extracts the kind from a regular Datastore entity key. */
|
||||
public static final Function<Key, String> KEY_TO_KIND_FUNCTION = new Function<Key, String>() {
|
||||
@Override
|
||||
public String apply(Key key) {
|
||||
return key.getKind();
|
||||
}};
|
||||
public static final Function<Key, String> KEY_TO_KIND_FUNCTION = Key::getKind;
|
||||
|
||||
/** Returns the name or id of a key, which may be a string or a long. */
|
||||
public static Object getNameOrId(Key key) {
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
package google.registry.util;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
|
@ -44,13 +43,10 @@ public class FormattingLogger {
|
|||
}
|
||||
|
||||
private void log(Level level, @Nullable Throwable cause, String msg) {
|
||||
StackTraceElement callerFrame = FluentIterable
|
||||
.from(new Exception().getStackTrace())
|
||||
.firstMatch(new Predicate<StackTraceElement>() {
|
||||
@Override
|
||||
public boolean apply(StackTraceElement frame) {
|
||||
return !frame.getClassName().equals(FormattingLogger.class.getName());
|
||||
}}).get();
|
||||
StackTraceElement callerFrame =
|
||||
FluentIterable.from(new Exception().getStackTrace())
|
||||
.firstMatch(frame -> !frame.getClassName().equals(FormattingLogger.class.getName()))
|
||||
.get();
|
||||
if (cause == null) {
|
||||
logger.logp(level, callerFrame.getClassName(), callerFrame.getMethodName(), msg);
|
||||
} else {
|
||||
|
|
|
@ -20,9 +20,5 @@ import com.googlecode.objectify.Key;
|
|||
/** Utilities for working with Objectify. */
|
||||
public class ObjectifyUtils {
|
||||
|
||||
public static final Function<Object, Key<?>> OBJECTS_TO_KEYS = new Function<Object, Key<?>>() {
|
||||
@Override
|
||||
public Key<?> apply(Object obj) {
|
||||
return Key.create(obj);
|
||||
}};
|
||||
public static final Function<Object, Key<?>> OBJECTS_TO_KEYS = Key::create;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ package google.registry.util;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Throwables.throwIfUnchecked;
|
||||
import static com.google.common.collect.Iterables.any;
|
||||
import static com.google.common.math.IntMath.pow;
|
||||
import static google.registry.util.PredicateUtils.supertypeOf;
|
||||
|
||||
|
@ -163,10 +162,7 @@ public class Retrier implements Serializable {
|
|||
Class<? extends Throwable>... moreRetryableErrors) {
|
||||
final Set<Class<?>> retryables =
|
||||
new ImmutableSet.Builder<Class<?>>().add(retryableError).add(moreRetryableErrors).build();
|
||||
return callWithRetry(callable, failureReporter, new Predicate<Throwable>() {
|
||||
@Override
|
||||
public boolean apply(Throwable e) {
|
||||
return any(retryables, supertypeOf(e.getClass()));
|
||||
}});
|
||||
return callWithRetry(
|
||||
callable, failureReporter, e -> retryables.stream().anyMatch(supertypeOf(e.getClass())));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ import com.google.appengine.api.taskqueue.TaskOptions;
|
|||
import com.google.appengine.api.taskqueue.TransientFailureException;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/** Utilities for dealing with App Engine task queues. */
|
||||
|
@ -65,15 +64,13 @@ public class TaskEnqueuer implements Serializable {
|
|||
*/
|
||||
public List<TaskHandle> enqueue(final Queue queue, final Iterable<TaskOptions> tasks) {
|
||||
return retrier.callWithRetry(
|
||||
new Callable<List<TaskHandle>>() {
|
||||
@Override
|
||||
public List<TaskHandle> call() {
|
||||
for (TaskOptions task : tasks) {
|
||||
logger.infofmt(
|
||||
"Enqueuing queue='%s' endpoint='%s'", queue.getQueueName(), task.getUrl());
|
||||
}
|
||||
return queue.add(tasks);
|
||||
}},
|
||||
() -> {
|
||||
for (TaskOptions task : tasks) {
|
||||
logger.infofmt(
|
||||
"Enqueuing queue='%s' endpoint='%s'", queue.getQueueName(), task.getUrl());
|
||||
}
|
||||
return queue.add(tasks);
|
||||
},
|
||||
TransientFailureException.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
|
||||
package google.registry.util;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
|
@ -59,13 +59,11 @@ public final class TokenUtils {
|
|||
final TokenType type,
|
||||
StringGenerator generator,
|
||||
int count) {
|
||||
return FluentIterable.from(generator.createStrings(type.getLength(), count))
|
||||
.transform(new Function<String, String>() {
|
||||
@Override
|
||||
public String apply(String token) {
|
||||
return String.format("%s_%s", type.getPrefix(), token);
|
||||
}})
|
||||
.toSet();
|
||||
return generator
|
||||
.createStrings(type.getLength(), count)
|
||||
.stream()
|
||||
.map(token -> String.format("%s_%s", type.getPrefix(), token))
|
||||
.collect(toImmutableSet());
|
||||
}
|
||||
|
||||
private TokenUtils() {}
|
||||
|
|
|
@ -103,7 +103,7 @@ public class TypeUtils {
|
|||
/** Returns a predicate that tests whether classes are annotated with the given annotation. */
|
||||
public static final Predicate<Class<?>> hasAnnotation(
|
||||
final Class<? extends Annotation> annotation) {
|
||||
return (Class<?> clazz) -> clazz.isAnnotationPresent(annotation);
|
||||
return clazz -> clazz.isAnnotationPresent(annotation);
|
||||
}
|
||||
|
||||
public static void checkNoInheritanceRelationships(ImmutableSet<Class<?>> resourceClasses) {
|
||||
|
|
|
@ -17,12 +17,11 @@ package google.registry.util;
|
|||
import static com.google.common.base.MoreObjects.firstNonNull;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Throwables.throwIfInstanceOf;
|
||||
import static com.google.common.collect.MoreCollectors.onlyElement;
|
||||
import static com.google.common.io.BaseEncoding.base64;
|
||||
import static java.nio.charset.StandardCharsets.US_ASCII;
|
||||
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Iterables;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -72,9 +71,12 @@ public final class X509Utils {
|
|||
public static X509Certificate loadCertificate(InputStream input)
|
||||
throws CertificateParsingException {
|
||||
try {
|
||||
return Iterables.getOnlyElement(FluentIterable
|
||||
.from(CertificateFactory.getInstance("X.509").generateCertificates(input))
|
||||
.filter(X509Certificate.class));
|
||||
return CertificateFactory.getInstance("X.509")
|
||||
.generateCertificates(input)
|
||||
.stream()
|
||||
.filter(X509Certificate.class::isInstance)
|
||||
.map(X509Certificate.class::cast)
|
||||
.collect(onlyElement());
|
||||
} catch (CertificateException e) { // CertificateParsingException by specification.
|
||||
throwIfInstanceOf(e, CertificateParsingException.class);
|
||||
throw new CertificateParsingException(e);
|
||||
|
@ -114,9 +116,12 @@ public final class X509Utils {
|
|||
public static X509CRL loadCrl(String asciiCrl) throws GeneralSecurityException {
|
||||
ByteArrayInputStream input = new ByteArrayInputStream(asciiCrl.getBytes(US_ASCII));
|
||||
try {
|
||||
return Iterables.getOnlyElement(FluentIterable
|
||||
.from(CertificateFactory.getInstance("X.509").generateCRLs(input))
|
||||
.filter(X509CRL.class));
|
||||
return CertificateFactory.getInstance("X.509")
|
||||
.generateCRLs(input)
|
||||
.stream()
|
||||
.filter(X509CRL.class::isInstance)
|
||||
.map(X509CRL.class::cast)
|
||||
.collect(onlyElement());
|
||||
} catch (NoSuchElementException e) {
|
||||
throw new CRLException("No X509CRL found.");
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue