Run automatic Java 8 conversion over codebase

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=171174380
This commit is contained in:
mcilwain
2017-10-10 12:09:41 -04:00
committed by Ben McIlwain
parent 44df5da771
commit 5edb7935ed
190 changed files with 2312 additions and 3096 deletions
@@ -21,9 +21,7 @@ import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.util.CollectionUtils.isNullOrEmpty;
import static google.registry.xml.UtcDateTimeAdapter.getFormattedString;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
@@ -77,13 +75,7 @@ final class DomainWhoisResponse extends WhoisResponseImpl {
Registrar registrar = registrarOptional.get();
Optional<RegistrarContact> abuseContact =
Iterables.tryFind(
registrar.getContacts(),
new Predicate<RegistrarContact>() {
@Override
public boolean apply(@Nullable RegistrarContact contact) {
return contact.getVisibleInDomainWhoisAsAbuse();
}
});
registrar.getContacts(), RegistrarContact::getVisibleInDomainWhoisAsAbuse);
String plaintext =
new DomainEmitter()
.emitField(
@@ -97,9 +89,7 @@ final class DomainWhoisResponse extends WhoisResponseImpl {
.emitField(
"Registry Expiry Date", getFormattedString(domain.getRegistrationExpirationTime()))
.emitField("Registrar", registrar.getRegistrarName())
.emitField(
"Registrar IANA ID",
Objects.toString(registrar.getIanaIdentifier(), ""))
.emitField("Registrar IANA ID", Objects.toString(registrar.getIanaIdentifier(), ""))
// Email address is a required field for registrar contacts. Therefore as long as there
// is an abuse contact, we can get an email address from it.
.emitFieldIfDefined(
@@ -116,12 +106,7 @@ final class DomainWhoisResponse extends WhoisResponseImpl {
.emitSet(
"Name Server",
domain.loadNameserverFullyQualifiedHostNames(),
new Function<String, String>() {
@Override
public String apply(String hostName) {
return maybeFormatHostname(hostName, preferUnicode);
}
})
hostName -> maybeFormatHostname(hostName, preferUnicode))
.emitField(
"DNSSEC", isNullOrEmpty(domain.getDsData()) ? "unsigned" : "signedDelegation")
.emitWicfLink()
@@ -135,12 +120,8 @@ final class DomainWhoisResponse extends WhoisResponseImpl {
/** Returns the contact of the given type, or null if it does not exist. */
@Nullable
private Key<ContactResource> getContactReference(final Type type) {
Optional<DesignatedContact> contactOfType = tryFind(domain.getContacts(),
new Predicate<DesignatedContact>() {
@Override
public boolean apply(DesignatedContact d) {
return d.getType() == type;
}});
Optional<DesignatedContact> contactOfType =
tryFind(domain.getContacts(), d -> d.getType() == type);
return contactOfType.isPresent() ? contactOfType.get().getContactKey() : null;
}
@@ -200,12 +181,10 @@ final class DomainWhoisResponse extends WhoisResponseImpl {
return emitSet(
"Domain Status",
combinedStatuses.build(),
new Function<EppEnum, String>() {
@Override
public String apply(EppEnum status) {
String xmlName = status.getXmlName();
return String.format("%s %s%s", xmlName, ICANN_STATUS_URL_PREFIX, xmlName);
}});
status -> {
String xmlName = status.getXmlName();
return String.format("%s %s%s", xmlName, ICANN_STATUS_URL_PREFIX, xmlName);
});
}
/** Emits the message that AWIP requires accompany all domain WHOIS responses. */
@@ -15,13 +15,13 @@
package google.registry.whois;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static google.registry.model.EppResourceUtils.queryNotDeleted;
import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Streams;
import com.google.common.net.InternetDomainName;
import google.registry.model.host.HostResource;
import google.registry.model.registry.Registries;
@@ -47,16 +47,14 @@ final class NameserverLookupByIpCommand implements WhoisCommand {
@Override
public WhoisResponse executeQuery(DateTime now) throws WhoisException {
ImmutableList<HostResource> hosts = FluentIterable
.from(queryNotDeleted(HostResource.class, now, "inetAddresses", ipAddress))
.filter(new Predicate<HostResource>() {
@Override
public boolean apply(final HostResource host) {
return Registries
.findTldForName(InternetDomainName.from(host.getFullyQualifiedHostName()))
.isPresent();
}})
.toList();
ImmutableList<HostResource> hosts =
Streams.stream(queryNotDeleted(HostResource.class, now, "inetAddresses", ipAddress))
.filter(
host ->
Registries.findTldForName(
InternetDomainName.from(host.getFullyQualifiedHostName()))
.isPresent())
.collect(toImmutableList());
if (hosts.isEmpty()) {
throw new WhoisException(now, SC_NOT_FOUND, "No nameservers found.");
}
@@ -18,13 +18,11 @@ import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static google.registry.model.ofy.ObjectifyService.ofy;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.net.InetAddresses;
import google.registry.model.host.HostResource;
import google.registry.model.registrar.Registrar;
import java.net.InetAddress;
import org.joda.time.DateTime;
/** Container for WHOIS responses to a nameserver lookup queries. */
@@ -60,15 +58,7 @@ final class NameserverWhoisResponse extends WhoisResponseImpl {
emitter
.emitField(
"Server Name", maybeFormatHostname(host.getFullyQualifiedHostName(), preferUnicode))
.emitSet(
"IP Address",
host.getInetAddresses(),
new Function<InetAddress, String>() {
@Override
public String apply(InetAddress addr) {
return InetAddresses.toAddrString(addr);
}
})
.emitSet("IP Address", host.getInetAddresses(), InetAddresses::toAddrString)
.emitField("Registrar", registrar.get().getRegistrarName())
.emitField("Registrar WHOIS Server", registrar.get().getWhoisServer())
.emitField("Registrar URL", registrar.get().getReferralUrl());
@@ -45,42 +45,42 @@ final class RegistrarLookupCommand implements WhoisCommand {
* WHOIS.
*/
private static final Supplier<Map<String, Registrar>> REGISTRAR_BY_NORMALIZED_NAME_CACHE =
memoizeWithShortExpiration(new Supplier<Map<String, Registrar>>() {
@Override
public Map<String, Registrar> get() {
Map<String, Registrar> map = new HashMap<>();
// Use the normalized registrar name as a key, and ignore inactive and hidden registrars.
for (Registrar registrar : Registrar.loadAllCached()) {
if (!registrar.isLiveAndPubliclyVisible() || registrar.getRegistrarName() == null) {
continue;
}
String normalized = normalizeRegistrarName(registrar.getRegistrarName());
if (map.put(normalized, registrar) != null) {
logger.warning(normalized
+ " appeared as a normalized registrar name for more than one registrar");
}
}
// Use the normalized registrar name without its last word as a key, assuming there are
// multiple words in the name. This allows searches without LLC or INC, etc. Only insert
// if there isn't already a mapping for this string, so that if there's a registrar with a
// two word name (Go Daddy) and no business-type suffix and another registrar with just
// that first word as its name (Go), the latter will win.
for (Registrar registrar : ImmutableList.copyOf(map.values())) {
if (registrar.getRegistrarName() == null) {
continue;
}
List<String> words =
Splitter.on(CharMatcher.whitespace()).splitToList(registrar.getRegistrarName());
if (words.size() > 1) {
String normalized =
normalizeRegistrarName(Joiner.on("").join(words.subList(0, words.size() - 1)));
if (!map.containsKey(normalized)) {
map.put(normalized, registrar);
memoizeWithShortExpiration(
() -> {
Map<String, Registrar> map = new HashMap<>();
// Use the normalized registrar name as a key, and ignore inactive and hidden
// registrars.
for (Registrar registrar : Registrar.loadAllCached()) {
if (!registrar.isLiveAndPubliclyVisible() || registrar.getRegistrarName() == null) {
continue;
}
String normalized = normalizeRegistrarName(registrar.getRegistrarName());
if (map.put(normalized, registrar) != null) {
logger.warning(
normalized
+ " appeared as a normalized registrar name for more than one registrar");
}
}
}
return ImmutableMap.copyOf(map);
}});
// Use the normalized registrar name without its last word as a key, assuming there are
// multiple words in the name. This allows searches without LLC or INC, etc. Only insert
// if there isn't already a mapping for this string, so that if there's a registrar with
// a
// two word name (Go Daddy) and no business-type suffix and another registrar with just
// that first word as its name (Go), the latter will win.
for (Registrar registrar : ImmutableList.copyOf(map.values())) {
if (registrar.getRegistrarName() == null) {
continue;
}
List<String> words =
Splitter.on(CharMatcher.whitespace()).splitToList(registrar.getRegistrarName());
if (words.size() > 1) {
String normalized =
normalizeRegistrarName(Joiner.on("").join(words.subList(0, words.size() - 1)));
map.putIfAbsent(normalized, registrar);
}
}
return ImmutableMap.copyOf(map);
});
@VisibleForTesting
final String registrarName;
@@ -16,13 +16,12 @@ package google.registry.whois;
import static com.google.common.base.Preconditions.checkNotNull;
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 com.google.common.base.Optional;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.Ordering;
import google.registry.model.eppcommon.Address;
import google.registry.util.Idn;
import google.registry.xml.UtcDateTimeAdapter;
@@ -93,10 +92,7 @@ abstract class WhoisResponseImpl implements WhoisResponse {
* be to use {@link java.util.SortedSet} but that would require reworking the models.
*/
<T> E emitSet(String title, Set<T> values, Function<T, String> transform) {
return emitList(title, FluentIterable
.from(values)
.transform(transform)
.toSortedList(Ordering.natural()));
return emitList(title, values.stream().map(transform).sorted().collect(toImmutableList()));
}
/** Helper method that loops over a list of values and calls {@link #emitField}. */