mirror of
https://github.com/google/nomulus.git
synced 2025-08-03 00:12: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
|
@ -21,6 +21,7 @@ import static com.google.common.base.Predicates.in;
|
|||
import static com.google.common.base.Predicates.notNull;
|
||||
import static com.google.common.base.Strings.emptyToNull;
|
||||
import static com.google.common.base.Strings.nullToEmpty;
|
||||
import static com.google.common.collect.ImmutableSortedSet.toImmutableSortedSet;
|
||||
import static com.google.common.collect.Sets.immutableEnumSet;
|
||||
import static com.google.common.io.BaseEncoding.base64;
|
||||
import static google.registry.config.RegistryConfig.getDefaultRegistrarReferralUrl;
|
||||
|
@ -35,13 +36,13 @@ import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
|
|||
import static google.registry.util.X509Utils.getCertificateHash;
|
||||
import static google.registry.util.X509Utils.loadCertificate;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static java.util.Comparator.comparing;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
@ -50,6 +51,7 @@ import com.google.common.collect.ImmutableSortedSet;
|
|||
import com.google.common.collect.Ordering;
|
||||
import com.google.common.collect.Range;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.collect.Streams;
|
||||
import com.google.re2j.Pattern;
|
||||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.Work;
|
||||
|
@ -193,12 +195,9 @@ public class Registrar extends ImmutableObject implements Buildable, Jsonifiable
|
|||
* Compare two instances of {@link RegistrarContact} by their email addresses lexicographically.
|
||||
*/
|
||||
private static final Comparator<RegistrarContact> CONTACT_EMAIL_COMPARATOR =
|
||||
new Comparator<RegistrarContact>() {
|
||||
@Override
|
||||
public int compare(RegistrarContact rc1, RegistrarContact rc2) {
|
||||
return rc1.getEmailAddress().compareTo(rc2.getEmailAddress());
|
||||
}
|
||||
};
|
||||
comparing(
|
||||
(RegistrarContact arg) -> arg.getEmailAddress(),
|
||||
(String leftProperty, String rightProperty) -> leftProperty.compareTo(rightProperty));
|
||||
|
||||
/**
|
||||
* A caching {@link Supplier} of a clientId to {@link Registrar} map.
|
||||
|
@ -207,19 +206,21 @@ public class Registrar extends ImmutableObject implements Buildable, Jsonifiable
|
|||
* query inside an unrelated client-affecting transaction.
|
||||
*/
|
||||
private static final Supplier<ImmutableMap<String, Registrar>> CACHE_BY_CLIENT_ID =
|
||||
memoizeWithShortExpiration(new Supplier<ImmutableMap<String, Registrar>>() {
|
||||
@Override
|
||||
public ImmutableMap<String, Registrar> get() {
|
||||
return ofy().doTransactionless(new Work<ImmutableMap<String, Registrar>>() {
|
||||
@Override
|
||||
public ImmutableMap<String, Registrar> run() {
|
||||
ImmutableMap.Builder<String, Registrar> builder = new ImmutableMap.Builder<>();
|
||||
for (Registrar registrar : loadAll()) {
|
||||
builder.put(registrar.getClientId(), registrar);
|
||||
}
|
||||
return builder.build();
|
||||
}});
|
||||
}});
|
||||
memoizeWithShortExpiration(
|
||||
() ->
|
||||
ofy()
|
||||
.doTransactionless(
|
||||
new Work<ImmutableMap<String, Registrar>>() {
|
||||
@Override
|
||||
public ImmutableMap<String, Registrar> run() {
|
||||
ImmutableMap.Builder<String, Registrar> builder =
|
||||
new ImmutableMap.Builder<>();
|
||||
for (Registrar registrar : loadAll()) {
|
||||
builder.put(registrar.getClientId(), registrar);
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
}));
|
||||
|
||||
@Parent
|
||||
Key<EntityGroupRoot> parent = getCrossTldKey();
|
||||
|
@ -421,14 +422,13 @@ public class Registrar extends ImmutableObject implements Buildable, Jsonifiable
|
|||
BillingMethod billingMethod;
|
||||
|
||||
@NonFinalForTesting
|
||||
private static Supplier<byte[]> saltSupplier = new Supplier<byte[]>() {
|
||||
@Override
|
||||
public byte[] get() {
|
||||
// There are 32 bytes in a sha-256 hash, and the salt should generally be the same size.
|
||||
byte[] salt = new byte[32];
|
||||
new SecureRandom().nextBytes(salt);
|
||||
return salt;
|
||||
}};
|
||||
private static Supplier<byte[]> saltSupplier =
|
||||
() -> {
|
||||
// There are 32 bytes in a sha-256 hash, and the salt should generally be the same size.
|
||||
byte[] salt = new byte[32];
|
||||
new SecureRandom().nextBytes(salt);
|
||||
return salt;
|
||||
};
|
||||
|
||||
public String getClientId() {
|
||||
return clientIdentifier;
|
||||
|
@ -576,9 +576,9 @@ public class Registrar extends ImmutableObject implements Buildable, Jsonifiable
|
|||
* address.
|
||||
*/
|
||||
public ImmutableSortedSet<RegistrarContact> getContacts() {
|
||||
return FluentIterable.from(getContactsIterable())
|
||||
return Streams.stream(getContactsIterable())
|
||||
.filter(notNull())
|
||||
.toSortedSet(CONTACT_EMAIL_COMPARATOR);
|
||||
.collect(toImmutableSortedSet(CONTACT_EMAIL_COMPARATOR));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -586,16 +586,10 @@ public class Registrar extends ImmutableObject implements Buildable, Jsonifiable
|
|||
* their email address.
|
||||
*/
|
||||
public ImmutableSortedSet<RegistrarContact> getContactsOfType(final RegistrarContact.Type type) {
|
||||
return FluentIterable.from(getContactsIterable())
|
||||
return Streams.stream(getContactsIterable())
|
||||
.filter(notNull())
|
||||
.filter(
|
||||
new Predicate<RegistrarContact>() {
|
||||
@Override
|
||||
public boolean apply(@Nullable RegistrarContact contact) {
|
||||
return contact.getTypes().contains(type);
|
||||
}
|
||||
})
|
||||
.toSortedSet(CONTACT_EMAIL_COMPARATOR);
|
||||
.filter((@Nullable RegistrarContact contact) -> contact.getTypes().contains(type))
|
||||
.collect(toImmutableSortedSet(CONTACT_EMAIL_COMPARATOR));
|
||||
}
|
||||
|
||||
private Iterable<RegistrarContact> getContactsIterable() {
|
||||
|
|
|
@ -16,17 +16,17 @@ 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.Iterables.transform;
|
||||
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;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
import com.google.common.collect.Streams;
|
||||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.VoidWork;
|
||||
import com.googlecode.objectify.annotation.Entity;
|
||||
|
@ -141,7 +141,9 @@ public class RegistrarContact extends ImmutableObject implements Jsonifiable {
|
|||
}
|
||||
|
||||
public static ImmutableSet<Type> typesFromStrings(Iterable<String> typeNames) {
|
||||
return FluentIterable.from(typeNames).transform(Enums.stringConverter(Type.class)).toSet();
|
||||
return Streams.stream(typeNames)
|
||||
.map(Enums.stringConverter(Type.class))
|
||||
.collect(toImmutableSet());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -154,15 +156,25 @@ public class RegistrarContact extends ImmutableObject implements Jsonifiable {
|
|||
*/
|
||||
public static void updateContacts(
|
||||
final Registrar registrar, final Set<RegistrarContact> contacts) {
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy().delete().keys(difference(
|
||||
ImmutableSet.copyOf(
|
||||
ofy().load().type(RegistrarContact.class).ancestor(registrar).keys()),
|
||||
FluentIterable.from(contacts).transform(OBJECTS_TO_KEYS).toSet()));
|
||||
ofy().save().entities(contacts);
|
||||
}});
|
||||
ofy()
|
||||
.transact(
|
||||
new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy()
|
||||
.delete()
|
||||
.keys(
|
||||
difference(
|
||||
ImmutableSet.copyOf(
|
||||
ofy()
|
||||
.load()
|
||||
.type(RegistrarContact.class)
|
||||
.ancestor(registrar)
|
||||
.keys()),
|
||||
contacts.stream().map(OBJECTS_TO_KEYS).collect(toImmutableSet())));
|
||||
ofy().save().entities(contacts);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Key<Registrar> getParent() {
|
||||
|
@ -260,7 +272,7 @@ public class RegistrarContact extends ImmutableObject implements Jsonifiable {
|
|||
.put("emailAddress", emailAddress)
|
||||
.put("phoneNumber", phoneNumber)
|
||||
.put("faxNumber", faxNumber)
|
||||
.put("types", Joiner.on(',').join(transform(getTypes(), toStringFunction())))
|
||||
.put("types", getTypes().stream().map(toStringFunction()).collect(joining(",")))
|
||||
.put("visibleInWhoisAsAdmin", visibleInWhoisAsAdmin)
|
||||
.put("visibleInWhoisAsTech", visibleInWhoisAsTech)
|
||||
.put("visibleInDomainWhoisAsAbuse", visibleInDomainWhoisAsAbuse)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue