Skip to content

Commit

Permalink
feat: Remove usage of Guava
Browse files Browse the repository at this point in the history
The Guava library is really convenient, but over time, most of its features became part
of the vanilla Java.

This PR removes the usage of Guava, replacing it by Java equivalents.
  • Loading branch information
Carlos Tasada committed Jun 6, 2023
1 parent 110c3fa commit ef385bb
Show file tree
Hide file tree
Showing 41 changed files with 243 additions and 292 deletions.
2 changes: 0 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ ext {

commonsIoVersion = '2.12.0'

guavaVersion = '32.0.0-jre'

javaMoneyMonetaVersion = '1.4.2'

jsonAssertVersion = '1.5.1'
Expand Down
2 changes: 0 additions & 2 deletions springwolf-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ dependencies {
implementation "org.springframework:spring-messaging"
implementation "org.springframework.boot:spring-boot-autoconfigure"

implementation "com.google.guava:guava:${guavaVersion}"

compileOnly "org.projectlombok:lombok:${lombokVersion}"
annotationProcessor "org.projectlombok:lombok:${lombokVersion}"
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.github.stavshamir.springwolf.asyncapi;

import com.google.common.collect.ImmutableMap;
import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.Message;
import lombok.extern.slf4j.Slf4j;

Expand Down Expand Up @@ -28,7 +27,7 @@ public static Object toMessageObjectOrComposition(Set<Message> messages) {
case 0 -> throw new IllegalArgumentException("messages must not be empty");
case 1 -> messages.toArray()[0];
default ->
ImmutableMap.of(ONE_OF, new ArrayList<>(messages.stream().collect(Collectors.toCollection(messageSupplier))));
Map.of(ONE_OF, new ArrayList<>(messages.stream().collect(Collectors.toCollection(messageSupplier))));
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.asyncapi.v2.binding.operation.OperationBinding;
import com.asyncapi.v2._0_0.model.channel.ChannelItem;
import com.asyncapi.v2._0_0.model.channel.operation.Operation;
import com.google.common.collect.Maps;
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.ChannelMerger;
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.ChannelsScanner;
import io.github.stavshamir.springwolf.asyncapi.scanners.classes.ComponentClassScanner;
Expand Down Expand Up @@ -126,7 +125,7 @@ private Optional<Map.Entry<String, ChannelItem>> mapClassToChannel(Class<?> comp
}

ChannelItem channelItem = buildChannel(component.getSimpleName(), annotatedMethods, channelBinding, operationBinding);
return Optional.of(Maps.immutableEntry(channelName, channelItem));
return Optional.of(Map.entry(channelName, channelItem));
}

private Set<Method> getAnnotatedMethods(Class<?> component) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.asyncapi.v2.binding.operation.OperationBinding;
import com.asyncapi.v2._0_0.model.channel.ChannelItem;
import com.asyncapi.v2._0_0.model.channel.operation.Operation;
import com.google.common.collect.Maps;
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.ChannelsScanner;
import io.github.stavshamir.springwolf.asyncapi.scanners.classes.ComponentClassScanner;
import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.Message;
Expand Down Expand Up @@ -104,7 +103,7 @@ private Map.Entry<String, ChannelItem> mapMethodToChannel(Method method) {
String operationId = channelName + "_publish_" + method.getName();
ChannelItem channel = buildChannel(channelBinding, payload, operationBinding, messageBinding, operationId);

return Maps.immutableEntry(channelName, channel);
return Map.entry(channelName, channel);
}

private ChannelItem buildChannel(Map<String, ? extends ChannelBinding> channelBinding,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ConsumerData implements OperationData {
* <br>
* For example:
* <code>
* ImmutableMap.of("kafka", new KafkaChannelBinding())
* Map.of("kafka", new KafkaChannelBinding())
* </code>
*/
protected Map<String, ? extends ChannelBinding> channelBinding;
Expand All @@ -57,7 +57,7 @@ public class ConsumerData implements OperationData {
* <br>
* For example:
* <code>
* ImmutableMap.of("kafka", new KafkaOperationBinding())
* Map.of("kafka", new KafkaOperationBinding())
* </code>
*/
protected Map<String, ? extends OperationBinding> operationBinding;
Expand All @@ -67,7 +67,7 @@ public class ConsumerData implements OperationData {
* <br>
* For example:
* <code>
* ImmutableMap.of("kafka", new KafkaMessageBinding())
* Map.of("kafka", new KafkaMessageBinding())
* </code>
*/
protected Map<String, ? extends MessageBinding> messageBinding;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ProducerData implements OperationData {
* <br>
* For example:
* <code>
* ImmutableMap.of("kafka", new KafkaChannelBinding())
* Map.of("kafka", new KafkaChannelBinding())
* </code>
*/
protected Map<String, ? extends ChannelBinding> channelBinding;
Expand All @@ -57,7 +57,7 @@ public class ProducerData implements OperationData {
* <br>
* For example:
* <code>
* ImmutableMap.of("kafka", new KafkaOperationBinding())
* Map.of("kafka", new KafkaOperationBinding())
* </code>
*/
protected Map<String, ? extends OperationBinding> operationBinding;
Expand All @@ -67,7 +67,7 @@ public class ProducerData implements OperationData {
* <br>
* For example:
* <code>
* ImmutableMap.of("kafka", new KafkaMessageBinding())
* Map.of("kafka", new KafkaMessageBinding())
* </code>
*/
protected Map<String, ? extends MessageBinding> messageBinding;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

import java.util.List;

import static com.google.common.collect.ImmutableList.of;
import static java.util.stream.Collectors.toList;

public class AsyncHeadersForCloudEventsBuilder {

private final AsyncHeaders headers;
Expand All @@ -25,11 +22,11 @@ public AsyncHeadersForCloudEventsBuilder(String newSchemaName, AsyncHeaders base
}

public AsyncHeadersForCloudEventsBuilder withContentTypeHeader(MediaType contentType) {
return withContentTypeHeader(contentType, of(contentType));
return withContentTypeHeader(contentType, List.of(contentType));
}

public AsyncHeadersForCloudEventsBuilder withContentTypeHeader(MediaType exampleContentType, List<MediaType> contentTypeValues) {
List<String> contentTypeStringValues = contentTypeValues.stream().map(MimeType::toString).collect(toList());
List<String> contentTypeStringValues = contentTypeValues.stream().map(MimeType::toString).toList();
return withHeader(
"content-type",
contentTypeStringValues,
Expand All @@ -39,7 +36,7 @@ public AsyncHeadersForCloudEventsBuilder withContentTypeHeader(MediaType example
}

public AsyncHeadersForCloudEventsBuilder withSpecVersionHeader(String specVersion) {
return withSpecVersionHeader(specVersion, of(specVersion));
return withSpecVersionHeader(specVersion, List.of(specVersion));
}

public AsyncHeadersForCloudEventsBuilder withSpecVersionHeader(String specVersion, List<String> specValues) {
Expand All @@ -52,7 +49,7 @@ public AsyncHeadersForCloudEventsBuilder withSpecVersionHeader(String specVersio
}

public AsyncHeadersForCloudEventsBuilder withIdHeader(String idExample) {
return withIdHeader(idExample, of(idExample));
return withIdHeader(idExample, List.of(idExample));
}

public AsyncHeadersForCloudEventsBuilder withIdHeader(String idExample, List<String> idValues) {
Expand All @@ -65,7 +62,7 @@ public AsyncHeadersForCloudEventsBuilder withIdHeader(String idExample, List<Str
}

public AsyncHeadersForCloudEventsBuilder withTimeHeader(String timeExample) {
return withTimeHeader(timeExample, of(timeExample));
return withTimeHeader(timeExample, List.of(timeExample));
}

public AsyncHeadersForCloudEventsBuilder withTimeHeader(String timeExample, List<String> timeValues) {
Expand All @@ -78,7 +75,7 @@ public AsyncHeadersForCloudEventsBuilder withTimeHeader(String timeExample, List
}

public AsyncHeadersForCloudEventsBuilder withTypeHeader(String typeExample) {
return withTypeHeader(typeExample, of(typeExample));
return withTypeHeader(typeExample, List.of(typeExample));
}

public AsyncHeadersForCloudEventsBuilder withTypeHeader(String typeExample, List<String> typeValues) {
Expand All @@ -91,7 +88,7 @@ public AsyncHeadersForCloudEventsBuilder withTypeHeader(String typeExample, List
}

public AsyncHeadersForCloudEventsBuilder withSourceHeader(String sourceExample) {
return withSourceHeader(sourceExample, of(sourceExample));
return withSourceHeader(sourceExample, List.of(sourceExample));
}

public AsyncHeadersForCloudEventsBuilder withSourceHeader(String sourceExample, List<String> sourceValues) {
Expand All @@ -104,7 +101,7 @@ public AsyncHeadersForCloudEventsBuilder withSourceHeader(String sourceExample,
}

public AsyncHeadersForCloudEventsBuilder withSubjectHeader(String subjectExample) {
return withSubjectHeader(subjectExample, of(subjectExample));
return withSubjectHeader(subjectExample, List.of(subjectExample));
}

public AsyncHeadersForCloudEventsBuilder withSubjectHeader(String subjectExample, List<String> subjectValues) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.asyncapi.v2.binding.operation.OperationBinding;
import com.asyncapi.v2.binding.operation.kafka.KafkaOperationBinding;
import com.asyncapi.v2.schema.Type;
import com.google.common.collect.ImmutableMap;
import io.github.stavshamir.springwolf.asyncapi.types.AsyncAPI;
import io.github.stavshamir.springwolf.asyncapi.types.Components;
import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.Message;
Expand Down Expand Up @@ -72,7 +71,7 @@ private AsyncAPI getAsyncAPITestObject() {
.name("io.github.stavshamir.springwolf.ExamplePayload")
.title("Example Payload")
.payload(PayloadReference.fromModelName("ExamplePayload"))
.bindings(ImmutableMap.of("kafka", new KafkaMessageBinding(new StringSchema(), null, null, null, "binding-version-1")))
.bindings(Map.of("kafka", new KafkaMessageBinding(new StringSchema(), null, null, null, "binding-version-1")))
.build();

com.asyncapi.v2.schema.Schema groupId = new com.asyncapi.v2.schema.Schema();
Expand All @@ -84,7 +83,7 @@ private AsyncAPI getAsyncAPITestObject() {
.description("Auto-generated description")
.operationId("new-user_listenerMethod_subscribe")
.message(message)
.bindings(ImmutableMap.of("kafka", operationBinding))
.bindings(Map.of("kafka", operationBinding))
.build();

ChannelItem newUserChannel = ChannelItem.builder()
Expand All @@ -97,8 +96,8 @@ private AsyncAPI getAsyncAPITestObject() {
AsyncAPI asyncapi = AsyncAPI.builder()
.info(info)
.defaultContentType("application/json")
.servers(ImmutableMap.of("production", productionServer))
.channels(ImmutableMap.of("new-user", newUserChannel))
.servers(Map.of("production", productionServer))
.channels(Map.of("new-user", newUserChannel))
.components(Components.builder().schemas(schemas).build())
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.asyncapi.v2._0_0.model.channel.ChannelItem;
import com.asyncapi.v2._0_0.model.info.Info;
import com.asyncapi.v2._0_0.model.server.Server;
import com.google.common.collect.ImmutableMap;
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.ConsumerOperationDataScanner;
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.ProducerOperationDataScanner;
import io.github.stavshamir.springwolf.asyncapi.types.ConsumerData;
Expand Down Expand Up @@ -53,16 +52,16 @@ public AsyncApiDocket docket() {
.channelName("producer-topic")
.description("producer-topic-description")
.payloadType(String.class)
.operationBinding(ImmutableMap.of("kafka", new KafkaOperationBinding()))
.messageBinding(ImmutableMap.of("kafka", new KafkaMessageBinding()))
.operationBinding(Map.of("kafka", new KafkaOperationBinding()))
.messageBinding(Map.of("kafka", new KafkaMessageBinding()))
.build();

ConsumerData kafkaConsumerData = ConsumerData.builder()
.channelName("consumer-topic")
.description("consumer-topic-description")
.payloadType(String.class)
.operationBinding(ImmutableMap.of("kafka", new KafkaOperationBinding()))
.messageBinding(ImmutableMap.of("kafka", new KafkaMessageBinding()))
.operationBinding(Map.of("kafka", new KafkaOperationBinding()))
.messageBinding(Map.of("kafka", new KafkaMessageBinding()))
.build();

return AsyncApiDocket.builder()
Expand Down Expand Up @@ -111,7 +110,7 @@ void getAsyncAPI_producers_should_be_correct() {
final Message message = (Message) channel.getSubscribe().getMessage();
// Message description is not supported yet
assertThat(message.getDescription()).isNull();
assertThat(message.getBindings()).isEqualTo(ImmutableMap.of("kafka", new KafkaMessageBinding()));
assertThat(message.getBindings()).isEqualTo(Map.of("kafka", new KafkaMessageBinding()));
}

@Test
Expand All @@ -127,7 +126,7 @@ void getAsyncAPI_consumers_should_be_correct() {
final Message message = (Message) channel.getPublish().getMessage();
// Message description is not supported yet
assertThat(message.getDescription()).isNull();
assertThat(message.getBindings()).isEqualTo(ImmutableMap.of("kafka", new KafkaMessageBinding()));
assertThat(message.getBindings()).isEqualTo(Map.of("kafka", new KafkaMessageBinding()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.asyncapi.v2._0_0.model.channel.ChannelItem;
import com.asyncapi.v2._0_0.model.channel.operation.Operation;
import com.google.common.collect.ImmutableMap;
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.ChannelsScanner;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -48,15 +47,15 @@ void getChannels() {
static class FooChannelScanner implements ChannelsScanner {
@Override
public Map<String, ChannelItem> scan() {
return ImmutableMap.of("foo", new ChannelItem());
return Map.of("foo", new ChannelItem());
}
}

@Component
static class BarChannelScanner implements ChannelsScanner {
@Override
public Map<String, ChannelItem> scan() {
return ImmutableMap.of("bar", new ChannelItem());
return Map.of("bar", new ChannelItem());
}
}

Expand All @@ -73,7 +72,7 @@ static class ProduceChannelScanner implements ChannelsScanner {

@Override
public Map<String, ChannelItem> scan() {
return ImmutableMap.of(topicName, ChannelItem.builder().publish(publishOperation).build());
return Map.of(topicName, ChannelItem.builder().publish(publishOperation).build());
}
}

Expand All @@ -83,7 +82,7 @@ static class SubscribeChannelScanner implements ChannelsScanner {

@Override
public Map<String, ChannelItem> scan() {
return ImmutableMap.of(topicName, ChannelItem.builder().subscribe(subscribeOperation).build());
return Map.of(topicName, ChannelItem.builder().subscribe(subscribeOperation).build());
}
}
}
Expand Down
Loading

0 comments on commit ef385bb

Please sign in to comment.