Clean up some code quality issues

This removes some qualifiers that aren't necessary (e.g. public/abstract on interfaces, private on enum constructors, final on private methods, static on nested interfaces/enums), uses Java 8 lambdas and features where that's an improvement

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=177182945
This commit is contained in:
mcilwain 2017-11-28 10:35:57 -08:00 committed by jianglai
parent 0935ba6450
commit e2db3f914e
109 changed files with 286 additions and 379 deletions

View file

@ -122,7 +122,7 @@ public interface FlowComponent {
/** Module to delegate injection of a desired {@link Flow}. */
@Module
static class FlowComponentModule {
class FlowComponentModule {
// WARNING: @FlowScope is intentionally omitted here so that we get a fresh Flow instance on
// each call to Provider<Flow>.get(), to avoid Flow instance re-use upon transaction retries.
// TODO(b/29874464): fix this in a cleaner way.

View file

@ -14,6 +14,7 @@
package google.registry.flows;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.io.BaseEncoding.base64;
import static google.registry.xml.XmlTransformer.prettyPrint;
import static java.util.Collections.EMPTY_LIST;
@ -22,6 +23,7 @@ import com.google.common.base.Ascii;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Streams;
import google.registry.flows.FlowModule.ClientId;
import google.registry.flows.FlowModule.InputXml;
import google.registry.flows.annotations.ReportingSpec;
@ -105,7 +107,7 @@ public class FlowReporter {
* just about anything could be supplied, and there's no reason to validate twice when this just
* needs to be roughly correct.
*/
private static final Optional<String> extractTld(String domainName) {
private static Optional<String> extractTld(String domainName) {
int index = domainName.indexOf('.');
return index == -1
? Optional.empty()
@ -116,22 +118,19 @@ public class FlowReporter {
* Returns the set of unique results of {@link #extractTld} applied to each given domain name,
* excluding any absent results (i.e. cases where no TLD was detected).
*/
public static final ImmutableSet<String> extractTlds(Iterable<String> domainNames) {
ImmutableSet.Builder<String> set = new ImmutableSet.Builder<>();
for (String domainName : domainNames) {
Optional<String> extractedTld = extractTld(domainName);
if (extractedTld.isPresent()) {
set.add(extractedTld.get());
}
}
return set.build();
public static ImmutableSet<String> extractTlds(Iterable<String> domainNames) {
return Streams.stream(domainNames)
.map(FlowReporter::extractTld)
.filter(Optional::isPresent)
.map(Optional::get)
.collect(toImmutableSet());
}
/**
* Returns the ICANN activity report field for the given flow class, or the empty string if no
* activity report field specification is found.
*/
private static final String extractActivityReportField(Class<? extends Flow> flowClass) {
private static String extractActivityReportField(Class<? extends Flow> flowClass) {
ReportingSpec reportingSpec = flowClass.getAnnotation(ReportingSpec.class);
if (reportingSpec != null) {
return reportingSpec.value().getFieldName();

View file

@ -24,5 +24,5 @@ import google.registry.model.eppcommon.Trid;
public interface ServerTridProvider {
/** Creates a new server Trid. */
public String createServerTrid();
String createServerTrid();
}

View file

@ -29,7 +29,7 @@ public interface TransportCredentials {
void validate(Registrar registrar, String password) throws AuthenticationErrorException;
/** Registrar password is incorrect. */
static class BadRegistrarPasswordException extends AuthenticationErrorException {
class BadRegistrarPasswordException extends AuthenticationErrorException {
public BadRegistrarPasswordException() {
super("Registrar password is incorrect");
}

View file

@ -110,7 +110,7 @@ public class AsyncFlowMetrics {
private final String metricLabelValue;
private OperationType(String metricLabelValue) {
OperationType(String metricLabelValue) {
this.metricLabelValue = metricLabelValue;
}
@ -135,7 +135,7 @@ public class AsyncFlowMetrics {
private final String metricLabelValue;
private OperationResult(String metricLabelValue) {
OperationResult(String metricLabelValue) {
this.metricLabelValue = metricLabelValue;
}

View file

@ -509,9 +509,7 @@ public class DomainFlowUtils {
// If the resultant autorenew poll message would have no poll messages to deliver, then just
// delete it. Otherwise save it with the new end time.
if (isAtOrAfter(updatedAutorenewPollMessage.getEventTime(), newEndTime)) {
if (autorenewPollMessage.isPresent()) {
ofy().delete().entity(autorenewPollMessage.get());
}
autorenewPollMessage.ifPresent(autorenew -> ofy().delete().entity(autorenew));
} else {
ofy().save().entity(updatedAutorenewPollMessage);
}

View file

@ -207,9 +207,7 @@ public final class DomainTransferApproveFlow implements TransactionalFlow {
autorenewEvent,
gainingClientPollMessage,
gainingClientAutorenewPollMessage);
if (billingEvent.isPresent()) {
entitiesToSave.add(billingEvent.get());
}
billingEvent.ifPresent(entitiesToSave::add);
ofy().save().entities(entitiesToSave.build());
// Delete the billing event and poll messages that were written in case the transfer would have
// been implicitly server approved.

View file

@ -197,9 +197,7 @@ public final class DomainTransferRequestFlow implements TransactionalFlow {
existingDomain,
trid,
gainingClientId,
(feesAndCredits.isPresent())
? Optional.of(feesAndCredits.get().getTotalCost())
: Optional.empty(),
feesAndCredits.map(FeesAndCredits::getTotalCost),
now);
// Create the transfer data that represents the pending transfer.
TransferData pendingTransferData =

View file

@ -193,9 +193,7 @@ public final class DomainUpdateFlow implements TransactionalFlow {
entitiesToSave.add(newDomain, historyEntry);
Optional<BillingEvent.OneTime> statusUpdateBillingEvent =
createBillingEventForStatusUpdates(existingDomain, newDomain, historyEntry, now);
if (statusUpdateBillingEvent.isPresent()) {
entitiesToSave.add(statusUpdateBillingEvent.get());
}
statusUpdateBillingEvent.ifPresent(entitiesToSave::add);
EntityChanges entityChanges =
customLogic.beforeSave(
BeforeSaveParameters.newBuilder()

View file

@ -113,15 +113,15 @@ public final class HostCreateFlow implements TransactionalFlow {
? new SubordinateHostMustHaveIpException()
: new UnexpectedExternalHostIpException();
}
HostResource newHost = new Builder()
.setCreationClientId(clientId)
.setPersistedCurrentSponsorClientId(clientId)
.setFullyQualifiedHostName(targetId)
.setInetAddresses(command.getInetAddresses())
.setRepoId(createRepoId(ObjectifyService.allocateId(), roidSuffix))
.setSuperordinateDomain(
superordinateDomain.isPresent() ? Key.create(superordinateDomain.get()) : null)
.build();
HostResource newHost =
new Builder()
.setCreationClientId(clientId)
.setPersistedCurrentSponsorClientId(clientId)
.setFullyQualifiedHostName(targetId)
.setInetAddresses(command.getInetAddresses())
.setRepoId(createRepoId(ObjectifyService.allocateId(), roidSuffix))
.setSuperordinateDomain(superordinateDomain.map(Key::create).orElse(null))
.build();
historyBuilder
.setType(HistoryEntry.Type.HOST_CREATE)
.setModificationTime(now)

View file

@ -152,9 +152,8 @@ public final class HostUpdateFlow implements TransactionalFlow {
AddRemove remove = command.getInnerRemove();
checkSameValuesNotAddedAndRemoved(add.getStatusValues(), remove.getStatusValues());
checkSameValuesNotAddedAndRemoved(add.getInetAddresses(), remove.getInetAddresses());
Key<DomainResource> newSuperordinateDomainKey = newSuperordinateDomain.isPresent()
? Key.create(newSuperordinateDomain.get())
: null;
Key<DomainResource> newSuperordinateDomainKey =
newSuperordinateDomain.map(Key::create).orElse(null);
// If the superordinateDomain field is changing, set the lastSuperordinateChange to now.
DateTime lastSuperordinateChange =
Objects.equals(newSuperordinateDomainKey, existingHost.getSuperordinateDomain())