Skip to content

Commit fc37712

Browse files
Modernize code for diamond, isEmpty & pattern matching
1 parent 40faaa0 commit fc37712

File tree

107 files changed

+550
-454
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+550
-454
lines changed

spring-integration-amqp/src/main/java/org/springframework/integration/amqp/channel/AbstractAmqpChannel.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -45,6 +45,7 @@
4545
* @author Mark Fisher
4646
* @author Artem Bilan
4747
* @author Gary Russell
48+
* @author Ngoc Nhan
4849
*
4950
* @since 2.1
5051
*/
@@ -94,8 +95,8 @@ public abstract class AbstractAmqpChannel extends AbstractMessageChannel impleme
9495
AbstractAmqpChannel(AmqpTemplate amqpTemplate, AmqpHeaderMapper outboundMapper, AmqpHeaderMapper inboundMapper) {
9596
Assert.notNull(amqpTemplate, "amqpTemplate must not be null");
9697
this.amqpTemplate = amqpTemplate;
97-
if (amqpTemplate instanceof RabbitTemplate) {
98-
this.rabbitTemplate = (RabbitTemplate) amqpTemplate;
98+
if (amqpTemplate instanceof RabbitTemplate castRabbitTemplate) {
99+
this.rabbitTemplate = castRabbitTemplate;
99100
MessageConverter converter = this.rabbitTemplate.getMessageConverter();
100101
if (converter instanceof AllowedListDeserializingMessageConverter allowedListMessageConverter) {
101102
allowedListMessageConverter.addAllowedListPatterns(

spring-integration-amqp/src/main/java/org/springframework/integration/amqp/channel/PollableAmqpChannel.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
* @author Mark Fisher
4848
* @author Artem Bilan
4949
* @author Gary Russell
50+
* @author Ngoc Nhan
5051
*
5152
* @since 2.1
5253
*/
@@ -167,7 +168,7 @@ protected Message<?> doReceive(Long timeout) {
167168
if (traceEnabled) {
168169
logger.trace("preReceive on channel '" + this + "'");
169170
}
170-
if (interceptorList.getInterceptors().size() > 0) {
171+
if (!interceptorList.getInterceptors().isEmpty()) {
171172
interceptorStack = new ArrayDeque<>();
172173
if (!interceptorList.preReceive(this, interceptorStack)) {
173174
return null;

spring-integration-amqp/src/main/java/org/springframework/integration/amqp/config/AmqpChannelFactoryBean.java

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
* @author Mark Fisher
6565
* @author Gary Russell
6666
* @author Artem Bilan
67+
* @author Ngoc Nhan
6768
*
6869
* @since 2.1
6970
*/
@@ -197,26 +198,26 @@ public void setQueueName(String queueName) {
197198
*/
198199

199200
public void setEncoding(String encoding) {
200-
if (this.amqpTemplate instanceof RabbitTemplate) {
201-
((RabbitTemplate) this.amqpTemplate).setEncoding(encoding);
201+
if (this.amqpTemplate instanceof RabbitTemplate rabbitTemplate) {
202+
rabbitTemplate.setEncoding(encoding);
202203
}
203204
else if (logger.isInfoEnabled()) {
204205
logger.info("AmqpTemplate is not a RabbitTemplate, so configured 'encoding' value will be ignored.");
205206
}
206207
}
207208

208209
public void setMessageConverter(MessageConverter messageConverter) {
209-
if (this.amqpTemplate instanceof RabbitTemplate) {
210-
((RabbitTemplate) this.amqpTemplate).setMessageConverter(messageConverter);
210+
if (this.amqpTemplate instanceof RabbitTemplate rabbitTemplate) {
211+
rabbitTemplate.setMessageConverter(messageConverter);
211212
}
212213
else if (logger.isInfoEnabled()) {
213214
logger.info("AmqpTemplate is not a RabbitTemplate, so configured MessageConverter will be ignored.");
214215
}
215216
}
216217

217218
public void setTemplateChannelTransacted(boolean channelTransacted) {
218-
if (this.amqpTemplate instanceof RabbitTemplate) {
219-
((RabbitTemplate) this.amqpTemplate).setChannelTransacted(channelTransacted);
219+
if (this.amqpTemplate instanceof RabbitTemplate rabbitTemplate) {
220+
rabbitTemplate.setChannelTransacted(channelTransacted);
220221
}
221222
else if (logger.isInfoEnabled()) {
222223
logger.info("AmqpTemplate is not a RabbitTemplate, so configured 'channelTransacted' will be ignored.");
@@ -233,15 +234,15 @@ public void setChannelTransacted(boolean channelTransacted) {
233234

234235
public void setConnectionFactory(ConnectionFactory connectionFactory) {
235236
this.connectionFactory = connectionFactory;
236-
if (this.amqpTemplate instanceof RabbitTemplate) {
237-
((RabbitTemplate) this.amqpTemplate).setConnectionFactory(this.connectionFactory);
237+
if (this.amqpTemplate instanceof RabbitTemplate rabbitTemplate) {
238+
rabbitTemplate.setConnectionFactory(this.connectionFactory);
238239
}
239240
}
240241

241242
public void setMessagePropertiesConverter(MessagePropertiesConverter messagePropertiesConverter) {
242243
this.messagePropertiesConverter = messagePropertiesConverter;
243-
if (this.amqpTemplate instanceof RabbitTemplate) {
244-
((RabbitTemplate) this.amqpTemplate).setMessagePropertiesConverter(messagePropertiesConverter);
244+
if (this.amqpTemplate instanceof RabbitTemplate rabbitTemplate) {
245+
rabbitTemplate.setMessagePropertiesConverter(messagePropertiesConverter);
245246
}
246247
}
247248

@@ -354,8 +355,8 @@ public Class<?> getObjectType() {
354355
protected AbstractAmqpChannel createInstance() {
355356
if (this.messageDriven) {
356357
AbstractMessageListenerContainer container = this.createContainer();
357-
if (this.amqpTemplate instanceof RabbitAccessor) {
358-
((RabbitAccessor) this.amqpTemplate).afterPropertiesSet();
358+
if (this.amqpTemplate instanceof RabbitAccessor rabbitAccessor) {
359+
rabbitAccessor.afterPropertiesSet();
359360
}
360361
if (this.isPubSub) {
361362
PublishSubscribeAmqpChannel pubsub = new PublishSubscribeAmqpChannel(
@@ -440,38 +441,38 @@ private AbstractMessageListenerContainer createContainer() {
440441

441442
@Override
442443
public boolean isAutoStartup() {
443-
return (this.channel instanceof SmartLifecycle) && ((SmartLifecycle) this.channel).isAutoStartup();
444+
return (this.channel instanceof SmartLifecycle smartLifecycle) && smartLifecycle.isAutoStartup();
444445
}
445446

446447
@Override
447448
public int getPhase() {
448-
return (this.channel instanceof SmartLifecycle) ?
449-
((SmartLifecycle) this.channel).getPhase() : 0;
449+
return (this.channel instanceof SmartLifecycle smartLifecycle) ?
450+
smartLifecycle.getPhase() : 0;
450451
}
451452

452453
@Override
453454
public boolean isRunning() {
454-
return (this.channel instanceof Lifecycle) && ((Lifecycle) this.channel).isRunning();
455+
return (this.channel instanceof Lifecycle lifecycle) && lifecycle.isRunning();
455456
}
456457

457458
@Override
458459
public void start() {
459-
if (this.channel instanceof Lifecycle) {
460-
((Lifecycle) this.channel).start();
460+
if (this.channel instanceof Lifecycle lifecycle) {
461+
lifecycle.start();
461462
}
462463
}
463464

464465
@Override
465466
public void stop() {
466-
if (this.channel instanceof Lifecycle) {
467-
((Lifecycle) this.channel).stop();
467+
if (this.channel instanceof Lifecycle lifecycle) {
468+
lifecycle.stop();
468469
}
469470
}
470471

471472
@Override
472473
public void stop(Runnable callback) {
473-
if (this.channel instanceof SmartLifecycle) {
474-
((SmartLifecycle) this.channel).stop(callback);
474+
if (this.channel instanceof SmartLifecycle smartLifecycle) {
475+
smartLifecycle.stop(callback);
475476
}
476477
else {
477478
callback.run();

spring-integration-amqp/src/main/java/org/springframework/integration/amqp/inbound/AmqpInboundChannelAdapter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
* @author Mark Fisher
6464
* @author Gary Russell
6565
* @author Artem Bilan
66+
* @author Ngoc Nhan
6667
*
6768
* @since 2.1
6869
*/
@@ -136,8 +137,8 @@ public AmqpInboundChannelAdapter(MessageListenerContainer listenerContainer) {
136137
this.messageListenerContainer = listenerContainer;
137138
this.messageListenerContainer.setAutoStartup(false);
138139
setErrorMessageStrategy(new AmqpMessageHeaderErrorMessageStrategy());
139-
this.abstractListenerContainer = listenerContainer instanceof AbstractMessageListenerContainer
140-
? (AbstractMessageListenerContainer) listenerContainer
140+
this.abstractListenerContainer = listenerContainer instanceof AbstractMessageListenerContainer abstractMessageListenerContainer
141+
? abstractMessageListenerContainer
141142
: null;
142143
}
143144

spring-integration-amqp/src/main/java/org/springframework/integration/amqp/inbound/AmqpInboundGateway.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
* @author Mark Fisher
6363
* @author Artem Bilan
6464
* @author Gary Russell
65+
* @author Ngoc Nhan
6566
*
6667
* @since 2.1
6768
*/
@@ -123,12 +124,12 @@ private AmqpInboundGateway(MessageListenerContainer listenerContainer, AmqpTempl
123124
this.messageListenerContainer.setAutoStartup(false);
124125
this.amqpTemplate = amqpTemplate;
125126
this.amqpTemplateExplicitlySet = amqpTemplateExplicitlySet;
126-
if (this.amqpTemplateExplicitlySet && this.amqpTemplate instanceof RabbitTemplate) {
127-
this.templateMessageConverter = ((RabbitTemplate) this.amqpTemplate).getMessageConverter();
127+
if (this.amqpTemplateExplicitlySet && this.amqpTemplate instanceof RabbitTemplate rabbitTemplate) {
128+
this.templateMessageConverter = rabbitTemplate.getMessageConverter();
128129
}
129130
setErrorMessageStrategy(new AmqpMessageHeaderErrorMessageStrategy());
130-
this.abstractListenerContainer = listenerContainer instanceof AbstractMessageListenerContainer
131-
? (AbstractMessageListenerContainer) listenerContainer
131+
this.abstractListenerContainer = listenerContainer instanceof AbstractMessageListenerContainer abstractMessageListenerContainer
132+
? abstractMessageListenerContainer
132133
: null;
133134
}
134135

spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AbstractAmqpOutboundEndpoint.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
* @author Gary Russell
6262
* @author Artem Bilan
6363
* @author Christian Tzolov
64+
* @author Ngoc Nhan
6465
*
6566
* @since 4.3
6667
*
@@ -594,8 +595,8 @@ protected CorrelationData generateCorrelationData(Message<?> requestMessage) {
594595
}
595596
if (correlationData == null) {
596597
Object correlation = requestMessage.getHeaders().get(AmqpHeaders.PUBLISH_CONFIRM_CORRELATION);
597-
if (correlation instanceof CorrelationData) {
598-
correlationData = (CorrelationData) correlation;
598+
if (correlation instanceof CorrelationData castCorrelationData) {
599+
correlationData = castCorrelationData;
599600
}
600601
if (correlationData != null) {
601602
correlationData = new CorrelationDataWrapper(messageId, correlationData, requestMessage);
@@ -728,8 +729,8 @@ public Message<?> getMessage() {
728729

729730
@Override
730731
public CompletableFuture<Confirm> getFuture() {
731-
if (this.userData instanceof CorrelationData) {
732-
return ((CorrelationData) this.userData).getFuture();
732+
if (this.userData instanceof CorrelationData correlationData) {
733+
return correlationData.getFuture();
733734
}
734735
else {
735736
return super.getFuture();
@@ -738,8 +739,8 @@ public CompletableFuture<Confirm> getFuture() {
738739

739740
@Override
740741
public void setReturned(ReturnedMessage returned) {
741-
if (this.userData instanceof CorrelationData) {
742-
((CorrelationData) this.userData).setReturned(returned);
742+
if (this.userData instanceof CorrelationData correlationData) {
743+
correlationData.setReturned(returned);
743744
}
744745
super.setReturned(returned);
745746
}

spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AmqpOutboundEndpoint.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -44,6 +44,7 @@
4444
* @author Oleg Zhurakousky
4545
* @author Gary Russell
4646
* @author Artem Bilan
47+
* @author Ngoc Nhan
4748
*
4849
* @since 2.1
4950
*/
@@ -67,9 +68,9 @@ public class AmqpOutboundEndpoint extends AbstractAmqpOutboundEndpoint
6768
public AmqpOutboundEndpoint(AmqpTemplate amqpTemplate) {
6869
Assert.notNull(amqpTemplate, "amqpTemplate must not be null");
6970
this.amqpTemplate = amqpTemplate;
70-
if (amqpTemplate instanceof RabbitTemplate) {
71-
setConnectionFactory(((RabbitTemplate) amqpTemplate).getConnectionFactory());
72-
this.rabbitTemplate = (RabbitTemplate) amqpTemplate;
71+
if (amqpTemplate instanceof RabbitTemplate castRabbitTemplate) {
72+
setConnectionFactory(castRabbitTemplate.getConnectionFactory());
73+
this.rabbitTemplate = castRabbitTemplate;
7374
}
7475
else {
7576
this.rabbitTemplate = null;
@@ -159,8 +160,8 @@ protected void endpointInit() {
159160

160161
@Override
161162
protected void doStop() {
162-
if (this.amqpTemplate instanceof Lifecycle) {
163-
((Lifecycle) this.amqpTemplate).stop();
163+
if (this.amqpTemplate instanceof Lifecycle lifecycle) {
164+
lifecycle.stop();
164165
}
165166
}
166167

spring-integration-cassandra/src/main/java/org/springframework/integration/cassandra/outbound/CassandraMessageHandler.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022-2023 the original author or authors.
2+
* Copyright 2022-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -60,6 +60,7 @@
6060
* @author Soby Chacko
6161
* @author Artem Bilan
6262
* @author Filippo Balicchia
63+
* @author Ngoc Nhan
6364
*
6465
* @since 6.0
6566
*/
@@ -180,11 +181,11 @@ protected void doInit() {
180181

181182
this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory());
182183
TypeLocator typeLocator = this.evaluationContext.getTypeLocator();
183-
if (typeLocator instanceof StandardTypeLocator) {
184+
if (typeLocator instanceof StandardTypeLocator standardTypeLocator) {
184185
/*
185186
* Register the Cassandra Query DSL package, so they don't need a FQCN for QueryBuilder, for example.
186187
*/
187-
((StandardTypeLocator) typeLocator).registerImport(QueryBuilder.class.getPackage().getName());
188+
standardTypeLocator.registerImport(QueryBuilder.class.getPackage().getName());
188189
}
189190
}
190191

0 commit comments

Comments
 (0)