Apply Java pattern matching

This commit is contained in:
Tran Ngoc Nhan
2024-09-04 23:20:44 +07:00
committed by GitHub
parent 8f8e1d1294
commit d7058bbac6
26 changed files with 107 additions and 113 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2021-2023 the original author or authors.
* Copyright 2021-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -104,8 +104,8 @@ public class StreamRabbitListenerContainerFactory
@Override
public StreamListenerContainer createListenerContainer(RabbitListenerEndpoint endpoint) {
if (endpoint instanceof MethodRabbitListenerEndpoint && this.nativeListener) {
((MethodRabbitListenerEndpoint) endpoint).setAdapterProvider(
if (endpoint instanceof MethodRabbitListenerEndpoint methodRabbitListenerEndpoint && this.nativeListener) {
methodRabbitListenerEndpoint.setAdapterProvider(
(boolean batch, Object bean, Method method, boolean returnExceptions,
RabbitListenerErrorHandler errorHandler, @Nullable BatchingStrategy batchingStrategy) -> {

View File

@@ -338,11 +338,11 @@ public class StreamListenerContainer extends ObservableListenerContainer {
}
else {
Message message2 = this.streamConverter.toMessage(message, new StreamMessageProperties(context));
if (this.messageListener instanceof ChannelAwareMessageListener) {
if (this.messageListener instanceof ChannelAwareMessageListener channelAwareMessageListener) {
try {
observation.observe(() -> {
try {
((ChannelAwareMessageListener) this.messageListener).onMessage(message2, null);
channelAwareMessageListener.onMessage(message2, null);
if (finalSample != null) {
micrometerHolder.success(finalSample, this.streamName);
}
@@ -375,8 +375,8 @@ public class StreamListenerContainer extends ObservableListenerContainer {
private void adviseIfNeeded(MessageListener messageListener) {
this.messageListener = messageListener;
if (messageListener instanceof StreamMessageListener) {
this.streamListener = (StreamMessageListener) messageListener;
if (messageListener instanceof StreamMessageListener streamMessageListener) {
this.streamListener = streamMessageListener;
}
if (this.adviceChain != null && this.adviceChain.length > 0) {
ProxyFactory factory = new ProxyFactory(messageListener);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2021 the original author or authors.
* Copyright 2021-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -115,35 +115,35 @@ public class DefaultStreamMessageConverter implements StreamMessageConverter {
}
private void mapProp(String key, Object val, ApplicationPropertiesBuilder builder) { // NOSONAR - complexity
if (val instanceof String) {
builder.entry(key, (String) val);
if (val instanceof String string) {
builder.entry(key, string);
}
else if (val instanceof Long) {
builder.entry(key, (Long) val);
else if (val instanceof Long longValue) {
builder.entry(key, longValue);
}
else if (val instanceof Integer) {
builder.entry(key, (Integer) val);
else if (val instanceof Integer intValue) {
builder.entry(key, intValue);
}
else if (val instanceof Short) {
builder.entry(key, (Short) val);
else if (val instanceof Short shortValue) {
builder.entry(key, shortValue);
}
else if (val instanceof Byte) {
builder.entry(key, (Byte) val);
else if (val instanceof Byte byteValue) {
builder.entry(key, byteValue);
}
else if (val instanceof Double) {
builder.entry(key, (Double) val);
else if (val instanceof Double doubleValue) {
builder.entry(key, doubleValue);
}
else if (val instanceof Float) {
builder.entry(key, (Float) val);
else if (val instanceof Float floatValue) {
builder.entry(key, floatValue);
}
else if (val instanceof Character) {
builder.entry(key, (Character) val);
else if (val instanceof Character character) {
builder.entry(key, character);
}
else if (val instanceof UUID) {
builder.entry(key, (UUID) val);
else if (val instanceof UUID uuid) {
builder.entry(key, uuid);
}
else if (val instanceof byte[]) {
builder.entry(key, (byte[]) val);
else if (val instanceof byte[] bytes) {
builder.entry(key, bytes);
}
}