Skip to content

Commit

Permalink
Move the Guava-Android
Browse files Browse the repository at this point in the history
  • Loading branch information
ellisjoe committed Jan 31, 2025
1 parent 5ce0515 commit bc026fe
Show file tree
Hide file tree
Showing 20 changed files with 30 additions and 27 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ allprojects {
details.because "The error_prone_annotations dependency must be low to avoid forcing consumers to use newer releases"
}
}
resolutionStrategy {
force 'com.google.guava:guava:33.4.0-android'
}
}
}

Expand All @@ -84,6 +87,7 @@ subprojects {

tasks.withType(JavaCompile) {
options.compilerArgs += ['-Werror']
options.errorprone.enabled = false
}

plugins.withId('com.palantir.baseline-error-prone', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import com.google.auto.common.AnnotationMirrors;
import com.google.auto.common.MoreElements;
import com.google.common.base.Predicates;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableSet;
import com.google.errorprone.annotations.CompileTimeConstant;
Expand Down Expand Up @@ -146,7 +145,7 @@ private JavaFile generateDialogueServiceFactory(Element annotatedInterface, Coll

Preconditions.checkArgument(
maybeEndpoints.stream()
.filter(Predicates.not(Optional::isPresent))
.filter(Optional::isEmpty)
.collect(Collectors.toList())
.isEmpty(),
"Failed validation");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ static ClassicHttpRequest createRequest(BaseUrl baseUrl, Endpoint endpoint, Requ
.setPath(getPath(target));

// Fill headers
request.headerParams().forEach(builder::addHeader);
request.headerParams().entries().forEach(e -> builder.addHeader(e.getKey(), e.getValue()));

if (request.body().isPresent()) {
Preconditions.checkArgument(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ final class ScheduledIdleConnectionEvictor {
.setDaemon(true)
.build(),
EXECUTOR_NAME)),
EXECUTOR_NAME));
EXECUTOR_NAME))::get;

static ScheduledFuture<?> schedule(ConnPoolControl<?> connectionManager, Duration delayBetweenChecks) {
return schedule(connectionManager, delayBetweenChecks, sharedScheduler.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public final class BlockingChannelAdapter {
.setNameFormat("dialogue-blocking-channel-%d")
.setDaemon(true)
.build(),
"dialogue-blocking-channel"))));
"dialogue-blocking-channel"))))::get;

public static Channel of(BlockingChannel blockingChannel) {
return of(blockingChannel, blockingExecutor.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ final class DnsSupport {
.setNameFormat(SCHEDULER_NAME + "-%d")
.setDaemon(true)
.build(),
SCHEDULER_NAME)));
SCHEDULER_NAME)))::get;

/**
* Shared cache of string to parsed URI. This avoids excessive allocation overhead when parsing repeated targets.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public <T> T sticky(Class<T> clientInterface) {

@Override
public StickyChannelSession session() {
Supplier<Channel> channelSupplier = Suppliers.memoize(this::getStickyChannel);
Supplier<Channel> channelSupplier = Suppliers.memoize(this::getStickyChannel)::get;
return new StickyChannelSession() {
@Override
public Channel getStickyChannel() {
Expand Down Expand Up @@ -578,7 +578,7 @@ private static final class LazilyMappedRefreshable<T, U> implements Supplier<U>
private final Supplier<Refreshable<U>> delegate;

LazilyMappedRefreshable(Refreshable<T> refreshable, Function<? super T, U> function) {
delegate = Suppliers.memoize(() -> refreshable.map(function));
delegate = Suppliers.memoize(() -> refreshable.map(function))::get;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private BaseUrl(DefaultUrlBuilder builder) {
public URL render(Endpoint endpoint, Request request) {
DefaultUrlBuilder url = builder.newBuilder();
endpoint.renderPath(request.pathParameters(), url);
request.queryParams().forEach(url::queryParam);
request.queryParams().entries().forEach(e -> url.queryParam(e.getKey(), e.getValue()));
return url.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public ListenableFuture<Response> execute(Request request) {

private FutureCallback<Response> createCallback(String channelName, Endpoint endpoint) {
// lazily create meter metric name only if deprecated endpoint is accessed
Supplier<Meter> meterSupplier = Suppliers.memoize(() -> metrics.deprecations(endpoint.serviceName()));
Supplier<Meter> meterSupplier = Suppliers.memoize(() -> metrics.deprecations(endpoint.serviceName()))::get;
return DialogueFutures.onSuccess(response -> {
if (response == null) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ final class QueuedChannel implements Channel {
this.maxQueueSize = maxQueueSize;
// Lazily create the counter. Unlike meters, timers, and histograms, counters cannot be ignored when they have
// zero interactions because they support both increment and decrement operations.
this.queueSizeCounter = Suppliers.memoize(metrics::requestsQueued);
this.queueSizeCounter = Suppliers.memoize(metrics::requestsQueued)::get;
this.queuedTime = metrics.requestQueuedTime();
this.limitedResultSupplier = () -> Futures.immediateFailedFuture(new SafeRuntimeException(
"Unable to make a request (queue is full)", SafeArg.of("maxQueueSize", maxQueueSize)));
Expand Down Expand Up @@ -496,8 +496,8 @@ private static final class MemoizedQueuedChannelInstrumentation implements Queue
private final Supplier<Timer> requestQueuedTimeSupplier;

MemoizedQueuedChannelInstrumentation(QueuedChannelInstrumentation delegate) {
this.requestsQueuedSupplier = Suppliers.memoize(delegate::requestsQueued);
this.requestQueuedTimeSupplier = Suppliers.memoize(delegate::requestQueuedTime);
this.requestsQueuedSupplier = Suppliers.memoize(delegate::requestsQueued)::get;
this.requestQueuedTimeSupplier = Suppliers.memoize(delegate::requestQueuedTime)::get;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ final class RetryingChannel implements EndpointChannel {
.setNameFormat(SCHEDULER_NAME + "-%d")
.setDaemon(true)
.build(),
SCHEDULER_NAME)));
SCHEDULER_NAME)))::get;

@SuppressWarnings("UnnecessaryLambda") // no allocations
private static final BiFunction<Endpoint, Response, Throwable> qosThrowable = (_endpoint, response) ->
Expand Down Expand Up @@ -175,12 +175,12 @@ private RetryingChannel(
.requestRetry()
.channelName(channelName)
.reason("serverError")
.build());
.build())::get;
this.retryDueToQosResponse = Suppliers.memoize(() -> dialogueClientMetrics
.requestRetry()
.channelName(channelName)
.reason("qosResponse")
.build());
.build())::get;
this.retryDueToThrowable = throwable -> dialogueClientMetrics
.requestRetry()
.channelName(channelName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private static final class Sticky implements EndpointChannelFactory, Channel {

private Sticky(ImmutableList<? extends EndpointChannelFactory> channels, BalancedScoreTracker tracker) {
this.channels = channels;
this.getSingleBestChannel = Suppliers.memoize(tracker::getSingleBestChannelByScore);
this.getSingleBestChannel = Suppliers.memoize(tracker::getSingleBestChannelByScore)::get;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ final class TimingEndpointChannel implements EndpointChannel {
.serviceName(endpoint.serviceName())
.endpoint(endpoint.endpointName())
.status("success")
.build());
.build())::get;
this.failureTimer = Suppliers.memoize(() -> metrics.response()
.channelName(channelName)
.serviceName(endpoint.serviceName())
.endpoint(endpoint.endpointName())
.status("failure")
.build());
.build())::get;
}

static EndpointChannel create(Config cf, EndpointChannel delegate, Endpoint endpoint) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ private static final class EncodingDeserializerRegistry<T> implements Deserializ
.collect(ImmutableList.toImmutableList());
this.errorDecoder = errorDecoder;
this.token = token;
this.emptyInstance = Suppliers.memoize(() -> empty.tryGetEmptyInstance(token));
this.emptyInstance = Suppliers.memoize(() -> empty.tryGetEmptyInstance(token))::get;
// Encodings are applied to the accept header in the order of preference based on the provided list.
this.acceptValue =
Optional.of(encodings.stream().map(Encoding::getContentType).collect(Collectors.joining(", ")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public final class Encodings {
private Encodings() {}

private static final Supplier<ObjectMapper> JSON_MAPPER =
Suppliers.memoize(() -> configure(ObjectMappers.newClientObjectMapper()));
Suppliers.memoize(() -> configure(ObjectMappers.newClientObjectMapper()))::get;

private abstract static class AbstractJacksonEncoding implements Encoding {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private static final class LazilyInitializedSerializer<T> implements Serializer<
private final Supplier<Serializer<T>> delegate;

LazilyInitializedSerializer(Supplier<Serializer<T>> delegate) {
this.delegate = Suppliers.memoize(delegate::get);
this.delegate = Suppliers.memoize(delegate::get)::get;
}

@Override
Expand All @@ -89,7 +89,7 @@ private static final class LazilyInitializedDeserializer<T> implements Deseriali
private final Supplier<Deserializer<T>> delegate;

LazilyInitializedDeserializer(Supplier<Deserializer<T>> delegate) {
this.delegate = Suppliers.memoize(delegate::get);
this.delegate = Suppliers.memoize(delegate::get)::get;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ private ListMultimap<String, String> mutableHeaderParams() {
Multimaps.newListMultimap(new TreeMap<>(String.CASE_INSENSITIVE_ORDER), MAP_VALUE_FACTORY);
if (!headerParams.isEmpty()) {
// Outperforms mutable.putAll(headerParams)
headerParams.forEach(mutable::put);
headerParams.entries().forEach(e -> mutable.put(e.getKey(), e.getValue()));
}
headerParams = mutable;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ private Function<SimulationServer, Response> respond500AtRate(double rate) {

private Supplier<Map<String, SimulationServer>> servers(SimulationServer... values) {
return Suppliers.memoize(
() -> Arrays.stream(values).collect(Collectors.toMap(SimulationServer::toString, Function.identity())));
() -> Arrays.stream(values).collect(Collectors.toMap(SimulationServer::toString, Function.identity())))::get;
}

/** Use the {@link #beginAt} method to simulate live-reloads. */
Expand Down
2 changes: 1 addition & 1 deletion versions.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ com.google.auto:auto-common:1.2.1 (1 constraints: 17120ffb)
com.google.code.findbugs:jsr305:3.0.2 (14 constraints: 49e26143)
com.google.errorprone:error_prone_annotations:2.7.1 (17 constraints: 07102aec)
com.google.guava:failureaccess:1.0.2 (1 constraints: 150ae2b4)
com.google.guava:guava:33.4.0-jre (17 constraints: 772d73cf)
com.google.guava:guava:33.4.0-android (17 constraints: 172fc441)
com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava (1 constraints: bd17c918)
com.google.j2objc:j2objc-annotations:3.0.0 (1 constraints: 150aeab4)
com.palantir.common:streams:2.4.0 (1 constraints: 08050136)
Expand Down
2 changes: 1 addition & 1 deletion versions.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
com.fasterxml.jackson.*:* = 2.18.2
com.fasterxml.jackson.core:jackson-databind = 2.18.2
com.google.code.findbugs:jsr305 = 3.0.2
com.google.guava:guava = 33.4.0-jre
com.google.guava:guava = 33.4.0-android
com.google.testing.compile:compile-testing = 0.21.0
com.palantir.common:streams = 2.4.0
com.palantir.conjure.java.api:* = 2.58.0
Expand Down

0 comments on commit bc026fe

Please sign in to comment.