Skip to content

Commit

Permalink
Update to guava 21.0 (#389)
Browse files Browse the repository at this point in the history
- Replaces guava helper with upstream collectors
- Replaces gross spliterator with guava utility
  • Loading branch information
anuraaga authored and trustin committed Feb 3, 2017
1 parent 9f72335 commit 8ce7f74
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 35 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Expand Up @@ -235,7 +235,7 @@ Map<String, String> map = Maps.newHashMap(); // B (Guava)
List<String> list = Collections.unmodifiableList( // A (JDK)
otherList.stream().filter(...).collect(Collectors.toList()));
List<String> list = otherList.stream().filter(...) // B (Guava)
.collect(GuavaCollectors.toImmutableList());
.collect(toImmutableList());
```

#### Prefer early-return style
Expand Down
3 changes: 0 additions & 3 deletions build.gradle
Expand Up @@ -105,9 +105,6 @@ configure(javaProjects) {
}
}

// Guava-helper
dependency "jp.skypencil.guava:helper:${ext.versionOf('guava-helper')}"

// Hamcrest
dependency "org.hamcrest:hamcrest-library:${ext.versionOf('hamcrest')}"

Expand Down
5 changes: 0 additions & 5 deletions core/build.gradle
Expand Up @@ -58,7 +58,6 @@ dependencies {
// Internal dependencies which will be shaded by the 'internalDeps' task below.
internalDependency 'com.spotify:completable-futures'
internalDependency 'it.unimi.dsi:fastutil'
internalDependency 'jp.skypencil.guava:helper'
internalDependency 'org.reflections:reflections'

// Used by the 'relocateInternalDependencies', because ShadowTask doesn't let me specify a file.
Expand Down Expand Up @@ -93,9 +92,6 @@ task trimInternalDependencies(type: ProGuardTask) {
keepclasses 'it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap',
'it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap'

// Guava Stream
keepclasses 'jp.skypencil.guava.stream.GuavaCollectors'

// Reflections
keepclasses 'org.reflections.Configuration',
'org.reflections.Reflections',
Expand All @@ -116,7 +112,6 @@ task relocateInternalDependencies(type: ShadowJar, dependsOn: tasks.trimInternal

relocate 'com.spotify.futures', 'com.linecorp.armeria.internal.futures'
relocate 'it.unimi.dsi.fastutil', 'com.linecorp.armeria.internal.fastutil'
relocate 'jp.skypencil.guava.stream', 'com.linecorp.armeria.internal.guava.stream'
relocate 'org.reflections', 'com.linecorp.armeria.internal.reflections'
}

Expand Down
Expand Up @@ -15,6 +15,7 @@
*/
package com.linecorp.armeria.client.endpoint.healthcheck;

import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static java.util.Objects.requireNonNull;

import java.util.Map;
Expand All @@ -29,7 +30,6 @@

import com.linecorp.armeria.client.Endpoint;
import com.linecorp.armeria.client.endpoint.healthcheck.HealthCheckedEndpointGroup.ServerConnection;
import com.linecorp.armeria.internal.guava.stream.GuavaCollectors;

/**
* {@link Metric}s for a {@link HealthCheckedEndpointGroup}.
Expand All @@ -56,18 +56,18 @@ public Map<String, Metric> getMetrics() {
(Gauge<Set<String>>) () -> ImmutableSet.copyOf(endpointGroup.healthyEndpoints)
.stream()
.map(Endpoint::authority)
.collect(GuavaCollectors.toImmutableSet()),
.collect(toImmutableSet()),
METRIC_NAME_PREFIX + metricName + ".unhealthy.endpoints",
(Gauge<Set<String>>) () -> {
Set<String> all = ImmutableSet.copyOf(endpointGroup.allServers)
.stream()
.map(ServerConnection::endpoint)
.map(Endpoint::authority)
.collect(GuavaCollectors.toImmutableSet());
.collect(toImmutableSet());
Set<String> healthy = ImmutableSet.copyOf(endpointGroup.healthyEndpoints)
.stream()
.map(Endpoint::authority)
.collect(GuavaCollectors.toImmutableSet());
.collect(toImmutableSet());
return Sets.difference(all, healthy);
}
);
Expand Down
Expand Up @@ -15,6 +15,8 @@
*/
package com.linecorp.armeria.client.endpoint.healthcheck;

import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableMap.toImmutableMap;
import static com.linecorp.armeria.common.util.Functions.voidFunction;
import static java.util.Objects.requireNonNull;

Expand All @@ -32,7 +34,6 @@
import com.linecorp.armeria.client.Endpoint;
import com.linecorp.armeria.client.endpoint.EndpointGroup;
import com.linecorp.armeria.internal.futures.CompletableFutures;
import com.linecorp.armeria.internal.guava.stream.GuavaCollectors;

/**
* An {@link EndpointGroup} decorator that only provides healthy {@link Endpoint}s.
Expand Down Expand Up @@ -87,7 +88,7 @@ private CompletableFuture<Void> checkAndUpdateHealthyServers() {
CompletableFuture<List<Boolean>> healthCheckResults = CompletableFutures.successfulAsList(
checkedServers.stream()
.map(connection -> connection.healthChecker.isHealthy(connection.endpoint()))
.collect(GuavaCollectors.toImmutableList()),
.collect(toImmutableList()),
t -> false);
return healthCheckResults.handle(voidFunction((result, thrown) -> {
ImmutableList.Builder<Endpoint> newHealthyEndpoints = ImmutableList.builder();
Expand All @@ -106,8 +107,8 @@ private CompletableFuture<Void> checkAndUpdateHealthyServers() {
private List<ServerConnection> updateServerList() {
Map<Endpoint, ServerConnection> allServersByEndpoint = allServers
.stream()
.collect(GuavaCollectors.toImmutableMap(ServerConnection::endpoint,
Function.identity()));
.collect(toImmutableMap(ServerConnection::endpoint,
Function.identity()));
return allServers = delegate
.endpoints()
.stream()
Expand All @@ -118,7 +119,7 @@ private List<ServerConnection> updateServerList() {
}
return new ServerConnection(endpoint, createEndpointHealthChecker(endpoint));
})
.collect(GuavaCollectors.toImmutableList());
.collect(toImmutableList());
}

/**
Expand Down
Expand Up @@ -24,7 +24,8 @@
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

import com.google.common.collect.Streams;

/**
* A set of configuration options and their respective values.
Expand Down Expand Up @@ -65,7 +66,7 @@ public abstract class AbstractOptions {
requireNonNull(values, "values");

valueMap = new IdentityHashMap<>();
putAll(valueFilter, StreamSupport.stream(values.spliterator(), false));
putAll(valueFilter, Streams.stream(values));
}

/**
Expand Down Expand Up @@ -103,7 +104,7 @@ public abstract class AbstractOptions {
requireNonNull(values, "values");

valueMap = new IdentityHashMap<>(baseOptions.valueMap);
putAll(valueFilter, StreamSupport.stream(values.spliterator(), false));
putAll(valueFilter, Streams.stream(values));
}

/**
Expand Down
Expand Up @@ -16,6 +16,7 @@

package com.linecorp.armeria.server;

import static com.google.common.collect.ImmutableList.toImmutableList;
import static java.util.Objects.requireNonNull;

import java.time.Duration;
Expand All @@ -28,7 +29,6 @@
import java.util.stream.Collectors;

import com.linecorp.armeria.common.Request;
import com.linecorp.armeria.internal.guava.stream.GuavaCollectors;

import io.netty.handler.ssl.SslContext;
import io.netty.util.DomainNameMapping;
Expand Down Expand Up @@ -150,7 +150,7 @@ public final class ServerConfig {
// Build the complete list of the services available in this server.
services = virtualHostsCopy.stream()
.flatMap(h -> h.serviceConfigs().stream())
.collect(GuavaCollectors.toImmutableList());
.collect(toImmutableList());
}

static int validateNumBosses(int numBosses) {
Expand Down
Expand Up @@ -26,13 +26,13 @@
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import javax.annotation.Nullable;

import org.apache.thrift.TBase;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Streams;
import com.google.common.net.MediaType;

import com.linecorp.armeria.common.http.HttpRequest;
Expand Down Expand Up @@ -96,8 +96,8 @@ public DocService(Iterable<? extends TBase<?, ?>> sampleRequests,
ofCatchAll(HttpFileService.forClassPath(DocService.class.getClassLoader(),
"com/linecorp/armeria/server/docs")));
requireNonNull(sampleRequests, "sampleRequests");
this.sampleRequests = StreamSupport.stream(sampleRequests.spliterator(), false)
.collect(Collectors.toMap(Object::getClass, Function.identity()));
this.sampleRequests = Streams.stream(sampleRequests)
.collect(Collectors.toMap(Object::getClass, Function.identity()));
this.sampleHttpHeaders = sampleHttpHeaders;
}

Expand Down
Expand Up @@ -16,6 +16,7 @@

package com.linecorp.armeria.server.docs;

import static com.google.common.collect.ImmutableList.toImmutableList;
import static java.util.Objects.requireNonNull;

import java.lang.reflect.Method;
Expand All @@ -37,7 +38,6 @@
import com.fasterxml.jackson.annotation.JsonProperty;

import com.linecorp.armeria.common.thrift.ThriftProtocolFactories;
import com.linecorp.armeria.internal.guava.stream.GuavaCollectors;

final class FunctionInfo {

Expand Down Expand Up @@ -121,7 +121,7 @@ private FunctionInfo(String namespace,
parameters = argsMetaData.values().stream()
.map(fieldMetaData -> FieldInfo.of(fieldMetaData,
functionNamespace, docStrings))
.collect(GuavaCollectors.toImmutableList());
.collect(toImmutableList());

FieldInfo fieldInfo = null;
if (resultClass != null) { // Function isn't "oneway" function
Expand Down
Expand Up @@ -16,6 +16,7 @@

package com.linecorp.armeria.server.thrift;

import static com.google.common.collect.ImmutableMap.toImmutableMap;
import static java.util.Objects.requireNonNull;

import java.util.List;
Expand All @@ -34,7 +35,6 @@
import com.linecorp.armeria.common.DefaultRpcResponse;
import com.linecorp.armeria.common.RpcRequest;
import com.linecorp.armeria.common.RpcResponse;
import com.linecorp.armeria.internal.guava.stream.GuavaCollectors;
import com.linecorp.armeria.internal.thrift.ThriftFunction;
import com.linecorp.armeria.server.Service;
import com.linecorp.armeria.server.ServiceRequestContext;
Expand Down Expand Up @@ -76,7 +76,7 @@ private ThriftCallService(Map<String, ?> implementations) {
}

entries = implementations.entrySet().stream().collect(
GuavaCollectors.toImmutableMap(Map.Entry::getKey, ThriftServiceEntry::new));
toImmutableMap(Map.Entry::getKey, ThriftServiceEntry::new));
}

/**
Expand Down
3 changes: 1 addition & 2 deletions gradle.properties
Expand Up @@ -7,8 +7,7 @@ brave.version=3.14.1
completable-futures.version=0.3.0
fastutil.version=7.0.13
grpc.version=1.0.3
guava.version=19.0
guava-helper.version=1.0.1
guava.version=21.0
hamcrest.version=1.3
hbase-client.version=1.2.3
httpclient.version=4.5.2
Expand Down
@@ -1,5 +1,6 @@
package com.linecorp.armeria.common.logback;

import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static java.util.Objects.requireNonNull;

import java.util.Collections;
Expand All @@ -13,7 +14,6 @@

import com.linecorp.armeria.common.http.HttpHeaderNames;
import com.linecorp.armeria.common.logback.RequestContextExporter.ExportEntry;
import com.linecorp.armeria.internal.guava.stream.GuavaCollectors;

import io.netty.util.AsciiString;
import io.netty.util.AttributeKey;
Expand Down Expand Up @@ -92,11 +92,11 @@ private static AsciiString toHeaderName(CharSequence name) {
}

Set<AsciiString> getHttpRequestHeaders() {
return httpReqHeaders.stream().map(e -> e.key).collect(GuavaCollectors.toImmutableSet());
return httpReqHeaders.stream().map(e -> e.key).collect(toImmutableSet());
}

Set<AsciiString> getHttpResponseHeaders() {
return httpResHeaders.stream().map(e -> e.key).collect(GuavaCollectors.toImmutableSet());
return httpResHeaders.stream().map(e -> e.key).collect(toImmutableSet());
}

void export(String mdcKey) {
Expand Down

0 comments on commit 8ce7f74

Please sign in to comment.