Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Remove usage of Guava #206

Merged
merged 2 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Expand Up @@ -11,7 +11,7 @@
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Nullable;
import org.springframework.lang.Nullable;
import java.util.Map;

@Configuration
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,14 +27,14 @@ 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))));
};
}

@SuppressWarnings("unchecked")
public static Set<Message> messageObjectToSet(Object messageObject) {
if (messageObject instanceof Message) {
return new HashSet<>(Collections.singletonList((Message) messageObject));
if (messageObject instanceof Message message) {
return new HashSet<>(Collections.singletonList(message));
}

if (messageObject instanceof Map) {
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 @@ -54,7 +54,7 @@ protected List<OperationData> getOperationData() {
return componentClassScanner.scan().stream()
.flatMap(this::getAnnotatedMethods)
.flatMap(this::toOperationData)
.collect(Collectors.toList());
.toList();
}

private Stream<Method> getAnnotatedMethods(Class<?> type) {
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 @@ -7,7 +7,7 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Nullable;
import org.springframework.lang.Nullable;
import java.util.Optional;

@Slf4j
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 @@ -110,7 +109,7 @@ void getAsyncAPI_producers_should_be_correct() {
assertThat(channel.getSubscribe()).isNotNull();
final Message message = (Message) channel.getSubscribe().getMessage();
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 @@ -125,7 +124,7 @@ void getAsyncAPI_consumers_should_be_correct() {
assertThat(channel.getPublish()).isNotNull();
final Message message = (Message) channel.getPublish().getMessage();
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