Skip to content

Commit 5df8694

Browse files
polish
- diamond operator - isEmpty condition
1 parent 3664c94 commit 5df8694

File tree

107 files changed

+456
-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

+456
-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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ protected Message<?> doReceive(Long timeout) {
167167
if (traceEnabled) {
168168
logger.trace("preReceive on channel '" + this + "'");
169169
}
170-
if (interceptorList.getInterceptors().size() > 0) {
170+
if (!interceptorList.getInterceptors().isEmpty()) {
171171
interceptorStack = new ArrayDeque<>();
172172
if (!interceptorList.preReceive(this, interceptorStack)) {
173173
return null;

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

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -197,26 +197,26 @@ public void setQueueName(String queueName) {
197197
*/
198198

199199
public void setEncoding(String encoding) {
200-
if (this.amqpTemplate instanceof RabbitTemplate) {
201-
((RabbitTemplate) this.amqpTemplate).setEncoding(encoding);
200+
if (this.amqpTemplate instanceof RabbitTemplate rabbitTemplate) {
201+
rabbitTemplate.setEncoding(encoding);
202202
}
203203
else if (logger.isInfoEnabled()) {
204204
logger.info("AmqpTemplate is not a RabbitTemplate, so configured 'encoding' value will be ignored.");
205205
}
206206
}
207207

208208
public void setMessageConverter(MessageConverter messageConverter) {
209-
if (this.amqpTemplate instanceof RabbitTemplate) {
210-
((RabbitTemplate) this.amqpTemplate).setMessageConverter(messageConverter);
209+
if (this.amqpTemplate instanceof RabbitTemplate rabbitTemplate) {
210+
rabbitTemplate.setMessageConverter(messageConverter);
211211
}
212212
else if (logger.isInfoEnabled()) {
213213
logger.info("AmqpTemplate is not a RabbitTemplate, so configured MessageConverter will be ignored.");
214214
}
215215
}
216216

217217
public void setTemplateChannelTransacted(boolean channelTransacted) {
218-
if (this.amqpTemplate instanceof RabbitTemplate) {
219-
((RabbitTemplate) this.amqpTemplate).setChannelTransacted(channelTransacted);
218+
if (this.amqpTemplate instanceof RabbitTemplate rabbitTemplate) {
219+
rabbitTemplate.setChannelTransacted(channelTransacted);
220220
}
221221
else if (logger.isInfoEnabled()) {
222222
logger.info("AmqpTemplate is not a RabbitTemplate, so configured 'channelTransacted' will be ignored.");
@@ -233,15 +233,15 @@ public void setChannelTransacted(boolean channelTransacted) {
233233

234234
public void setConnectionFactory(ConnectionFactory connectionFactory) {
235235
this.connectionFactory = connectionFactory;
236-
if (this.amqpTemplate instanceof RabbitTemplate) {
237-
((RabbitTemplate) this.amqpTemplate).setConnectionFactory(this.connectionFactory);
236+
if (this.amqpTemplate instanceof RabbitTemplate rabbitTemplate) {
237+
rabbitTemplate.setConnectionFactory(this.connectionFactory);
238238
}
239239
}
240240

241241
public void setMessagePropertiesConverter(MessagePropertiesConverter messagePropertiesConverter) {
242242
this.messagePropertiesConverter = messagePropertiesConverter;
243-
if (this.amqpTemplate instanceof RabbitTemplate) {
244-
((RabbitTemplate) this.amqpTemplate).setMessagePropertiesConverter(messagePropertiesConverter);
243+
if (this.amqpTemplate instanceof RabbitTemplate rabbitTemplate) {
244+
rabbitTemplate.setMessagePropertiesConverter(messagePropertiesConverter);
245245
}
246246
}
247247

@@ -354,8 +354,8 @@ public Class<?> getObjectType() {
354354
protected AbstractAmqpChannel createInstance() {
355355
if (this.messageDriven) {
356356
AbstractMessageListenerContainer container = this.createContainer();
357-
if (this.amqpTemplate instanceof RabbitAccessor) {
358-
((RabbitAccessor) this.amqpTemplate).afterPropertiesSet();
357+
if (this.amqpTemplate instanceof RabbitAccessor rabbitAccessor) {
358+
rabbitAccessor.afterPropertiesSet();
359359
}
360360
if (this.isPubSub) {
361361
PublishSubscribeAmqpChannel pubsub = new PublishSubscribeAmqpChannel(
@@ -440,38 +440,38 @@ private AbstractMessageListenerContainer createContainer() {
440440

441441
@Override
442442
public boolean isAutoStartup() {
443-
return (this.channel instanceof SmartLifecycle) && ((SmartLifecycle) this.channel).isAutoStartup();
443+
return (this.channel instanceof SmartLifecycle smartLifecycle) && smartLifecycle.isAutoStartup();
444444
}
445445

446446
@Override
447447
public int getPhase() {
448-
return (this.channel instanceof SmartLifecycle) ?
449-
((SmartLifecycle) this.channel).getPhase() : 0;
448+
return (this.channel instanceof SmartLifecycle smartLifecycle) ?
449+
smartLifecycle.getPhase() : 0;
450450
}
451451

452452
@Override
453453
public boolean isRunning() {
454-
return (this.channel instanceof Lifecycle) && ((Lifecycle) this.channel).isRunning();
454+
return (this.channel instanceof Lifecycle lifecycle) && lifecycle.isRunning();
455455
}
456456

457457
@Override
458458
public void start() {
459-
if (this.channel instanceof Lifecycle) {
460-
((Lifecycle) this.channel).start();
459+
if (this.channel instanceof Lifecycle lifecycle) {
460+
lifecycle.start();
461461
}
462462
}
463463

464464
@Override
465465
public void stop() {
466-
if (this.channel instanceof Lifecycle) {
467-
((Lifecycle) this.channel).stop();
466+
if (this.channel instanceof Lifecycle lifecycle) {
467+
lifecycle.stop();
468468
}
469469
}
470470

471471
@Override
472472
public void stop(Runnable callback) {
473-
if (this.channel instanceof SmartLifecycle) {
474-
((SmartLifecycle) this.channel).stop(callback);
473+
if (this.channel instanceof SmartLifecycle smartLifecycle) {
474+
smartLifecycle.stop(callback);
475475
}
476476
else {
477477
callback.run();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ public AmqpInboundChannelAdapter(MessageListenerContainer listenerContainer) {
136136
this.messageListenerContainer = listenerContainer;
137137
this.messageListenerContainer.setAutoStartup(false);
138138
setErrorMessageStrategy(new AmqpMessageHeaderErrorMessageStrategy());
139-
this.abstractListenerContainer = listenerContainer instanceof AbstractMessageListenerContainer
140-
? (AbstractMessageListenerContainer) listenerContainer
139+
this.abstractListenerContainer = listenerContainer instanceof AbstractMessageListenerContainer abstractMessageListenerContainer
140+
? abstractMessageListenerContainer
141141
: null;
142142
}
143143

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,12 @@ private AmqpInboundGateway(MessageListenerContainer listenerContainer, AmqpTempl
123123
this.messageListenerContainer.setAutoStartup(false);
124124
this.amqpTemplate = amqpTemplate;
125125
this.amqpTemplateExplicitlySet = amqpTemplateExplicitlySet;
126-
if (this.amqpTemplateExplicitlySet && this.amqpTemplate instanceof RabbitTemplate) {
127-
this.templateMessageConverter = ((RabbitTemplate) this.amqpTemplate).getMessageConverter();
126+
if (this.amqpTemplateExplicitlySet && this.amqpTemplate instanceof RabbitTemplate rabbitTemplate) {
127+
this.templateMessageConverter = rabbitTemplate.getMessageConverter();
128128
}
129129
setErrorMessageStrategy(new AmqpMessageHeaderErrorMessageStrategy());
130-
this.abstractListenerContainer = listenerContainer instanceof AbstractMessageListenerContainer
131-
? (AbstractMessageListenerContainer) listenerContainer
130+
this.abstractListenerContainer = listenerContainer instanceof AbstractMessageListenerContainer abstractMessageListenerContainer
131+
? abstractMessageListenerContainer
132132
: null;
133133
}
134134

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: 6 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.
@@ -67,9 +67,9 @@ public class AmqpOutboundEndpoint extends AbstractAmqpOutboundEndpoint
6767
public AmqpOutboundEndpoint(AmqpTemplate amqpTemplate) {
6868
Assert.notNull(amqpTemplate, "amqpTemplate must not be null");
6969
this.amqpTemplate = amqpTemplate;
70-
if (amqpTemplate instanceof RabbitTemplate) {
71-
setConnectionFactory(((RabbitTemplate) amqpTemplate).getConnectionFactory());
72-
this.rabbitTemplate = (RabbitTemplate) amqpTemplate;
70+
if (amqpTemplate instanceof RabbitTemplate castRabbitTemplate) {
71+
setConnectionFactory(castRabbitTemplate.getConnectionFactory());
72+
this.rabbitTemplate = castRabbitTemplate;
7373
}
7474
else {
7575
this.rabbitTemplate = null;
@@ -159,8 +159,8 @@ protected void endpointInit() {
159159

160160
@Override
161161
protected void doStop() {
162-
if (this.amqpTemplate instanceof Lifecycle) {
163-
((Lifecycle) this.amqpTemplate).stop();
162+
if (this.amqpTemplate instanceof Lifecycle lifecycle) {
163+
lifecycle.stop();
164164
}
165165
}
166166

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

Lines changed: 3 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.
@@ -180,11 +180,11 @@ protected void doInit() {
180180

181181
this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory());
182182
TypeLocator typeLocator = this.evaluationContext.getTypeLocator();
183-
if (typeLocator instanceof StandardTypeLocator) {
183+
if (typeLocator instanceof StandardTypeLocator standardTypeLocator) {
184184
/*
185185
* Register the Cassandra Query DSL package, so they don't need a FQCN for QueryBuilder, for example.
186186
*/
187-
((StandardTypeLocator) typeLocator).registerImport(QueryBuilder.class.getPackage().getName());
187+
standardTypeLocator.registerImport(QueryBuilder.class.getPackage().getName());
188188
}
189189
}
190190

spring-integration-core/src/main/java/org/springframework/integration/aggregator/AbstractCorrelatingMessageHandler.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -387,14 +387,14 @@ protected void onInit() {
387387
"'discardChannelName' and 'discardChannel' are mutually exclusive.");
388388
BeanFactory beanFactory = getBeanFactory();
389389
if (beanFactory != null) {
390-
if (this.outputProcessor instanceof BeanFactoryAware) {
391-
((BeanFactoryAware) this.outputProcessor).setBeanFactory(beanFactory);
390+
if (this.outputProcessor instanceof BeanFactoryAware beanFactoryAware) {
391+
beanFactoryAware.setBeanFactory(beanFactory);
392392
}
393-
if (this.correlationStrategy instanceof BeanFactoryAware) {
394-
((BeanFactoryAware) this.correlationStrategy).setBeanFactory(beanFactory);
393+
if (this.correlationStrategy instanceof BeanFactoryAware beanFactoryAware) {
394+
beanFactoryAware.setBeanFactory(beanFactory);
395395
}
396-
if (this.releaseStrategy instanceof BeanFactoryAware) {
397-
((BeanFactoryAware) this.releaseStrategy).setBeanFactory(beanFactory);
396+
if (this.releaseStrategy instanceof BeanFactoryAware beanFactoryAware) {
397+
beanFactoryAware.setBeanFactory(beanFactory);
398398
}
399399
}
400400

@@ -422,8 +422,8 @@ protected void onInit() {
422422
this.lockRegistrySet = true;
423423
this.forceReleaseProcessor = createGroupTimeoutProcessor();
424424

425-
if (this.releaseStrategy instanceof GroupConditionProvider) {
426-
this.groupConditionSupplier = ((GroupConditionProvider) this.releaseStrategy).getGroupConditionSupplier();
425+
if (this.releaseStrategy instanceof GroupConditionProvider groupConditionProvider) {
426+
this.groupConditionSupplier = groupConditionProvider.getGroupConditionSupplier();
427427
}
428428
}
429429

@@ -671,8 +671,8 @@ private void scheduleGroupToForceComplete(MessageGroup messageGroup) {
671671
*/
672672
if (groupTimeout != null) {
673673
Date startTime = null;
674-
if (groupTimeout instanceof Date) {
675-
startTime = (Date) groupTimeout;
674+
if (groupTimeout instanceof Date date) {
675+
startTime = date;
676676
}
677677
else if ((Long) groupTimeout > 0) {
678678
startTime = new Date(System.currentTimeMillis() + (Long) groupTimeout);
@@ -976,11 +976,11 @@ public void destroy() {
976976
public void start() {
977977
if (!this.running) {
978978
this.running = true;
979-
if (this.outputProcessor instanceof Lifecycle) {
980-
((Lifecycle) this.outputProcessor).start();
979+
if (this.outputProcessor instanceof Lifecycle lifecycle) {
980+
lifecycle.start();
981981
}
982-
if (this.releaseStrategy instanceof Lifecycle) {
983-
((Lifecycle) this.releaseStrategy).start();
982+
if (this.releaseStrategy instanceof Lifecycle lifecycle) {
983+
lifecycle.start();
984984
}
985985
if (this.expireTimeout > 0) {
986986
purgeOrphanedGroups();
@@ -996,11 +996,11 @@ public void start() {
996996
public void stop() {
997997
if (this.running) {
998998
this.running = false;
999-
if (this.outputProcessor instanceof Lifecycle) {
1000-
((Lifecycle) this.outputProcessor).stop();
999+
if (this.outputProcessor instanceof Lifecycle lifecycle) {
1000+
lifecycle.stop();
10011001
}
1002-
if (this.releaseStrategy instanceof Lifecycle) {
1003-
((Lifecycle) this.releaseStrategy).stop();
1002+
if (this.releaseStrategy instanceof Lifecycle lifecycle) {
1003+
lifecycle.stop();
10041004
}
10051005
}
10061006
}
@@ -1033,8 +1033,8 @@ public SequenceAwareMessageGroup(MessageGroup messageGroup) {
10331033
*/
10341034
super(messageGroup.getMessages(), null, messageGroup.getGroupId(), messageGroup.getTimestamp(),
10351035
messageGroup.isComplete(), true);
1036-
if (messageGroup instanceof SimpleMessageGroup) {
1037-
this.sourceGroup = (SimpleMessageGroup) messageGroup;
1036+
if (messageGroup instanceof SimpleMessageGroup simpleMessageGroup) {
1037+
this.sourceGroup = simpleMessageGroup;
10381038
}
10391039
else {
10401040
this.sourceGroup = null;

spring-integration-core/src/main/java/org/springframework/integration/aggregator/AggregatingMessageHandler.java

Lines changed: 3 additions & 3 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.
@@ -103,8 +103,8 @@ protected void afterRelease(MessageGroup messageGroup, Collection<Message<?>> co
103103
remove(messageGroup);
104104
}
105105
else {
106-
if (messageStore instanceof SimpleMessageStore) {
107-
((SimpleMessageStore) messageStore).clearMessageGroup(groupId);
106+
if (messageStore instanceof SimpleMessageStore simpleMessageStore) {
107+
simpleMessageStore.clearMessageGroup(groupId);
108108
}
109109
else {
110110
messageStore.removeMessagesFromGroup(groupId, messageGroup.getMessages());

0 commit comments

Comments
 (0)