mirror of
https://github.com/google/nomulus
synced 2026-09-04 07:07:20 +00:00
Replace FluentIterable with streams
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=180005797
This commit is contained in:
@@ -14,16 +14,17 @@
|
||||
|
||||
package google.registry.model.ofy;
|
||||
|
||||
import static com.google.common.collect.ImmutableList.toImmutableList;
|
||||
import static com.googlecode.objectify.ObjectifyService.ofy;
|
||||
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Streams;
|
||||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.Result;
|
||||
import com.googlecode.objectify.cmd.DeleteType;
|
||||
import com.googlecode.objectify.cmd.Deleter;
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* A Deleter that forwards to {@code ofy().delete()}, but can be augmented via subclassing to
|
||||
@@ -35,21 +36,25 @@ abstract class AugmentedDeleter implements Deleter {
|
||||
/** Extension method to allow this Deleter to do extra work prior to the actual delete. */
|
||||
protected abstract void handleDeletion(Iterable<Key<?>> keys);
|
||||
|
||||
private void handleDeletionStream(Stream<?> entityStream) {
|
||||
handleDeletion(entityStream.map(Key::create).collect(toImmutableList()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Void> entities(Iterable<?> entities) {
|
||||
handleDeletion(Iterables.transform(entities, Key::create));
|
||||
handleDeletionStream(Streams.stream(entities));
|
||||
return delegate.entities(entities);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Void> entities(Object... entities) {
|
||||
handleDeletion(FluentIterable.from(entities).transform(Key::create));
|
||||
handleDeletionStream(Arrays.stream(entities));
|
||||
return delegate.entities(entities);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Void> entity(Object entity) {
|
||||
handleDeletion(Arrays.asList(Key.create(entity)));
|
||||
handleDeletionStream(Stream.of(entity));
|
||||
return delegate.entity(entity);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,11 +14,10 @@
|
||||
|
||||
package google.registry.model.ofy;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.Objectify;
|
||||
import google.registry.model.BackupGroupRoot;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
@@ -43,19 +42,19 @@ class TimestampInversionException extends RuntimeException {
|
||||
|
||||
private TimestampInversionException(DateTime transactionTime, String problem) {
|
||||
super(
|
||||
Joiner.on('\n')
|
||||
.join(
|
||||
String.format(
|
||||
"Timestamp inversion between transaction time (%s) and %s",
|
||||
transactionTime, problem),
|
||||
getFileAndLine(
|
||||
FluentIterable.from(new Exception().getStackTrace())
|
||||
.firstMatch(
|
||||
(StackTraceElement element) ->
|
||||
!element
|
||||
.getClassName()
|
||||
.startsWith(Objectify.class.getPackage().getName())
|
||||
&& !element.getClassName().startsWith(Ofy.class.getName()))
|
||||
.get())));
|
||||
String.format(
|
||||
"Timestamp inversion between transaction time (%s) and %s\n%s",
|
||||
transactionTime,
|
||||
problem,
|
||||
getFileAndLine(
|
||||
Arrays.stream(new Exception().getStackTrace())
|
||||
.filter(
|
||||
element ->
|
||||
!element
|
||||
.getClassName()
|
||||
.startsWith(Objectify.class.getPackage().getName())
|
||||
&& !element.getClassName().startsWith(Ofy.class.getName()))
|
||||
.findFirst()
|
||||
.get())));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user