diff --git a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/channel/AbstractAmqpChannel.java b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/channel/AbstractAmqpChannel.java index fd5de1914b..3949d87bb1 100644 --- a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/channel/AbstractAmqpChannel.java +++ b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/channel/AbstractAmqpChannel.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-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. @@ -45,6 +45,7 @@ import org.springframework.util.Assert; * @author Mark Fisher * @author Artem Bilan * @author Gary Russell + * @author Ngoc Nhan * * @since 2.1 */ @@ -94,8 +95,8 @@ public abstract class AbstractAmqpChannel extends AbstractMessageChannel impleme AbstractAmqpChannel(AmqpTemplate amqpTemplate, AmqpHeaderMapper outboundMapper, AmqpHeaderMapper inboundMapper) { Assert.notNull(amqpTemplate, "amqpTemplate must not be null"); this.amqpTemplate = amqpTemplate; - if (amqpTemplate instanceof RabbitTemplate) { - this.rabbitTemplate = (RabbitTemplate) amqpTemplate; + if (amqpTemplate instanceof RabbitTemplate castRabbitTemplate) { + this.rabbitTemplate = castRabbitTemplate; MessageConverter converter = this.rabbitTemplate.getMessageConverter(); if (converter instanceof AllowedListDeserializingMessageConverter allowedListMessageConverter) { allowedListMessageConverter.addAllowedListPatterns( diff --git a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/channel/PollableAmqpChannel.java b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/channel/PollableAmqpChannel.java index dc52a0724c..c236485ae2 100644 --- a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/channel/PollableAmqpChannel.java +++ b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/channel/PollableAmqpChannel.java @@ -47,6 +47,7 @@ import org.springframework.util.Assert; * @author Mark Fisher * @author Artem Bilan * @author Gary Russell + * @author Ngoc Nhan * * @since 2.1 */ @@ -167,7 +168,7 @@ public class PollableAmqpChannel extends AbstractAmqpChannel if (traceEnabled) { logger.trace("preReceive on channel '" + this + "'"); } - if (interceptorList.getInterceptors().size() > 0) { + if (!interceptorList.getInterceptors().isEmpty()) { interceptorStack = new ArrayDeque<>(); if (!interceptorList.preReceive(this, interceptorStack)) { return null; diff --git a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/config/AmqpChannelFactoryBean.java b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/config/AmqpChannelFactoryBean.java index af82aef69c..a2f097a934 100644 --- a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/config/AmqpChannelFactoryBean.java +++ b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/config/AmqpChannelFactoryBean.java @@ -64,6 +64,7 @@ import org.springframework.util.ErrorHandler; * @author Mark Fisher * @author Gary Russell * @author Artem Bilan + * @author Ngoc Nhan * * @since 2.1 */ @@ -197,8 +198,8 @@ public class AmqpChannelFactoryBean extends AbstractFactoryBean getFuture() { - if (this.userData instanceof CorrelationData) { - return ((CorrelationData) this.userData).getFuture(); + if (this.userData instanceof CorrelationData correlationData) { + return correlationData.getFuture(); } else { return super.getFuture(); @@ -738,8 +739,8 @@ public abstract class AbstractAmqpOutboundEndpoint extends AbstractReplyProducin @Override public void setReturned(ReturnedMessage returned) { - if (this.userData instanceof CorrelationData) { - ((CorrelationData) this.userData).setReturned(returned); + if (this.userData instanceof CorrelationData correlationData) { + correlationData.setReturned(returned); } super.setReturned(returned); } diff --git a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AmqpOutboundEndpoint.java b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AmqpOutboundEndpoint.java index b941c08b0e..a66f47ec5c 100644 --- a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AmqpOutboundEndpoint.java +++ b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AmqpOutboundEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-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. @@ -44,6 +44,7 @@ import org.springframework.util.Assert; * @author Oleg Zhurakousky * @author Gary Russell * @author Artem Bilan + * @author Ngoc Nhan * * @since 2.1 */ @@ -67,9 +68,9 @@ public class AmqpOutboundEndpoint extends AbstractAmqpOutboundEndpoint public AmqpOutboundEndpoint(AmqpTemplate amqpTemplate) { Assert.notNull(amqpTemplate, "amqpTemplate must not be null"); this.amqpTemplate = amqpTemplate; - if (amqpTemplate instanceof RabbitTemplate) { - setConnectionFactory(((RabbitTemplate) amqpTemplate).getConnectionFactory()); - this.rabbitTemplate = (RabbitTemplate) amqpTemplate; + if (amqpTemplate instanceof RabbitTemplate castRabbitTemplate) { + setConnectionFactory(castRabbitTemplate.getConnectionFactory()); + this.rabbitTemplate = castRabbitTemplate; } else { this.rabbitTemplate = null; @@ -159,8 +160,8 @@ public class AmqpOutboundEndpoint extends AbstractAmqpOutboundEndpoint @Override protected void doStop() { - if (this.amqpTemplate instanceof Lifecycle) { - ((Lifecycle) this.amqpTemplate).stop(); + if (this.amqpTemplate instanceof Lifecycle lifecycle) { + lifecycle.stop(); } } diff --git a/spring-integration-cassandra/src/main/java/org/springframework/integration/cassandra/outbound/CassandraMessageHandler.java b/spring-integration-cassandra/src/main/java/org/springframework/integration/cassandra/outbound/CassandraMessageHandler.java index 411aa880f7..c902806b35 100644 --- a/spring-integration-cassandra/src/main/java/org/springframework/integration/cassandra/outbound/CassandraMessageHandler.java +++ b/spring-integration-cassandra/src/main/java/org/springframework/integration/cassandra/outbound/CassandraMessageHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 the original author or authors. + * Copyright 2022-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. @@ -60,6 +60,7 @@ import org.springframework.util.Assert; * @author Soby Chacko * @author Artem Bilan * @author Filippo Balicchia + * @author Ngoc Nhan * * @since 6.0 */ @@ -180,11 +181,11 @@ public class CassandraMessageHandler extends AbstractReplyProducingMessageHandle this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory()); TypeLocator typeLocator = this.evaluationContext.getTypeLocator(); - if (typeLocator instanceof StandardTypeLocator) { + if (typeLocator instanceof StandardTypeLocator standardTypeLocator) { /* * Register the Cassandra Query DSL package, so they don't need a FQCN for QueryBuilder, for example. */ - ((StandardTypeLocator) typeLocator).registerImport(QueryBuilder.class.getPackage().getName()); + standardTypeLocator.registerImport(QueryBuilder.class.getPackage().getName()); } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/AbstractCorrelatingMessageHandler.java b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/AbstractCorrelatingMessageHandler.java index 911101139b..78c76a52e3 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/AbstractCorrelatingMessageHandler.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/AbstractCorrelatingMessageHandler.java @@ -102,6 +102,7 @@ import org.springframework.util.ObjectUtils; * @author Enrique Rodriguez * @author Meherzad Lahewala * @author Jayadev Sirimamilla + * @author Ngoc Nhan * * @since 2.0 */ @@ -387,14 +388,14 @@ public abstract class AbstractCorrelatingMessageHandler extends AbstractMessageP "'discardChannelName' and 'discardChannel' are mutually exclusive."); BeanFactory beanFactory = getBeanFactory(); if (beanFactory != null) { - if (this.outputProcessor instanceof BeanFactoryAware) { - ((BeanFactoryAware) this.outputProcessor).setBeanFactory(beanFactory); + if (this.outputProcessor instanceof BeanFactoryAware beanFactoryAware) { + beanFactoryAware.setBeanFactory(beanFactory); } - if (this.correlationStrategy instanceof BeanFactoryAware) { - ((BeanFactoryAware) this.correlationStrategy).setBeanFactory(beanFactory); + if (this.correlationStrategy instanceof BeanFactoryAware beanFactoryAware) { + beanFactoryAware.setBeanFactory(beanFactory); } - if (this.releaseStrategy instanceof BeanFactoryAware) { - ((BeanFactoryAware) this.releaseStrategy).setBeanFactory(beanFactory); + if (this.releaseStrategy instanceof BeanFactoryAware beanFactoryAware) { + beanFactoryAware.setBeanFactory(beanFactory); } } @@ -422,8 +423,8 @@ public abstract class AbstractCorrelatingMessageHandler extends AbstractMessageP this.lockRegistrySet = true; this.forceReleaseProcessor = createGroupTimeoutProcessor(); - if (this.releaseStrategy instanceof GroupConditionProvider) { - this.groupConditionSupplier = ((GroupConditionProvider) this.releaseStrategy).getGroupConditionSupplier(); + if (this.releaseStrategy instanceof GroupConditionProvider groupConditionProvider) { + this.groupConditionSupplier = groupConditionProvider.getGroupConditionSupplier(); } } @@ -671,8 +672,8 @@ public abstract class AbstractCorrelatingMessageHandler extends AbstractMessageP */ if (groupTimeout != null) { Date startTime = null; - if (groupTimeout instanceof Date) { - startTime = (Date) groupTimeout; + if (groupTimeout instanceof Date date) { + startTime = date; } else if ((Long) groupTimeout > 0) { startTime = new Date(System.currentTimeMillis() + (Long) groupTimeout); @@ -976,11 +977,11 @@ public abstract class AbstractCorrelatingMessageHandler extends AbstractMessageP public void start() { if (!this.running) { this.running = true; - if (this.outputProcessor instanceof Lifecycle) { - ((Lifecycle) this.outputProcessor).start(); + if (this.outputProcessor instanceof Lifecycle lifecycle) { + lifecycle.start(); } - if (this.releaseStrategy instanceof Lifecycle) { - ((Lifecycle) this.releaseStrategy).start(); + if (this.releaseStrategy instanceof Lifecycle lifecycle) { + lifecycle.start(); } if (this.expireTimeout > 0) { purgeOrphanedGroups(); @@ -996,11 +997,11 @@ public abstract class AbstractCorrelatingMessageHandler extends AbstractMessageP public void stop() { if (this.running) { this.running = false; - if (this.outputProcessor instanceof Lifecycle) { - ((Lifecycle) this.outputProcessor).stop(); + if (this.outputProcessor instanceof Lifecycle lifecycle) { + lifecycle.stop(); } - if (this.releaseStrategy instanceof Lifecycle) { - ((Lifecycle) this.releaseStrategy).stop(); + if (this.releaseStrategy instanceof Lifecycle lifecycle) { + lifecycle.stop(); } } } @@ -1033,8 +1034,8 @@ public abstract class AbstractCorrelatingMessageHandler extends AbstractMessageP */ super(messageGroup.getMessages(), null, messageGroup.getGroupId(), messageGroup.getTimestamp(), messageGroup.isComplete(), true); - if (messageGroup instanceof SimpleMessageGroup) { - this.sourceGroup = (SimpleMessageGroup) messageGroup; + if (messageGroup instanceof SimpleMessageGroup simpleMessageGroup) { + this.sourceGroup = simpleMessageGroup; } else { this.sourceGroup = null; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/AggregatingMessageHandler.java b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/AggregatingMessageHandler.java index b325fa3c14..fdeeb7eb81 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/AggregatingMessageHandler.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/AggregatingMessageHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-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. @@ -32,6 +32,7 @@ import org.springframework.messaging.Message; * @author Oleg Zhurakousky * @author Artem Bilan * @author Gary Russell + * @author Ngoc Nhan * * @since 2.1 */ @@ -103,8 +104,8 @@ public class AggregatingMessageHandler extends AbstractCorrelatingMessageHandler remove(messageGroup); } else { - if (messageStore instanceof SimpleMessageStore) { - ((SimpleMessageStore) messageStore).clearMessageGroup(groupId); + if (messageStore instanceof SimpleMessageStore simpleMessageStore) { + simpleMessageStore.clearMessageGroup(groupId); } else { messageStore.removeMessagesFromGroup(groupId, messageGroup.getMessages()); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/ResequencingMessageGroupProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/ResequencingMessageGroupProcessor.java index a926d9319c..154351860f 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/ResequencingMessageGroupProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/ResequencingMessageGroupProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-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. @@ -32,6 +32,7 @@ import org.springframework.messaging.Message; * @author Dave Syer * @author Oleg Zhurakousky * @author Artem Bilan + * @author Ngoc Nhan * * @since 2.0 */ @@ -42,7 +43,7 @@ public class ResequencingMessageGroupProcessor implements MessageGroupProcessor public Object processMessageGroup(MessageGroup group) { Collection> messages = group.getMessages(); - if (messages.size() > 0) { + if (!messages.isEmpty()) { List> sorted = new ArrayList<>(messages); sorted.sort(this.comparator); ArrayList> partialSequence = new ArrayList<>(); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractExecutorChannel.java b/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractExecutorChannel.java index e79542f4e6..47b666cee7 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractExecutorChannel.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/channel/AbstractExecutorChannel.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2021 the original author or authors. + * Copyright 2015-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. @@ -47,6 +47,7 @@ import org.springframework.util.CollectionUtils; * * @author Artem Bilan * @author Gary Russell + * @author Ngoc Nhan * * @since 4.2 * @@ -185,8 +186,7 @@ public abstract class AbstractExecutorChannel extends AbstractSubscribableChanne private Message applyBeforeHandle(Message message, Deque interceptorStack) { Message theMessage = message; for (ChannelInterceptor interceptor : AbstractExecutorChannel.this.interceptors.interceptors) { - if (interceptor instanceof ExecutorChannelInterceptor) { - ExecutorChannelInterceptor executorInterceptor = (ExecutorChannelInterceptor) interceptor; + if (interceptor instanceof ExecutorChannelInterceptor executorInterceptor) { theMessage = executorInterceptor.beforeHandle(theMessage, AbstractExecutorChannel.this, this.delegate.getMessageHandler()); if (theMessage == null) { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/codec/kryo/AbstractKryoCodec.java b/spring-integration-core/src/main/java/org/springframework/integration/codec/kryo/AbstractKryoCodec.java index b5138d1c3f..9263c8cb8e 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/codec/kryo/AbstractKryoCodec.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/codec/kryo/AbstractKryoCodec.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-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. @@ -35,6 +35,7 @@ import org.springframework.util.Assert; * * @author David Turanski * @author Artem Bilan + * @author Ngoc Nhan * * @since 4.2 */ @@ -63,7 +64,7 @@ public abstract class AbstractKryoCodec implements Codec { Assert.notNull(outputStream, "'outputSteam' cannot be null"); Kryo kryo = this.pool.obtain(); - try (Output output = (outputStream instanceof Output ? (Output) outputStream : new Output(outputStream))) { + try (Output output = (outputStream instanceof Output castOutput ? castOutput : new Output(outputStream))) { doEncode(kryo, object, output); } finally { @@ -86,7 +87,7 @@ public abstract class AbstractKryoCodec implements Codec { Assert.notNull(type, "'type' cannot be null"); Kryo kryo = this.pool.obtain(); - try (Input input = (inputStream instanceof Input ? (Input) inputStream : new Input(inputStream))) { + try (Input input = (inputStream instanceof Input castInput ? castInput : new Input(inputStream))) { return doDecode(kryo, input, type); } finally { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/AbstractMethodAnnotationPostProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/config/AbstractMethodAnnotationPostProcessor.java index 2e1211815e..e13cdd04a6 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/AbstractMethodAnnotationPostProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/AbstractMethodAnnotationPostProcessor.java @@ -118,6 +118,7 @@ import org.springframework.util.StringUtils; * @author Artem Bilan * @author Gary Russell * @author Chris Bono + * @author Ngoc Nhan */ public abstract class AbstractMethodAnnotationPostProcessor implements MethodAnnotationPostProcessor, BeanFactoryAware { @@ -447,8 +448,8 @@ public abstract class AbstractMethodAnnotationPostProcessor adviceChain = extractAdviceChain(beanName, annotations); - if (!CollectionUtils.isEmpty(adviceChain) && handler instanceof AbstractReplyProducingMessageHandler) { - ((AbstractReplyProducingMessageHandler) handler).setAdviceChain(adviceChain); + if (!CollectionUtils.isEmpty(adviceChain) && handler instanceof AbstractReplyProducingMessageHandler abstractReplyProducingMessageHandler) { + abstractReplyProducingMessageHandler.setAdviceChain(adviceChain); } if (!CollectionUtils.isEmpty(adviceChain)) { @@ -516,8 +517,8 @@ public abstract class AbstractMethodAnnotationPostProcessor(); for (String adviceChainName : adviceChainNames) { Object adviceChainBean = this.beanFactory.getBean(adviceChainName); - if (adviceChainBean instanceof Advice) { - adviceChain.add((Advice) adviceChainBean); + if (adviceChainBean instanceof Advice advice) { + adviceChain.add(advice); } - else if (adviceChainBean instanceof Advice[]) { - Collections.addAll(adviceChain, (Advice[]) adviceChainBean); + else if (adviceChainBean instanceof Advice[] advices) { + Collections.addAll(adviceChain, advices); } else if (adviceChainBean instanceof Collection) { @SuppressWarnings(UNCHECKED) @@ -604,11 +605,11 @@ public abstract class AbstractMethodAnnotationPostProcessor "A '@Poller' should not be specified for Annotation-based " + "endpoint, since '" + inputChannel + "' is a SubscribableChannel (not pollable)."); - return new EventDrivenConsumer((SubscribableChannel) inputChannel, handler); + return new EventDrivenConsumer(subscribableChannel, handler); } else if (inputChannel instanceof PollableChannel) { return pollingConsumer(inputChannel, handler, poller); @@ -624,9 +625,9 @@ public abstract class AbstractMethodAnnotationPostProcessor implements FactoryBean, ApplicationContextAware, BeanFactoryAware, BeanNameAware, @@ -251,13 +252,13 @@ public abstract class AbstractSimpleMessageHandlerFactoryBean implements DisposableBean { @@ -207,8 +208,8 @@ public abstract class AbstractStandardMessageHandlerFactoryBean } if (this.requiresReply != null) { - if (handler instanceof AbstractReplyProducingMessageHandler) { - ((AbstractReplyProducingMessageHandler) handler).setRequiresReply(this.requiresReply); + if (handler instanceof AbstractReplyProducingMessageHandler abstractReplyProducingMessageHandler) { + abstractReplyProducingMessageHandler.setRequiresReply(this.requiresReply); } else { if (this.requiresReply && logger.isDebugEnabled()) { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/AggregatorFactoryBean.java b/spring-integration-core/src/main/java/org/springframework/integration/config/AggregatorFactoryBean.java index 94cd4fb9f0..f1f2cb7e13 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/AggregatorFactoryBean.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/AggregatorFactoryBean.java @@ -49,6 +49,7 @@ import org.springframework.util.StringUtils; * * @author Gary Russell * @author Artem Bilan + * @author Ngoc Nhan * * @since 4.2 * @@ -197,8 +198,8 @@ public class AggregatorFactoryBean extends AbstractSimpleMessageHandlerFactoryBe @Override protected AggregatingMessageHandler createHandler() { MessageGroupProcessor outputProcessor; - if (this.processorBean instanceof MessageGroupProcessor) { - outputProcessor = (MessageGroupProcessor) this.processorBean; + if (this.processorBean instanceof MessageGroupProcessor messageGroupProcessor) { + outputProcessor = messageGroupProcessor; } else { if (!StringUtils.hasText(this.methodName)) { @@ -210,8 +211,8 @@ public class AggregatorFactoryBean extends AbstractSimpleMessageHandlerFactoryBe } if (this.headersFunction != null) { - if (outputProcessor instanceof AbstractAggregatingMessageGroupProcessor) { - ((AbstractAggregatingMessageGroupProcessor) outputProcessor).setHeadersFunction(this.headersFunction); + if (outputProcessor instanceof AbstractAggregatingMessageGroupProcessor abstractAggregatingMessageGroupProcessor) { + abstractAggregatingMessageGroupProcessor.setHeadersFunction(this.headersFunction); } else { outputProcessor = new DelegatingMessageGroupProcessor(outputProcessor, this.headersFunction); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/FixedSubscriberChannelBeanFactoryPostProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/config/FixedSubscriberChannelBeanFactoryPostProcessor.java index 30c6e63590..3b24b2e425 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/FixedSubscriberChannelBeanFactoryPostProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/FixedSubscriberChannelBeanFactoryPostProcessor.java @@ -32,6 +32,7 @@ import org.springframework.util.Assert; * Used to post process candidates for {@link FixedSubscriberChannel} * {@link org.springframework.messaging.MessageHandler}s. * @author Gary Russell + * @author Ngoc Nhan * @since 4.0 * */ @@ -47,7 +48,7 @@ public final class FixedSubscriberChannelBeanFactoryPostProcessor implements Bea public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { if (beanFactory instanceof BeanDefinitionRegistry) { BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory; - if (this.candidateFixedChannelHandlerMap.size() > 0) { + if (!this.candidateFixedChannelHandlerMap.isEmpty()) { for (Entry entry : this.candidateFixedChannelHandlerMap.entrySet()) { String handlerName = entry.getKey(); String channelName = entry.getValue(); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/TransformerFactoryBean.java b/spring-integration-core/src/main/java/org/springframework/integration/config/TransformerFactoryBean.java index a25e6f36c2..5bf942003b 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/TransformerFactoryBean.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/TransformerFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-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. @@ -33,6 +33,7 @@ import org.springframework.util.StringUtils; * @author Gary Russell * @author David Liu * @author Artem Bilan + * @author Ngoc Nhan */ public class TransformerFactoryBean extends AbstractStandardMessageHandlerFactoryBean { @@ -44,8 +45,8 @@ public class TransformerFactoryBean extends AbstractStandardMessageHandlerFactor protected MessageHandler createMethodInvokingHandler(Object targetObject, String targetMethodName) { Assert.notNull(targetObject, "targetObject must not be null"); Transformer transformer = null; - if (targetObject instanceof Transformer) { - transformer = (Transformer) targetObject; + if (targetObject instanceof Transformer castTransformer) { + transformer = castTransformer; } else { this.checkForIllegalTarget(targetObject, targetMethodName); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractOutboundChannelAdapterParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractOutboundChannelAdapterParser.java index 7fb1f1a5b2..89f55961a9 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractOutboundChannelAdapterParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractOutboundChannelAdapterParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-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. @@ -42,6 +42,7 @@ import org.springframework.util.xml.DomUtils; * @author Mark Fisher * @author Gary Russell * @author Artem Bilan + * @author Ngoc Nhan */ public abstract class AbstractOutboundChannelAdapterParser extends AbstractChannelAdapterParser { @@ -99,8 +100,7 @@ public abstract class AbstractOutboundChannelAdapterParser extends AbstractChann boolean isReplyProducer = this.isUsingReplyProducer(); if (!isReplyProducer) { Class beanClass = null; - if (handlerBeanDefinition instanceof AbstractBeanDefinition) { - AbstractBeanDefinition abstractBeanDefinition = (AbstractBeanDefinition) handlerBeanDefinition; + if (handlerBeanDefinition instanceof AbstractBeanDefinition abstractBeanDefinition) { if (abstractBeanDefinition.hasBeanClass()) { beanClass = abstractBeanDefinition.getBeanClass(); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractPollingInboundChannelAdapterParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractPollingInboundChannelAdapterParser.java index 7296be5397..40eacac928 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractPollingInboundChannelAdapterParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractPollingInboundChannelAdapterParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-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. @@ -34,6 +34,7 @@ import org.springframework.util.xml.DomUtils; * @author Gary Russell * @author Oleg Zhurakousky * @author Artem Bilan + * @author Ngoc Nhan */ public abstract class AbstractPollingInboundChannelAdapterParser extends AbstractChannelAdapterParser { @@ -48,13 +49,13 @@ public abstract class AbstractPollingInboundChannelAdapterParser extends Abstrac String sourceBeanName = null; - if (source instanceof BeanDefinition) { + if (source instanceof BeanDefinition beanDefinition) { String channelAdapterId = this.resolveId(element, adapterBuilder.getRawBeanDefinition(), parserContext); sourceBeanName = channelAdapterId + ".source"; - parserContext.getRegistry().registerBeanDefinition(sourceBeanName, (BeanDefinition) source); + parserContext.getRegistry().registerBeanDefinition(sourceBeanName, beanDefinition); } - else if (source instanceof RuntimeBeanReference) { - sourceBeanName = ((RuntimeBeanReference) source).getBeanName(); + else if (source instanceof RuntimeBeanReference runtimeBeanReference) { + sourceBeanName = runtimeBeanReference.getBeanName(); } else { parserContext.getReaderContext().error("Wrong 'source' type: must be 'BeanDefinition' or 'RuntimeBeanReference'", source); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractRouterParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractRouterParser.java index 7554d343c9..4f012d0cb7 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractRouterParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractRouterParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-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. @@ -34,6 +34,7 @@ import org.springframework.util.xml.DomUtils; * * @author Mark Fisher * @author Gary Russell + * @author Ngoc Nhan */ public abstract class AbstractRouterParser extends AbstractConsumerEndpointParser { @@ -61,7 +62,7 @@ public abstract class AbstractRouterParser extends AbstractConsumerEndpointParse // check if mapping is provided otherwise returned values will be treated as channel names List mappingElements = DomUtils.getChildElementsByTagName(element, "mapping"); if (!CollectionUtils.isEmpty(mappingElements)) { - ManagedMap channelMappings = new ManagedMap(); + ManagedMap channelMappings = new ManagedMap<>(); for (Element mappingElement : mappingElements) { String key = mappingElement.getAttribute(this.getMappingKeyAttributeName()); channelMappings.put(key, mappingElement.getAttribute("channel")); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ChainParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ChainParser.java index 2a38669727..04e0fb1ff9 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ChainParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ChainParser.java @@ -51,6 +51,7 @@ import org.springframework.util.xml.DomUtils; * @author Artem Bilan * @author Gunnar Hillert * @author Gary Russell + * @author Ngoc Nhan */ public class ChainParser extends AbstractConsumerEndpointParser { @@ -73,8 +74,8 @@ public class ChainParser extends AbstractConsumerEndpointParser { } String chainHandlerId = this.resolveId(element, builder.getRawBeanDefinition(), parserContext); - List handlerList = new ManagedList(); - Set handlerBeanNameSet = new HashSet(); + List handlerList = new ManagedList<>(); + Set handlerBeanNameSet = new HashSet<>(); NodeList children = element.getChildNodes(); int childOrder = 0; @@ -83,8 +84,8 @@ public class ChainParser extends AbstractConsumerEndpointParser { if (child.getNodeType() == Node.ELEMENT_NODE && !"poller".equals(child.getLocalName())) { BeanMetadataElement childBeanMetadata = this.parseChild(chainHandlerId, (Element) child, childOrder++, parserContext, builder.getBeanDefinition()); - if (childBeanMetadata instanceof RuntimeBeanReference) { - String handlerBeanName = ((RuntimeBeanReference) childBeanMetadata).getBeanName(); + if (childBeanMetadata instanceof RuntimeBeanReference runtimeBeanReference) { + String handlerBeanName = runtimeBeanReference.getBeanName(); if (!handlerBeanNameSet.add(handlerBeanName)) { parserContext.getReaderContext().error("A bean definition is already registered for " + "beanName: '" + handlerBeanName + "' within the current .", diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ChannelInterceptorParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ChannelInterceptorParser.java index 0ff93aeb17..5b36333599 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ChannelInterceptorParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ChannelInterceptorParser.java @@ -37,13 +37,14 @@ import org.springframework.beans.factory.xml.ParserContext; * @author Mark Fisher * @author Oleg Zhurakousky * @author Gary Russell + * @author Ngoc Nhan */ public class ChannelInterceptorParser { private final Map parsers; public ChannelInterceptorParser() { - this.parsers = new HashMap(); + this.parsers = new HashMap<>(); this.parsers.put("wire-tap", new WireTapParser()); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/EnricherParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/EnricherParser.java index 61b3ec303c..af55e7c7b2 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/EnricherParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/EnricherParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-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. @@ -43,6 +43,7 @@ import org.springframework.util.xml.DomUtils; * @author Liujiong * @author Kris Jacyna * @author Gary Russell + * @author Ngoc Nhan * @since 2.1 */ public class EnricherParser extends AbstractConsumerEndpointParser { @@ -107,10 +108,10 @@ public class EnricherParser extends AbstractConsumerEndpointParser { nullResultExpression, hasAttributeValue, hasAttributeExpression, hasAttributeNullResultExpression); } - if (expressions.size() > 0) { + if (!expressions.isEmpty()) { builder.addPropertyValue("propertyExpressions", expressions); } - if (nullResultExpressions.size() > 0) { + if (!nullResultExpressions.isEmpty()) { builder.addPropertyValue("nullResultPropertyExpressions", nullResultExpressions); } } @@ -183,10 +184,10 @@ public class EnricherParser extends AbstractConsumerEndpointParser { headerExpression(parserContext, expressions, nullResultHeaderExpressions, subElement, name, valueElementValue, hasAttributeValue, hasAttributeExpression, hasAttributeNullResultExpression); } - if (expressions.size() > 0) { + if (!expressions.isEmpty()) { builder.addPropertyValue("headerExpressions", expressions); } - if (nullResultHeaderExpressions.size() > 0) { + if (!nullResultHeaderExpressions.isEmpty()) { builder.addPropertyValue("nullResultHeaderExpressions", nullResultHeaderExpressions); } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/PublishingInterceptorParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/PublishingInterceptorParser.java index 01a2796bd3..c771370fff 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/PublishingInterceptorParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/PublishingInterceptorParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-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. @@ -42,6 +42,7 @@ import org.springframework.util.xml.DomUtils; * @author Mark Fisher * @author Gary Russell * @author Artem Bilan + * @author Ngoc Nhan * @since 2.0 */ public class PublishingInterceptorParser extends AbstractBeanDefinitionParser { @@ -89,7 +90,7 @@ public class PublishingInterceptorParser extends AbstractBeanDefinitionParser { // set headersMap Map headerExpressions = headerExpressions(parserContext, mapping); - if (headerExpressions.size() > 0) { + if (!headerExpressions.isEmpty()) { headersExpressionMap.put(methodPattern, headerExpressions); } @@ -100,14 +101,14 @@ public class PublishingInterceptorParser extends AbstractBeanDefinitionParser { resolvableChannelMap.put(channel, new RuntimeBeanReference(channel)); } } - if (payloadExpressionMap.size() == 0) { + if (payloadExpressionMap.isEmpty()) { payloadExpressionMap.put("*", "#return"); } interceptorMappings.put(PAYLOAD, payloadExpressionMap); - if (headersExpressionMap.size() > 0) { + if (!headersExpressionMap.isEmpty()) { interceptorMappings.put("headers", headersExpressionMap); } - if (channelMap.size() > 0) { + if (!channelMap.isEmpty()) { interceptorMappings.put("channels", channelMap); interceptorMappings.put("resolvableChannels", resolvableChannelMap); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/RecipientListRouterParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/RecipientListRouterParser.java index f0fa484d6f..d2b9e8e4c0 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/RecipientListRouterParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/RecipientListRouterParser.java @@ -36,6 +36,7 @@ import org.springframework.util.xml.DomUtils; * * @author Oleg Zhurakousky * @author Mark Fisher + * @author Ngoc Nhan * @since 1.0.3 */ public class RecipientListRouterParser extends AbstractRouterParser { @@ -58,7 +59,7 @@ public class RecipientListRouterParser extends AbstractRouterParser { } recipientList.add(recipientBuilder.getBeanDefinition()); } - if (recipientList.size() > 0) { + if (!recipientList.isEmpty()) { recipientListRouterBuilder.addPropertyValue("recipients", recipientList); } return recipientListRouterBuilder.getBeanDefinition(); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/core/AsyncMessagingTemplate.java b/spring-integration-core/src/main/java/org/springframework/integration/core/AsyncMessagingTemplate.java index 8c17c2aba6..2977809c67 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/core/AsyncMessagingTemplate.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/core/AsyncMessagingTemplate.java @@ -31,6 +31,7 @@ import org.springframework.util.Assert; /** * @author Mark Fisher * @author Gary Russell + * @author Ngoc Nhan * @since 2.0 */ public class AsyncMessagingTemplate extends MessagingTemplate implements AsyncMessagingOperations { @@ -41,8 +42,8 @@ public class AsyncMessagingTemplate extends MessagingTemplate implements AsyncMe public void setExecutor(Executor executor) { Assert.notNull(executor, "executor must not be null"); - this.executor = (executor instanceof AsyncTaskExecutor) ? - (AsyncTaskExecutor) executor : new TaskExecutorAdapter(executor); + this.executor = (executor instanceof AsyncTaskExecutor asyncTaskExecutor) ? + asyncTaskExecutor : new TaskExecutorAdapter(executor); } @Override diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dsl/AggregatorSpec.java b/spring-integration-core/src/main/java/org/springframework/integration/dsl/AggregatorSpec.java index 390ac8fd6e..8ac109d36e 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dsl/AggregatorSpec.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dsl/AggregatorSpec.java @@ -33,6 +33,7 @@ import org.springframework.lang.Nullable; * A {@link CorrelationHandlerSpec} for an {@link AggregatingMessageHandler}. * * @author Artem Bilan + * @author Ngoc Nhan * * @since 5.0 */ @@ -71,8 +72,8 @@ public class AggregatorSpec extends CorrelationHandlerSpec getComponentsToRegister() { if (this.headersFunction != null) { MessageGroupProcessor outputProcessor = this.handler.getOutputProcessor(); - if (outputProcessor instanceof AbstractAggregatingMessageGroupProcessor) { - ((AbstractAggregatingMessageGroupProcessor) outputProcessor).setHeadersFunction(this.headersFunction); + if (outputProcessor instanceof AbstractAggregatingMessageGroupProcessor abstractAggregatingMessageGroupProcessor) { + abstractAggregatingMessageGroupProcessor.setHeadersFunction(this.headersFunction); } else { this.handler.setOutputProcessor( diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dsl/BaseIntegrationFlowDefinition.java b/spring-integration-core/src/main/java/org/springframework/integration/dsl/BaseIntegrationFlowDefinition.java index cf377de2b4..449bdb6dd1 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dsl/BaseIntegrationFlowDefinition.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dsl/BaseIntegrationFlowDefinition.java @@ -111,6 +111,7 @@ import org.springframework.util.StringUtils; * @author Gary Russell * @author Gabriele Del Prete * @author Tim Feuerbach + * @author Ngoc Nhan * * @since 5.2.1 * @@ -728,7 +729,7 @@ public abstract class BaseIntegrationFlowDefinition> endpointConfigurer) { Assert.notNull(genericTransformer, "'genericTransformer' must not be null"); - Transformer transformer = genericTransformer instanceof Transformer ? (Transformer) genericTransformer : + Transformer transformer = genericTransformer instanceof Transformer castTransformer ? castTransformer : (ClassUtils.isLambda(genericTransformer.getClass()) ? new MethodInvokingTransformer(new LambdaMessageProcessor(genericTransformer, expectedType)) : new MethodInvokingTransformer(genericTransformer, ClassUtils.TRANSFORMER_TRANSFORM_METHOD)); @@ -900,7 +901,7 @@ public abstract class BaseIntegrationFlowDefinition endpointConfigurer) { Assert.notNull(genericSelector, "'genericSelector' must not be null"); - MessageSelector selector = genericSelector instanceof MessageSelector ? (MessageSelector) genericSelector : + MessageSelector selector = genericSelector instanceof MessageSelector messageSelector ? messageSelector : (ClassUtils.isLambda(genericSelector.getClass()) ? new MethodInvokingSelector(new LambdaMessageProcessor(genericSelector, expectedType)) : new MethodInvokingSelector(genericSelector, ClassUtils.SELECTOR_ACCEPT_METHOD)); @@ -1136,8 +1137,8 @@ public abstract class BaseIntegrationFlowDefinition> endpointConfigurer) { Assert.notNull(messageHandlerSpec, "'messageHandlerSpec' must not be null"); - if (messageHandlerSpec instanceof ComponentsRegistration) { - addComponents(((ComponentsRegistration) messageHandlerSpec).getComponentsToRegister()); + if (messageHandlerSpec instanceof ComponentsRegistration componentsRegistration) { + addComponents(componentsRegistration.getComponentsToRegister()); } return handle(messageHandlerSpec.getObject(), endpointConfigurer); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dsl/TransformerEndpointSpec.java b/spring-integration-core/src/main/java/org/springframework/integration/dsl/TransformerEndpointSpec.java index 8ccb8fc1d5..46076bce26 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dsl/TransformerEndpointSpec.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dsl/TransformerEndpointSpec.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2023 the original author or authors. + * Copyright 2023-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. @@ -38,6 +38,7 @@ import org.springframework.util.Assert; * {@link #processor(MessageProcessorSpec)} or {@link #transformer(GenericTransformer)} must be provided. * * @author Artem Bilan + * @author Ngoc Nhan * * @since 6.2 */ @@ -218,7 +219,7 @@ public class TransformerEndpointSpec extends ConsumerEndpointSpec) { - this.messagingTemplate.send((MessageChannel) replyChannel, (Message) output); + this.messagingTemplate.send(messageChannel, (Message) output); } else { - this.messagingTemplate.convertAndSend((MessageChannel) replyChannel, output); + this.messagingTemplate.convertAndSend(messageChannel, output); } } - else if (replyChannel instanceof String) { + else if (replyChannel instanceof String string) { if (output instanceof Message) { - this.messagingTemplate.send((String) replyChannel, (Message) output); + this.messagingTemplate.send(string, (Message) output); } else { - this.messagingTemplate.convertAndSend((String) replyChannel, output); + this.messagingTemplate.convertAndSend(string, output); } } else { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractReplyProducingMessageHandler.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractReplyProducingMessageHandler.java index 0bf1c9f91c..b56c9a37e2 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractReplyProducingMessageHandler.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractReplyProducingMessageHandler.java @@ -44,6 +44,7 @@ import org.springframework.util.ClassUtils; * @author David Liu * @author Trung Pham * @author Christian Tzolov + * @author Ngoc Nhan */ public abstract class AbstractReplyProducingMessageHandler extends AbstractMessageProducingHandler implements BeanClassLoaderAware { @@ -91,7 +92,7 @@ public abstract class AbstractReplyProducingMessageHandler extends AbstractMessa } protected boolean hasAdviceChain() { - return this.adviceChain.size() > 0; + return !this.adviceChain.isEmpty(); } @Override diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/ExpressionCommandMessageProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/ExpressionCommandMessageProcessor.java index 7c0b238f9e..bde8b770a0 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/ExpressionCommandMessageProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/ExpressionCommandMessageProcessor.java @@ -46,6 +46,7 @@ import org.springframework.util.CollectionUtils; * @author Mark Fisher * @author Gary Russell * @author Artem Bilan + * @author Ngoc Nhan * * @since 2.0 * @@ -136,8 +137,8 @@ public class ExpressionCommandMessageProcessor extends AbstractMessageProcessor< } } List supportedMethods = this.methodFilter.filter(candidates); - if (supportedMethods.size() == 0) { - String methodDescription = (candidates.size() > 0) ? candidates.get(0).toString() : name; + if (supportedMethods.isEmpty()) { + String methodDescription = (!candidates.isEmpty()) ? candidates.get(0).toString() : name; throw new EvaluationException("The method '" + methodDescription + "' is not supported by this command processor. " + "If using the Control Bus, consider adding @ManagedOperation or @ManagedAttribute."); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/AbstractRequestHandlerAdvice.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/AbstractRequestHandlerAdvice.java index 73ed529304..aadfe8ed12 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/AbstractRequestHandlerAdvice.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/AbstractRequestHandlerAdvice.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-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. @@ -36,6 +36,7 @@ import org.springframework.messaging.MessagingException; * * @author Gary Russell * @author Artem Bilan + * @author Ngoc Nhan * @since 2.2 */ public abstract class AbstractRequestHandlerAdvice extends IntegrationObjectSupport @@ -162,8 +163,8 @@ public abstract class AbstractRequestHandlerAdvice extends IntegrationObjectSupp * If we don't copy the invocation carefully it won't keep a reference to the other * interceptors in the chain. */ - if (this.invocation instanceof ProxyMethodInvocation) { - return ((ProxyMethodInvocation) this.invocation).invocableClone().proceed(); + if (this.invocation instanceof ProxyMethodInvocation proxyMethodInvocation) { + return proxyMethodInvocation.invocableClone().proceed(); } else { throw new IllegalStateException( diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/CacheRequestHandlerAdvice.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/CacheRequestHandlerAdvice.java index 84a204d59f..8bb6632468 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/CacheRequestHandlerAdvice.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/CacheRequestHandlerAdvice.java @@ -53,6 +53,7 @@ import org.springframework.util.ReflectionUtils; * The default cache {@code key} is {@code payload} of the request message. * * @author Artem Bilan + * @author Ngoc Nhan * * @since 5.2 * @@ -198,8 +199,7 @@ public class CacheRequestHandlerAdvice extends AbstractRequestHandlerAdvice .filter((operation) -> ObjectUtils.isEmpty(operation.getCacheNames())) .map((operation) -> { CacheOperation.Builder builder; - if (operation instanceof CacheableOperation) { - CacheableOperation cacheableOperation = (CacheableOperation) operation; + if (operation instanceof CacheableOperation cacheableOperation) { CacheableOperation.Builder cacheableBuilder = new CacheableOperation.Builder(); cacheableBuilder.setSync(cacheableOperation.isSync()); String unless = cacheableOperation.getUnless(); @@ -208,9 +208,8 @@ public class CacheRequestHandlerAdvice extends AbstractRequestHandlerAdvice } builder = cacheableBuilder; } - else if (operation instanceof CacheEvictOperation) { + else if (operation instanceof CacheEvictOperation cacheEvictOperation) { CacheEvictOperation.Builder cacheEvictBuilder = new CacheEvictOperation.Builder(); - CacheEvictOperation cacheEvictOperation = (CacheEvictOperation) operation; cacheEvictBuilder.setBeforeInvocation(cacheEvictOperation.isBeforeInvocation()); cacheEvictBuilder.setCacheWide(cacheEvictOperation.isCacheWide()); builder = cacheEvictBuilder; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/router/AbstractMappingMessageRouter.java b/spring-integration-core/src/main/java/org/springframework/integration/router/AbstractMappingMessageRouter.java index d1b9d6dcde..81592f684f 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/router/AbstractMappingMessageRouter.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/router/AbstractMappingMessageRouter.java @@ -49,6 +49,7 @@ import org.springframework.util.StringUtils; * @author Gary Russell * @author Artem Bilan * @author Trung Pham + * @author Ngoc Nhan * * @since 2.1 */ @@ -372,25 +373,25 @@ public abstract class AbstractMappingMessageRouter extends AbstractMessageRouter private void addChannelKeyToCollection(Collection channels, Message message, Object channelKey) { ConversionService conversionService = getRequiredConversionService(); - if (channelKey instanceof MessageChannel) { - channels.add((MessageChannel) channelKey); + if (channelKey instanceof MessageChannel messageChannel) { + channels.add(messageChannel); } - else if (channelKey instanceof MessageChannel[]) { - channels.addAll(Arrays.asList((MessageChannel[]) channelKey)); + else if (channelKey instanceof MessageChannel[] messageChannels) { + channels.addAll(Arrays.asList(messageChannels)); } - else if (channelKey instanceof String) { - addChannelFromString(channels, (String) channelKey, message); + else if (channelKey instanceof String string) { + addChannelFromString(channels, string, message); } - else if (channelKey instanceof Class) { - addChannelFromString(channels, ((Class) channelKey).getName(), message); + else if (channelKey instanceof Class cls) { + addChannelFromString(channels, cls.getName(), message); } - else if (channelKey instanceof String[]) { - for (String indicatorName : (String[]) channelKey) { + else if (channelKey instanceof String[] strings) { + for (String indicatorName : strings) { addChannelFromString(channels, indicatorName, message); } } - else if (channelKey instanceof Collection) { - addToCollection(channels, (Collection) channelKey, message); + else if (channelKey instanceof Collection collection) { + addToCollection(channels, collection, message); } else if (conversionService.canConvert(channelKey.getClass(), String.class)) { String converted = conversionService.convert(channelKey, String.class); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/router/AbstractMessageProcessingRouter.java b/spring-integration-core/src/main/java/org/springframework/integration/router/AbstractMessageProcessingRouter.java index 90313b77ae..d795b651c0 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/router/AbstractMessageProcessingRouter.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/router/AbstractMessageProcessingRouter.java @@ -33,6 +33,7 @@ import org.springframework.util.Assert; * {@link MessageProcessor} instance. * * @author Mark Fisher + * @author Ngoc Nhan * @since 2.0 */ class AbstractMessageProcessingRouter extends AbstractMappingMessageRouter @@ -54,28 +55,28 @@ class AbstractMessageProcessingRouter extends AbstractMappingMessageRouter ((AbstractMessageProcessor) this.messageProcessor).setConversionService(conversionService); } } - if (this.messageProcessor instanceof BeanFactoryAware && this.getBeanFactory() != null) { - ((BeanFactoryAware) this.messageProcessor).setBeanFactory(this.getBeanFactory()); + if (this.messageProcessor instanceof BeanFactoryAware beanFactoryAware && this.getBeanFactory() != null) { + beanFactoryAware.setBeanFactory(this.getBeanFactory()); } } @Override public void start() { - if (this.messageProcessor instanceof Lifecycle) { - ((Lifecycle) this.messageProcessor).start(); + if (this.messageProcessor instanceof Lifecycle lifecycle) { + lifecycle.start(); } } @Override public void stop() { - if (this.messageProcessor instanceof Lifecycle) { - ((Lifecycle) this.messageProcessor).stop(); + if (this.messageProcessor instanceof Lifecycle lifecycle) { + lifecycle.stop(); } } @Override public boolean isRunning() { - return !(this.messageProcessor instanceof Lifecycle) || ((Lifecycle) this.messageProcessor).isRunning(); + return !(this.messageProcessor instanceof Lifecycle lifecycle) || lifecycle.isRunning(); } @Override diff --git a/spring-integration-core/src/main/java/org/springframework/integration/splitter/AbstractMessageProcessingSplitter.java b/spring-integration-core/src/main/java/org/springframework/integration/splitter/AbstractMessageProcessingSplitter.java index cc902bc0a0..cceb79ca63 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/splitter/AbstractMessageProcessingSplitter.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/splitter/AbstractMessageProcessingSplitter.java @@ -29,6 +29,7 @@ import org.springframework.util.Assert; * * @author Mark Fisher * @author Artem Bilan + * @author Ngoc Nhan * * @since 2.0 */ @@ -67,7 +68,7 @@ abstract class AbstractMessageProcessingSplitter extends AbstractMessageSplitter @Override public boolean isRunning() { - return !(this.processor instanceof Lifecycle) || ((Lifecycle) this.processor).isRunning(); + return !(this.processor instanceof Lifecycle lifecycle) || lifecycle.isRunning(); } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/splitter/AbstractMessageSplitter.java b/spring-integration-core/src/main/java/org/springframework/integration/splitter/AbstractMessageSplitter.java index 60867c8e35..c3bc15f860 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/splitter/AbstractMessageSplitter.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/splitter/AbstractMessageSplitter.java @@ -52,6 +52,7 @@ import org.springframework.util.ObjectUtils; * @author Artem Bilan * @author Ruslan Stelmachenko * @author Gary Russell + * @author Ngoc Nhan */ public abstract class AbstractMessageSplitter extends AbstractReplyProducingMessageHandler implements DiscardingMessageHandler { @@ -223,7 +224,7 @@ public abstract class AbstractMessageSplitter extends AbstractReplyProducingMess Function messageBuilderFunction = prepareMessageBuilderFunction(message, sequenceSize); return new FunctionIterator<>( - result instanceof AutoCloseable && !result.equals(iterator) ? (AutoCloseable) result : null, + result instanceof AutoCloseable autoCloseable && !result.equals(iterator) ? autoCloseable : null, iterator, messageBuilderFunction); } @@ -314,17 +315,16 @@ public abstract class AbstractMessageSplitter extends AbstractReplyProducingMess @Override protected void produceOutput(Object result, Message requestMessage) { - if (result instanceof Iterator) { - Iterator iterator = (Iterator) result; + if (result instanceof Iterator iterator) { try { while (iterator.hasNext()) { super.produceOutput(iterator.next(), requestMessage); } } finally { - if (iterator instanceof AutoCloseable) { + if (iterator instanceof AutoCloseable autoCloseable) { try { - ((AutoCloseable) iterator).close(); + autoCloseable.close(); } catch (Exception e) { // ignored diff --git a/spring-integration-core/src/main/java/org/springframework/integration/store/AbstractKeyValueMessageStore.java b/spring-integration-core/src/main/java/org/springframework/integration/store/AbstractKeyValueMessageStore.java index 425b05c665..b74be6ca43 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/store/AbstractKeyValueMessageStore.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/store/AbstractKeyValueMessageStore.java @@ -37,6 +37,7 @@ import org.springframework.util.Assert; * @author Oleg Zhurakousky * @author Gary Russell * @author Artem Bilan + * @author Ngoc Nhan * * @since 2.1 */ @@ -107,11 +108,11 @@ public abstract class AbstractKeyValueMessageStore extends AbstractMessageGroupS } private Message extractMessage(Object object) { - if (object instanceof MessageHolder) { - return ((MessageHolder) object).getMessage(); + if (object instanceof MessageHolder messageHolder) { + return messageHolder.getMessage(); } - else if (object instanceof Message) { - return (Message) object; + else if (object instanceof Message message) { + return message; } else { throw new IllegalArgumentException( @@ -126,8 +127,8 @@ public abstract class AbstractKeyValueMessageStore extends AbstractMessageGroupS Object object = doRetrieve(this.messagePrefix + messageId); if (object != null) { extractMessage(object); - if (object instanceof MessageHolder) { - return ((MessageHolder) object).getMessageMetadata(); + if (object instanceof MessageHolder messageHolder) { + return messageHolder.getMessageMetadata(); } } return null; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/store/MessageGroupMetadata.java b/spring-integration-core/src/main/java/org/springframework/integration/store/MessageGroupMetadata.java index 18ad27e4a5..b3f07e944f 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/store/MessageGroupMetadata.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/store/MessageGroupMetadata.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-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. @@ -33,6 +33,7 @@ import org.springframework.util.Assert; * @author Gary Russell * @author Artem Bilan * @author Laszlo Szabo + * @author Ngoc Nhan * * @since 2.1 */ @@ -91,7 +92,7 @@ public class MessageGroupMetadata implements Serializable { } public UUID firstId() { - if (this.messageIds.size() > 0) { + if (!this.messageIds.isEmpty()) { return this.messageIds.get(0); } return null; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/SmartLifecycleRoleController.java b/spring-integration-core/src/main/java/org/springframework/integration/support/SmartLifecycleRoleController.java index 5e4c72d6ba..3e0f13cc05 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/SmartLifecycleRoleController.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/SmartLifecycleRoleController.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2023 the original author or authors. + * Copyright 2015-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. @@ -55,6 +55,7 @@ import org.springframework.util.MultiValueMap; * @author Gary Russell * @author Artem Bilan * @author Christian Tzolov + * @author Ngoc Nhan * * @since 4.2 * @@ -169,7 +170,7 @@ public class SmartLifecycleRoleController implements ApplicationListener 0) { + if (!this.lazyLifecycles.isEmpty()) { addLazyLifecycles(); } List componentsInRole = this.lifecycles.get(role); @@ -201,7 +202,7 @@ public class SmartLifecycleRoleController implements ApplicationListener 0) { + if (!this.lazyLifecycles.isEmpty()) { addLazyLifecycles(); } List componentsInRole = this.lifecycles.get(role); @@ -234,7 +235,7 @@ public class SmartLifecycleRoleController implements ApplicationListener getRoles() { - if (this.lazyLifecycles.size() > 0) { + if (!this.lazyLifecycles.isEmpty()) { addLazyLifecycles(); } return Collections.unmodifiableCollection(this.lifecycles.keySet()); @@ -270,7 +271,7 @@ public class SmartLifecycleRoleController implements ApplicationListener getEndpointsRunningStatus(String role) { - if (this.lazyLifecycles.size() > 0) { + if (!this.lazyLifecycles.isEmpty()) { addLazyLifecycles(); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/json/AbstractJsonInboundMessageMapper.java b/spring-integration-core/src/main/java/org/springframework/integration/support/json/AbstractJsonInboundMessageMapper.java index aeb3371409..30a027aa2e 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/json/AbstractJsonInboundMessageMapper.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/json/AbstractJsonInboundMessageMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-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. @@ -32,6 +32,7 @@ import org.springframework.util.Assert; * * @author Artem Bilan * @author Gary Russell + * @author Ngoc Nhan * * @since 3.0 * @@ -43,7 +44,7 @@ public abstract class AbstractJsonInboundMessageMapper

implements InboundMess "JSON message is invalid. Expected a message in the format of either " + "{\"headers\":{...},\"payload\":{...}} or {\"payload\":{...}.\"headers\":{...}} but was "; - protected static final Map> DEFAULT_HEADER_TYPES = new HashMap>(); + protected static final Map> DEFAULT_HEADER_TYPES = new HashMap<>(); static { DEFAULT_HEADER_TYPES.put(IntegrationMessageHeaderAccessor.PRIORITY, Integer.class); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/json/AdviceMessageJacksonDeserializer.java b/spring-integration-core/src/main/java/org/springframework/integration/support/json/AdviceMessageJacksonDeserializer.java index b344cb8b7f..85fe049382 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/json/AdviceMessageJacksonDeserializer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/json/AdviceMessageJacksonDeserializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2022 the original author or authors. + * Copyright 2017-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. @@ -30,6 +30,7 @@ import org.springframework.messaging.MessageHeaders; * The {@link MessageJacksonDeserializer} implementation for the {@link AdviceMessage}. * * @author Artem Bilan + * @author Ngoc Nhan * * @since 4.3.10 */ @@ -46,7 +47,7 @@ public class AdviceMessageJacksonDeserializer extends MessageJacksonDeserializer protected AdviceMessage buildMessage(MutableMessageHeaders headers, Object payload, JsonNode root, DeserializationContext ctxt) throws IOException { Message inputMessage = getMapper().readValue(root.get("inputMessage").traverse(), Message.class); - return new AdviceMessage(payload, (MessageHeaders) headers, inputMessage); + return new AdviceMessage<>(payload, (MessageHeaders) headers, inputMessage); } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/transaction/TransactionSynchronizationFactoryBean.java b/spring-integration-core/src/main/java/org/springframework/integration/transaction/TransactionSynchronizationFactoryBean.java index 4fc130c69f..f500cb775d 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/transaction/TransactionSynchronizationFactoryBean.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/transaction/TransactionSynchronizationFactoryBean.java @@ -37,6 +37,7 @@ import org.springframework.util.StringUtils; * * @author Artem Bilan * @author Gary Russell + * @author Ngoc Nhan * * @since 4.0 */ @@ -197,8 +198,8 @@ public class TransactionSynchronizationFactoryBean implements FactoryBean visited = new HashSet<>(); recursiveFindAnnotation(annotationType, messagingAnnotation, annotationChain, visited); - if (annotationChain.size() > 0) { + if (!annotationChain.isEmpty()) { Collections.reverse(annotationChain); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/util/UUIDConverter.java b/spring-integration-core/src/main/java/org/springframework/integration/util/UUIDConverter.java index 344867f7bc..331847f481 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/util/UUIDConverter.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/util/UUIDConverter.java @@ -33,6 +33,7 @@ import org.springframework.util.ClassUtils; * @author Gary Russell * @author Christian Tzolov * @author Artem Bilan + * @author Ngoc Nhan */ public class UUIDConverter implements Converter { @@ -66,8 +67,8 @@ public class UUIDConverter implements Converter { if (input == null) { return null; } - if (input instanceof UUID) { - return (UUID) input; + if (input instanceof UUID uuid) { + return uuid; } if (input instanceof String inputText) { if (isValidUuidStringRepresentation(inputText)) { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/util/UniqueMethodFilter.java b/spring-integration-core/src/main/java/org/springframework/integration/util/UniqueMethodFilter.java index c8f0da4ff7..4a60b78ebc 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/util/UniqueMethodFilter.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/util/UniqueMethodFilter.java @@ -26,11 +26,12 @@ import org.springframework.util.ReflectionUtils.MethodFilter; /** * @author Oleg Zhurakousky * @author Artem Bilan + * @author Ngoc Nhan * @since 2.0 */ public class UniqueMethodFilter implements MethodFilter { - private final List uniqueMethods = new ArrayList(); + private final List uniqueMethods = new ArrayList<>(); public UniqueMethodFilter(Class targetClass) { Method[] allMethods = ReflectionUtils.getAllDeclaredMethods(targetClass); diff --git a/spring-integration-event/src/main/java/org/springframework/integration/event/inbound/ApplicationEventListeningMessageProducer.java b/spring-integration-event/src/main/java/org/springframework/integration/event/inbound/ApplicationEventListeningMessageProducer.java index 1c956b46e8..eb9f6efd0e 100644 --- a/spring-integration-event/src/main/java/org/springframework/integration/event/inbound/ApplicationEventListeningMessageProducer.java +++ b/spring-integration-event/src/main/java/org/springframework/integration/event/inbound/ApplicationEventListeningMessageProducer.java @@ -41,6 +41,7 @@ import org.springframework.util.Assert; * @author Mark Fisher * @author Artem Bilan * @author Gary Russell + * @author Ngoc Nhan * * @see ApplicationEventMulticaster * @see ExpressionMessageProducerSupport @@ -80,7 +81,7 @@ public class ApplicationEventListeningMessageProducer extends ExpressionMessageP eventSet.add(ResolvableType.forClass(eventType)); } } - this.eventTypes = (eventSet.size() > 0 ? eventSet : null); + this.eventTypes = (!eventSet.isEmpty() ? eventSet : null); if (this.applicationEventMulticaster != null) { this.applicationEventMulticaster.addApplicationListener(this); diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/FileWritingMessageHandler.java b/spring-integration-file/src/main/java/org/springframework/integration/file/FileWritingMessageHandler.java index 0a24b651eb..caf5bc82ac 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/FileWritingMessageHandler.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/FileWritingMessageHandler.java @@ -112,6 +112,7 @@ import org.springframework.util.StringUtils; * @author Alen Turkovic * @author Trung Pham * @author Christian Tzolov + * @author Ngoc Nhan */ public class FileWritingMessageHandler extends AbstractReplyProducingMessageHandler implements ManageableLifecycle, MessageTriggerAction { @@ -475,9 +476,9 @@ public class FileWritingMessageHandler extends AbstractReplyProducingMessageHand } Flusher flusher = new Flusher(); flusher.run(); - boolean needInterrupt = this.fileStates.size() > 0; + boolean needInterrupt = !this.fileStates.isEmpty(); int n = 0; - while (n++ < 10 && this.fileStates.size() > 0) { // NOSONAR + while (n++ < 10 && !this.fileStates.isEmpty()) { // NOSONAR try { Thread.sleep(1); } @@ -486,7 +487,7 @@ public class FileWritingMessageHandler extends AbstractReplyProducingMessageHand } flusher.run(); } - if (this.fileStates.size() > 0) { + if (!this.fileStates.isEmpty()) { this.logger.error("Failed to flush after multiple attempts, while stopping: " + this.fileStates.keySet()); } if (needInterrupt) { diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/filters/AbstractFileListFilter.java b/spring-integration-file/src/main/java/org/springframework/integration/file/filters/AbstractFileListFilter.java index 36e53c80ac..e3e0c239eb 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/filters/AbstractFileListFilter.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/filters/AbstractFileListFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-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. @@ -29,12 +29,13 @@ import java.util.List; * @author Mark Fisher * @author Iwein Fuld * @author Gary Russell + * @author Ngoc Nhan */ public abstract class AbstractFileListFilter implements FileListFilter { @Override public final List filterFiles(F[] files) { - List accepted = new ArrayList(); + List accepted = new ArrayList<>(); if (files != null) { for (F file : files) { if (this.accept(file)) { diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/filters/AbstractMarkerFilePresentFileListFilter.java b/spring-integration-file/src/main/java/org/springframework/integration/file/filters/AbstractMarkerFilePresentFileListFilter.java index 69da365eab..274edc8263 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/filters/AbstractMarkerFilePresentFileListFilter.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/filters/AbstractMarkerFilePresentFileListFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2021 the original author or authors. + * Copyright 2017-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. @@ -37,6 +37,7 @@ import java.util.stream.Collectors; * @param the target protocol file type. * * @author Gary Russell + * @author Ngoc Nhan * * @since 5.0 * @@ -125,7 +126,7 @@ public abstract class AbstractMarkerFilePresentFileListFilter implements File boolean anyMatch = this.filtersAndFunctions.entrySet().stream().anyMatch(entry -> { F[] fileToCheck = (F[]) Array.newInstance(file.getClass(), 1); fileToCheck[0] = file; - if (entry.getKey().filterFiles(fileToCheck).size() > 0) { + if (!entry.getKey().filterFiles(fileToCheck).isEmpty()) { String markerName = entry.getValue().apply(getFilename(file)); return markerName != null && candidates.contains(markerName); } diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/filters/AbstractPersistentAcceptOnceFileListFilter.java b/spring-integration-file/src/main/java/org/springframework/integration/file/filters/AbstractPersistentAcceptOnceFileListFilter.java index 516ab8a4a1..f00357e264 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/filters/AbstractPersistentAcceptOnceFileListFilter.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/filters/AbstractPersistentAcceptOnceFileListFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2021 the original author or authors. + * Copyright 2013-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. @@ -35,6 +35,7 @@ import org.springframework.util.Assert; * * @author Gary Russell * @author Artem Bilan + * @author Ngoc Nhan * * @since 3.0 * @@ -56,8 +57,8 @@ public abstract class AbstractPersistentAcceptOnceFileListFilter extends Abst Assert.notNull(prefix, "'prefix' cannot be null"); this.store = store; this.prefix = prefix; - if (store instanceof Flushable) { - this.flushableStore = (Flushable) store; + if (store instanceof Flushable flushable) { + this.flushableStore = flushable; } else { this.flushableStore = null; @@ -130,8 +131,8 @@ public abstract class AbstractPersistentAcceptOnceFileListFilter extends Abst @Override public void close() throws IOException { - if (this.store instanceof Closeable) { - ((Closeable) this.store).close(); + if (this.store instanceof Closeable closeable) { + closeable.close(); } } diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/filters/AcceptOnceFileListFilter.java b/spring-integration-file/src/main/java/org/springframework/integration/file/filters/AcceptOnceFileListFilter.java index f91c087b7f..b91a98dbc3 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/filters/AcceptOnceFileListFilter.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/filters/AcceptOnceFileListFilter.java @@ -40,6 +40,7 @@ import org.springframework.lang.Nullable; * @author Gary Russell * @author Artem Bilan * @author Christian Tzolov + * @author Ngoc Nhan */ public class AcceptOnceFileListFilter extends AbstractFileListFilter implements ReversibleFileListFilter, ResettableFileListFilter { @@ -47,7 +48,7 @@ public class AcceptOnceFileListFilter extends AbstractFileListFilter imple @Nullable private final Queue seen; - private final Set seenSet = new HashSet(); + private final Set seenSet = new HashSet<>(); private final Lock monitor = new ReentrantLock(); @@ -58,7 +59,7 @@ public class AcceptOnceFileListFilter extends AbstractFileListFilter imple * @param maxCapacity the maximum number of Files to maintain in the 'seen' queue. */ public AcceptOnceFileListFilter(int maxCapacity) { - this.seen = new LinkedBlockingQueue(maxCapacity); + this.seen = new LinkedBlockingQueue<>(maxCapacity); } /** diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizer.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizer.java index a2f964ac36..6dd85a9bdf 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizer.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizer.java @@ -74,6 +74,7 @@ import org.springframework.util.StringUtils; * @author Oleg Zhurakousky * @author Gary Russell * @author Artem Bilan + * @author Ngoc Nhan * * @since 2.0 */ @@ -137,7 +138,7 @@ public abstract class AbstractInboundFileSynchronizer */ public AbstractInboundFileSynchronizer(SessionFactory sessionFactory) { Assert.notNull(sessionFactory, "sessionFactory must not be null"); - this.remoteFileTemplate = new RemoteFileTemplate(sessionFactory); + this.remoteFileTemplate = new RemoteFileTemplate<>(sessionFactory); } @Nullable @@ -312,8 +313,8 @@ public abstract class AbstractInboundFileSynchronizer @Override public void close() throws IOException { - if (this.filter instanceof Closeable) { - ((Closeable) this.filter).close(); + if (this.filter instanceof Closeable closeable) { + closeable.close(); } } diff --git a/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/inbound/AbstractHazelcastMessageProducer.java b/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/inbound/AbstractHazelcastMessageProducer.java index d03c85b2da..a3c295bf4e 100644 --- a/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/inbound/AbstractHazelcastMessageProducer.java +++ b/spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/inbound/AbstractHazelcastMessageProducer.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-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. @@ -50,6 +50,7 @@ import org.springframework.util.Assert; * * @author Eren Avsarogullari * @author Artem Bilan + * @author Ngoc Nhan * * @since 6.0 */ @@ -218,9 +219,9 @@ public abstract class AbstractHazelcastMessageProducer extends MessageProducerSu entryEvent.getValue(), entryEvent.getOldValue()); return getMessageBuilderFactory().withPayload(messagePayload).copyHeaders(headers).build(); } - else if (event instanceof MapEvent) { + else if (event instanceof MapEvent mapEvent) { return getMessageBuilderFactory() - .withPayload(((MapEvent) event).getNumberOfEntriesAffected()).copyHeaders(headers).build(); + .withPayload(mapEvent.getNumberOfEntriesAffected()).copyHeaders(headers).build(); } else { throw new IllegalStateException("Invalid event is received. Event : " + event); diff --git a/spring-integration-http/src/main/java/org/springframework/integration/http/inbound/BaseHttpInboundEndpoint.java b/spring-integration-http/src/main/java/org/springframework/integration/http/inbound/BaseHttpInboundEndpoint.java index 4a8f88326d..4bc452027b 100644 --- a/spring-integration-http/src/main/java/org/springframework/integration/http/inbound/BaseHttpInboundEndpoint.java +++ b/spring-integration-http/src/main/java/org/springframework/integration/http/inbound/BaseHttpInboundEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2023 the original author or authors. + * Copyright 2017-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. @@ -52,6 +52,7 @@ import org.springframework.validation.Validator; * @author Artem Bilan * @author Gary Russell * @author Trung Pham + * @author Ngoc Nhan * * @since 5.0 */ @@ -311,14 +312,14 @@ public class BaseHttpInboundEndpoint extends MessagingGatewaySupport implements private HttpStatus buildHttpStatus(Object httpStatusValue) { HttpStatus httpStatus = null; - if (httpStatusValue instanceof HttpStatus) { - httpStatus = (HttpStatus) httpStatusValue; + if (httpStatusValue instanceof HttpStatus castHttpStatus) { + httpStatus = castHttpStatus; } - else if (httpStatusValue instanceof Integer) { - httpStatus = HttpStatus.valueOf((Integer) httpStatusValue); + else if (httpStatusValue instanceof Integer integer) { + httpStatus = HttpStatus.valueOf(integer); } - else if (httpStatusValue instanceof String) { - httpStatus = HttpStatus.valueOf(Integer.parseInt((String) httpStatusValue)); + else if (httpStatusValue instanceof String string) { + httpStatus = HttpStatus.valueOf(Integer.parseInt(string)); } return httpStatus; } diff --git a/spring-integration-http/src/main/java/org/springframework/integration/http/outbound/AbstractHttpRequestExecutingMessageHandler.java b/spring-integration-http/src/main/java/org/springframework/integration/http/outbound/AbstractHttpRequestExecutingMessageHandler.java index db98e61a37..32daf0ff41 100644 --- a/spring-integration-http/src/main/java/org/springframework/integration/http/outbound/AbstractHttpRequestExecutingMessageHandler.java +++ b/spring-integration-http/src/main/java/org/springframework/integration/http/outbound/AbstractHttpRequestExecutingMessageHandler.java @@ -73,6 +73,7 @@ import org.springframework.web.util.DefaultUriBuilderFactory; * @author Shiliang Li * @author Florian Schöffl * @author Christian Tzolov + * @author Ngoc Nhan * * @since 5.0 */ @@ -404,7 +405,7 @@ public abstract class AbstractHttpRequestExecutingMessageHandler extends Abstrac private HttpEntity createHttpEntityFromMessage(Message message, HttpMethod httpMethod) { HttpHeaders httpHeaders = mapHeaders(message); if (shouldIncludeRequestBody(httpMethod)) { - return new HttpEntity(message, httpHeaders); + return new HttpEntity<>(message, httpHeaders); } return new HttpEntity<>(httpHeaders); } @@ -447,11 +448,11 @@ public abstract class AbstractHttpRequestExecutingMessageHandler extends Abstrac for (Entry entry : simpleMap.entrySet()) { Object key = entry.getKey(); Object value = entry.getValue(); - if (value instanceof Object[]) { - value = Arrays.asList((Object[]) value); + if (value instanceof Object[] objects) { + value = Arrays.asList(objects); } - if (value instanceof Collection) { - multipartValueMap.put(key, new ArrayList<>((Collection) value)); + if (value instanceof Collection collection) { + multipartValueMap.put(key, new ArrayList<>(collection)); } else { multipartValueMap.add(key, value); @@ -502,8 +503,8 @@ public abstract class AbstractHttpRequestExecutingMessageHandler extends Abstrac Assert.state((httpMethod instanceof String || httpMethod instanceof HttpMethod), () -> "'httpMethodExpression' evaluation must result in an 'HttpMethod' enum or its String representation, " + "not: " + (httpMethod == null ? "null" : httpMethod.getClass())); - if (httpMethod instanceof HttpMethod) { - return (HttpMethod) httpMethod; + if (httpMethod instanceof HttpMethod castHttpMethod) { + return castHttpMethod; } else { try { @@ -537,9 +538,9 @@ public abstract class AbstractHttpRequestExecutingMessageHandler extends Abstrac () -> "The '" + property + "' can be an instance of 'Class', 'String' " + "or 'ParameterizedTypeReference'; " + "evaluation resulted in a " + typeClass + "."); - if (type instanceof String && StringUtils.hasText((String) type)) { + if (type instanceof String string && StringUtils.hasText(string)) { try { - type = ClassUtils.forName((String) type, getApplicationContext().getClassLoader()); + type = ClassUtils.forName(string, getApplicationContext().getClassLoader()); } catch (ClassNotFoundException e) { throw new IllegalStateException("Cannot load class for name: " + type, e); diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/AbstractConnectionFactory.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/AbstractConnectionFactory.java index e6c30a8b9d..1030222a4a 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/AbstractConnectionFactory.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/AbstractConnectionFactory.java @@ -61,6 +61,7 @@ import org.springframework.util.Assert; * @author Gary Russell * @author Artem Bilan * @author Christian Tzolov + * @author Ngoc Nhan * * @since 2.0 * @@ -153,9 +154,8 @@ public abstract class AbstractConnectionFactory extends IntegrationObjectSupport @Override public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) { this.applicationEventPublisher = applicationEventPublisher; - if (!this.deserializerSet && this.deserializer instanceof ApplicationEventPublisherAware) { - ((ApplicationEventPublisherAware) this.deserializer) - .setApplicationEventPublisher(applicationEventPublisher); + if (!this.deserializerSet && this.deserializer instanceof ApplicationEventPublisherAware applicationEventPublisherAware) { + applicationEventPublisherAware.setApplicationEventPublisher(applicationEventPublisher); } } @@ -335,7 +335,7 @@ public abstract class AbstractConnectionFactory extends IntegrationObjectSupport */ @Nullable public TcpSender getSender() { - return this.senders.size() > 0 ? this.senders.get(0) : null; + return !this.senders.isEmpty() ? this.senders.get(0) : null; } /** @@ -827,7 +827,7 @@ public abstract class AbstractConnectionFactory extends IntegrationObjectSupport private void rescheduleDelayedReads(Selector selector, long now) { boolean wakeSelector = false; try { - while (this.delayedReads.size() > 0) { + while (!this.delayedReads.isEmpty()) { if (this.delayedReads.peek().failedAt + this.readDelay < now) { PendingIO pendingRead = this.delayedReads.take(); if (pendingRead.key.channel().isOpen()) { diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpConnectionInterceptorSupport.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpConnectionInterceptorSupport.java index ba3688d6d9..b26fb406be 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpConnectionInterceptorSupport.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpConnectionInterceptorSupport.java @@ -37,6 +37,7 @@ import org.springframework.messaging.support.ErrorMessage; * @author Gary Russell * @author Kazuki Shimizu * @author Christian Tzolov + * @author Ngoc Nhan * * @since 2.0 */ @@ -110,7 +111,7 @@ public abstract class TcpConnectionInterceptorSupport extends TcpConnectionSuppo @Override public void registerSenders(List sendersToRegister) { this.interceptedSenders = sendersToRegister; - if (sendersToRegister.size() > 0) { + if (!sendersToRegister.isEmpty()) { if (!(sendersToRegister.get(0) instanceof TcpConnectionInterceptorSupport)) { this.realSender = true; } @@ -249,8 +250,8 @@ public abstract class TcpConnectionInterceptorSupport extends TcpConnectionSuppo return; } this.removed = true; - if (this.theConnection instanceof TcpConnectionInterceptorSupport && !this.theConnection.equals(this)) { - ((TcpConnectionInterceptorSupport) this.theConnection).removeDeadConnection(this); + if (this.theConnection instanceof TcpConnectionInterceptorSupport tcpConnectionInterceptorSupport && !this.theConnection.equals(this)) { + tcpConnectionInterceptorSupport.removeDeadConnection(this); } TcpSender sender = getSender(); if (sender != null && !(sender instanceof TcpConnectionInterceptorSupport)) { @@ -270,7 +271,7 @@ public abstract class TcpConnectionInterceptorSupport extends TcpConnectionSuppo @Override @Nullable public TcpSender getSender() { - return this.interceptedSenders != null && this.interceptedSenders.size() > 0 + return this.interceptedSenders != null && !this.interceptedSenders.isEmpty() ? this.interceptedSenders.get(0) : null; } diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpConnectionSupport.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpConnectionSupport.java index c9b218c5f9..b780e18c86 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpConnectionSupport.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpConnectionSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2001-2022 the original author or authors. + * Copyright 2001-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. @@ -48,6 +48,7 @@ import org.springframework.util.Assert; * * @author Gary Russell * @author Artem Bilan + * @author Ngoc Nhan * * @since 2.0 * @@ -370,7 +371,7 @@ public abstract class TcpConnectionSupport implements TcpConnection { */ @Nullable public TcpSender getSender() { - return this.senders.size() > 0 ? this.senders.get(0) : null; + return !this.senders.isEmpty() ? this.senders.get(0) : null; } /** diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpMessageMapper.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpMessageMapper.java index 1951a9f042..3cf2fa97ad 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpMessageMapper.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpMessageMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-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. @@ -56,6 +56,7 @@ import org.springframework.util.MimeType; * * * @author Gary Russell * @author Artem Bilan + * @author Ngoc Nhan * * @since 2.0 * @@ -260,12 +261,12 @@ public class TcpMessageMapper implements private byte[] getPayloadAsBytes(Message message) { byte[] bytes = null; Object payload = message.getPayload(); - if (payload instanceof byte[]) { - bytes = (byte[]) payload; + if (payload instanceof byte[] castBytes) { + bytes = castBytes; } - else if (payload instanceof String) { + else if (payload instanceof String string) { try { - bytes = ((String) payload).getBytes(this.charset); + bytes = string.getBytes(this.charset); } catch (UnsupportedEncodingException e) { throw new UncheckedIOException(e); diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetConnection.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetConnection.java index 22e16e0c6b..d00987dbaa 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetConnection.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetConnection.java @@ -1,5 +1,5 @@ /* - * Copyright 2001-2023 the original author or authors. + * Copyright 2001-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. @@ -46,6 +46,7 @@ import org.springframework.util.Assert; * @author Gary Russell * @author Artem Bilan * @author Christian Tzolov + * @author Ngoc Nhan * * @since 2.0 * @@ -172,8 +173,8 @@ public class TcpNetConnection extends TcpConnectionSupport implements Scheduling @Override @Nullable public SSLSession getSslSession() { - if (this.socket instanceof SSLSocket) { - return ((SSLSocket) this.socket).getSession(); + if (this.socket instanceof SSLSocket sslSocket) { + return sslSocket.getSession(); } else { return null; diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioClientConnectionFactory.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioClientConnectionFactory.java index e23a4a4c45..00954ebc05 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioClientConnectionFactory.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioClientConnectionFactory.java @@ -39,6 +39,7 @@ import org.springframework.util.Assert; * @author Gary Russell * @author Artem Bilan * @author Christian Tzolov + * @author Ngoc Nhan * * @since 2.0 * @@ -210,7 +211,7 @@ public class TcpNioClientConnectionFactory extends int selectionCount = 0; try { long timeout = Math.max(soTimeout, 0); - if (getDelayedReads().size() > 0 && (timeout == 0 || getReadDelay() < timeout)) { + if (!getDelayedReads().isEmpty() && (timeout == 0 || getReadDelay() < timeout)) { timeout = getReadDelay(); } selectionCount = this.selector.select(timeout); diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioServerConnectionFactory.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioServerConnectionFactory.java index 56a5f29cbf..541af20456 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioServerConnectionFactory.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioServerConnectionFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-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. @@ -41,6 +41,7 @@ import org.springframework.util.Assert; * * @author Gary Russell * @author Artem Bilan + * @author Ngoc Nhan * * @since 2.0 * @@ -185,7 +186,7 @@ public class TcpNioServerConnectionFactory extends AbstractServerConnectionFacto int selectionCount; try { long timeout = Math.max(soTimeout, 0); - if (getDelayedReads().size() > 0 && (timeout == 0 || getReadDelay() < timeout)) { + if (!getDelayedReads().isEmpty() && (timeout == 0 || getReadDelay() < timeout)) { timeout = getReadDelay(); } long timeoutToLog = timeout; diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/AbstractPooledBufferByteArraySerializer.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/AbstractPooledBufferByteArraySerializer.java index f8addf3656..21887a32de 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/AbstractPooledBufferByteArraySerializer.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/serializer/AbstractPooledBufferByteArraySerializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 the original author or authors. + * Copyright 2016-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. @@ -28,6 +28,7 @@ import org.springframework.util.Assert; * Optionally pools buffers. * * @author Gary Russell + * @author Ngoc Nhan * @since 4.3 * */ @@ -44,7 +45,7 @@ public abstract class AbstractPooledBufferByteArraySerializer extends AbstractBy */ public void setPoolSize(int size) { Assert.isNull(this.pool, "Cannot change pool size once set"); - this.pool = new SimplePool(size, new PoolItemCallback() { + this.pool = new SimplePool<>(size, new PoolItemCallback<>() { @Override public byte[] createForPool() { diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/udp/UnicastSendingMessageHandler.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/udp/UnicastSendingMessageHandler.java index ba638af6ae..cfb7272d03 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/udp/UnicastSendingMessageHandler.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/udp/UnicastSendingMessageHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2001-2023 the original author or authors. + * Copyright 2001-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. @@ -61,6 +61,7 @@ import org.springframework.util.StringUtils; * @author Marcin Pilaczynski * @author Artem Bilan * @author Christian Tzolov + * @author Ngoc Nhan * * @since 2.0 */ @@ -357,15 +358,14 @@ public class UnicastSendingMessageHandler extends SocketAddress destinationAddress; if (this.destinationExpression != null) { Object destination = this.destinationExpression.getValue(this.evaluationContext, message); - if (destination instanceof String) { - destination = new URI((String) destination); + if (destination instanceof String string) { + destination = new URI(string); } - if (destination instanceof URI) { - URI uri = (URI) destination; + if (destination instanceof URI uri) { destination = new InetSocketAddress(uri.getHost(), uri.getPort()); } - if (destination instanceof SocketAddress) { - destinationAddress = (SocketAddress) destination; + if (destination instanceof SocketAddress socketAddress) { + destinationAddress = socketAddress; } else { throw new IllegalStateException("'destinationExpression' must evaluate to String, URI " + diff --git a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/JdbcChannelMessageStore.java b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/JdbcChannelMessageStore.java index f9b0219cd8..86d74db44e 100644 --- a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/JdbcChannelMessageStore.java +++ b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/JdbcChannelMessageStore.java @@ -86,6 +86,7 @@ import org.springframework.util.StringUtils; * @author Meherzad Lahewala * @author Trung Pham * @author Johannes Edmeier + * @author Ngoc Nhan * * @since 2.2 */ @@ -609,7 +610,7 @@ public class JdbcChannelMessageStore implements PriorityCapableChannelMessageSto Assert.state(messages.size() < 2, () -> "The query must return zero or 1 row; got " + messages.size() + " rows"); - if (messages.size() > 0) { + if (!messages.isEmpty()) { final Message message = messages.get(0); UUID id = message.getHeaders().getId(); diff --git a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/JdbcMessageStore.java b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/JdbcMessageStore.java index 0936816d9c..db47f54235 100644 --- a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/JdbcMessageStore.java +++ b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/JdbcMessageStore.java @@ -79,6 +79,7 @@ import org.springframework.util.StringUtils; * @author Will Schipp * @author Gary Russell * @author Artem Bilan + * @author Ngoc Nhan * * @since 2.0 */ @@ -752,7 +753,7 @@ public class JdbcMessageStore extends AbstractMessageGroupStore groupIdKey, this.region, groupIdKey, this.region); Assert.state(messages.size() < 2, () -> "The query must return zero or 1 row; got " + messages.size() + " rows"); - if (messages.size() > 0) { + if (!messages.isEmpty()) { return messages.get(0); } return null; diff --git a/spring-integration-jms/src/main/java/org/springframework/integration/jms/ChannelPublishingJmsMessageListener.java b/spring-integration-jms/src/main/java/org/springframework/integration/jms/ChannelPublishingJmsMessageListener.java index 3ca51ce9f8..cc3cfc0592 100644 --- a/spring-integration-jms/src/main/java/org/springframework/integration/jms/ChannelPublishingJmsMessageListener.java +++ b/spring-integration-jms/src/main/java/org/springframework/integration/jms/ChannelPublishingJmsMessageListener.java @@ -77,6 +77,7 @@ import org.springframework.util.Assert; * @author Oleg Zhurakousky * @author Artem Bilan * @author Gary Russell + * @author Ngoc Nhan */ public class ChannelPublishingJmsMessageListener implements SessionAwareMessageListener, InitializingBean, @@ -558,8 +559,8 @@ public class ChannelPublishingJmsMessageListener * @see #setDestinationResolver */ private Destination resolveDefaultReplyDestination(Session session) throws JMSException { - if (this.defaultReplyDestination instanceof Destination) { - return (Destination) this.defaultReplyDestination; + if (this.defaultReplyDestination instanceof Destination destination) { + return destination; } if (this.defaultReplyDestination instanceof DestinationNameHolder nameHolder) { return this.destinationResolver.resolveDestinationName(session, nameHolder.name, nameHolder.isTopic); diff --git a/spring-integration-jms/src/main/java/org/springframework/integration/jms/PollableJmsChannel.java b/spring-integration-jms/src/main/java/org/springframework/integration/jms/PollableJmsChannel.java index b0a7362d63..1085c960f7 100644 --- a/spring-integration-jms/src/main/java/org/springframework/integration/jms/PollableJmsChannel.java +++ b/spring-integration-jms/src/main/java/org/springframework/integration/jms/PollableJmsChannel.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-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. @@ -35,6 +35,7 @@ import org.springframework.messaging.support.ExecutorChannelInterceptor; * @author Oleg Zhurakousky * @author Gary Russell * @author Artem Bilan + * @author Ngoc Nhan * * @since 2.0 */ @@ -77,7 +78,7 @@ public class PollableJmsChannel extends AbstractJmsChannel if (isLoggingEnabled()) { logger.trace(() -> "preReceive on channel '" + this + "'"); } - if (interceptorList.getInterceptors().size() > 0) { + if (!interceptorList.getInterceptors().isEmpty()) { interceptorStack = new ArrayDeque<>(); if (!interceptorList.preReceive(this, interceptorStack)) { diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/NotificationPublishingMessageHandler.java b/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/NotificationPublishingMessageHandler.java index 81f24215e7..f6a67fc2be 100644 --- a/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/NotificationPublishingMessageHandler.java +++ b/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/NotificationPublishingMessageHandler.java @@ -48,6 +48,7 @@ import org.springframework.util.Assert; * @author Gary Russell * @author Artem Bilan * @author Trung Pham + * @author Ngoc Nhan * * @since 2.0 */ @@ -118,7 +119,7 @@ public class NotificationPublishingMessageHandler extends AbstractMessageHandler Map exporters = BeanFactoryUtils.beansOfTypeIncludingAncestors((ListableBeanFactory) beanFactory, MBeanExporter.class); - Assert.state(exporters.size() > 0, "No MBeanExporter is available in the current context."); + Assert.state(!exporters.isEmpty(), "No MBeanExporter is available in the current context."); MBeanExporter exporter = null; for (MBeanExporter exp : exporters.values()) { exporter = exp; diff --git a/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/support/parametersource/BeanPropertyParameterSource.java b/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/support/parametersource/BeanPropertyParameterSource.java index 279a5d8291..a2c30a0de7 100644 --- a/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/support/parametersource/BeanPropertyParameterSource.java +++ b/spring-integration-jpa/src/main/java/org/springframework/integration/jpa/support/parametersource/BeanPropertyParameterSource.java @@ -28,6 +28,7 @@ import org.springframework.beans.PropertyAccessorFactory; * * @author Gunnar Hillert * @author Gary Russell + * @author Ngoc Nhan * * @since 2.2 * @@ -69,7 +70,7 @@ public class BeanPropertyParameterSource implements ParameterSource { */ public String[] getReadablePropertyNames() { if (this.propertyNames == null) { - final List names = new ArrayList(); + final List names = new ArrayList<>(); PropertyDescriptor[] props = this.beanWrapper.getPropertyDescriptors(); for (PropertyDescriptor pd : props) { if (this.beanWrapper.isReadableProperty(pd.getName())) { diff --git a/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/channel/PollableKafkaChannel.java b/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/channel/PollableKafkaChannel.java index 47b7ba9a6b..2c94c23ee1 100644 --- a/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/channel/PollableKafkaChannel.java +++ b/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/channel/PollableKafkaChannel.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 the original author or authors. + * Copyright 2020-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. @@ -37,6 +37,7 @@ import org.springframework.util.Assert; * * @author Gary Russell * @author Artem Bilan + * @author Ngoc Nhan * * @since 5.4 * @@ -85,7 +86,7 @@ public class PollableKafkaChannel extends AbstractKafkaChannel if (isLoggingEnabled()) { logger.trace(() -> "preReceive on channel '" + this + "'"); } - if (interceptorList.getInterceptors().size() > 0) { + if (!interceptorList.getInterceptors().isEmpty()) { interceptorStack = new ArrayDeque<>(); if (!interceptorList.preReceive(this, interceptorStack)) { return null; diff --git a/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/inbound/KafkaMessageSource.java b/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/inbound/KafkaMessageSource.java index 2c6ba72644..cf91379973 100644 --- a/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/inbound/KafkaMessageSource.java +++ b/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/inbound/KafkaMessageSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 the original author or authors. + * Copyright 2018-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,6 +104,7 @@ import org.springframework.util.StringUtils; * @author Artem Bilan * @author Anshul Mehra * @author Christian Tzolov + * @author Ngoc Nhan * * @since 5.4 * @@ -843,7 +844,7 @@ public class KafkaMessageSource extends AbstractMessageSource return i.getRecord().offset(); }) .collect(Collectors.toList()); - if (rewound.size() > 0) { + if (!rewound.isEmpty()) { this.logger.warn(() -> "Rolled back " + KafkaUtils.format(record) + " later in-flight offsets " + rewound + " will also be re-fetched"); @@ -875,7 +876,7 @@ public class KafkaMessageSource extends AbstractMessageSource } } } - if (toCommit.size() > 0) { + if (!toCommit.isEmpty()) { ackInformation = toCommit.get(toCommit.size() - 1); KafkaAckInfo ackInformationToLog = ackInformation; this.commitLogger.log(() -> "Committing pending offsets for " diff --git a/spring-integration-mail/src/main/java/org/springframework/integration/mail/AbstractMailReceiver.java b/spring-integration-mail/src/main/java/org/springframework/integration/mail/AbstractMailReceiver.java index c91fb69270..8000586b71 100755 --- a/spring-integration-mail/src/main/java/org/springframework/integration/mail/AbstractMailReceiver.java +++ b/spring-integration-mail/src/main/java/org/springframework/integration/mail/AbstractMailReceiver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-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. @@ -67,6 +67,7 @@ import org.springframework.util.ObjectUtils; * @author Artem Bilan * @author Dominik Simmen * @author Yuxin Wang + * @author Ngoc Nhan */ public abstract class AbstractMailReceiver extends IntegrationObjectSupport implements MailReceiver, DisposableBean { @@ -474,19 +475,19 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl headers.put(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN_VALUE); } } - else if (content instanceof InputStream) { + else if (content instanceof InputStream inputStream) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); - FileCopyUtils.copy((InputStream) content, baos); + FileCopyUtils.copy(inputStream, baos); content = byteArrayToContent(headers, baos); } - else if (content instanceof Multipart && this.embeddedPartsAsBytes) { + else if (content instanceof Multipart multipart && this.embeddedPartsAsBytes) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ((Multipart) content).writeTo(baos); + multipart.writeTo(baos); content = byteArrayToContent(headers, baos); } - else if (content instanceof Part && this.embeddedPartsAsBytes) { + else if (content instanceof Part part && this.embeddedPartsAsBytes) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ((Part) content).writeTo(baos); + part.writeTo(baos); content = byteArrayToContent(headers, baos); } return content; diff --git a/spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/inbound/AbstractMongoDbMessageSource.java b/spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/inbound/AbstractMongoDbMessageSource.java index fae39b04bc..6c7001b949 100644 --- a/spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/inbound/AbstractMongoDbMessageSource.java +++ b/spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/inbound/AbstractMongoDbMessageSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 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. @@ -51,6 +51,7 @@ import org.springframework.util.MultiValueMap; * @param The payload type. * * @author Artem Bilan + * @author Ngoc Nhan * * @since 5.5 */ @@ -175,9 +176,9 @@ public abstract class AbstractMongoDbMessageSource extends AbstractMessageSou protected void onInit() { super.onInit(); TypeLocator typeLocator = getEvaluationContext().getTypeLocator(); - if (typeLocator instanceof StandardTypeLocator) { + if (typeLocator instanceof StandardTypeLocator standardTypeLocator) { //Register MongoDB query API package so FQCN can be avoided in query-expression. - ((StandardTypeLocator) typeLocator).registerImport("org.springframework.data.mongodb.core.query"); + standardTypeLocator.registerImport("org.springframework.data.mongodb.core.query"); } } @@ -185,11 +186,11 @@ public abstract class AbstractMongoDbMessageSource extends AbstractMessageSou Object value = this.queryExpression.getValue(getEvaluationContext()); Assert.notNull(value, "'queryExpression' must not evaluate to null"); Query query = null; - if (value instanceof String) { - query = new BasicQuery((String) value); + if (value instanceof String string) { + query = new BasicQuery(string); } - else if (value instanceof Query) { - query = ((Query) value); + else if (value instanceof Query castQuery) { + query = castQuery; } else { throw new IllegalStateException("'queryExpression' must evaluate to String " + @@ -244,11 +245,11 @@ public abstract class AbstractMongoDbMessageSource extends AbstractMessageSou Object value = this.updateExpression.getValue(getEvaluationContext()); Assert.notNull(value, "'updateExpression' must not evaluate to null"); Update update; - if (value instanceof String) { - update = new BasicUpdate((String) value); + if (value instanceof String string) { + update = new BasicUpdate(string); } - else if (value instanceof Update) { - update = ((Update) value); + else if (value instanceof Update castUpdate) { + update = castUpdate; } else { throw new IllegalStateException("'updateExpression' must evaluate to String " + diff --git a/spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/store/ConfigurableMongoDbMessageStore.java b/spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/store/ConfigurableMongoDbMessageStore.java index 88577b5263..6176a2ccaf 100644 --- a/spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/store/ConfigurableMongoDbMessageStore.java +++ b/spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/store/ConfigurableMongoDbMessageStore.java @@ -53,6 +53,7 @@ import org.springframework.util.Assert; * @author Amol Nayak * @author Artem Bilan * @author Gary Russell + * @author Ngoc Nhan * * @since 3.0 */ @@ -194,7 +195,7 @@ public class ConfigurableMongoDbMessageStore extends AbstractConfigurableMongoDb ids.clear(); } } - if (ids.size() > 0) { + if (!ids.isEmpty()) { removeMessages(groupId, ids); } updateGroup(groupId, lastModifiedUpdate()); diff --git a/spring-integration-scripting/src/main/java/org/springframework/integration/scripting/config/AbstractScriptParser.java b/spring-integration-scripting/src/main/java/org/springframework/integration/scripting/config/AbstractScriptParser.java index 1ea0f5649c..235aef4d76 100644 --- a/spring-integration-scripting/src/main/java/org/springframework/integration/scripting/config/AbstractScriptParser.java +++ b/spring-integration-scripting/src/main/java/org/springframework/integration/scripting/config/AbstractScriptParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-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. @@ -37,6 +37,7 @@ import org.springframework.util.xml.DomUtils; /** * @author David Turanski * @author Artem Bilan + * @author Ngoc Nhan * */ public abstract class AbstractScriptParser extends AbstractSingleBeanDefinitionParser { @@ -63,7 +64,7 @@ public abstract class AbstractScriptParser extends AbstractSingleBeanDefinitionP List variableElements = DomUtils.getChildElementsByTagName(element, "variable"); String scriptVariableGeneratorName = element.getAttribute("script-variable-generator"); - if (StringUtils.hasText(scriptVariableGeneratorName) && variableElements.size() > 0) { + if (StringUtils.hasText(scriptVariableGeneratorName) && !variableElements.isEmpty()) { parserContext.getReaderContext().error( "'script-variable-generator' and 'variable' sub-elements are mutually exclusive.", element); return; diff --git a/spring-integration-scripting/src/main/java/org/springframework/integration/scripting/jsr223/AbstractScriptExecutor.java b/spring-integration-scripting/src/main/java/org/springframework/integration/scripting/jsr223/AbstractScriptExecutor.java index 2afd5eca2e..4872d397ee 100644 --- a/spring-integration-scripting/src/main/java/org/springframework/integration/scripting/jsr223/AbstractScriptExecutor.java +++ b/spring-integration-scripting/src/main/java/org/springframework/integration/scripting/jsr223/AbstractScriptExecutor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-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. @@ -40,6 +40,7 @@ import org.springframework.util.Assert; * @author Mark Fisher * @author Artem Bilan * @author Gary Russell + * @author Ngoc Nhan * * @since 2.1 */ @@ -79,7 +80,7 @@ public abstract class AbstractScriptExecutor implements ScriptExecutor { } Bindings bindings = null; - if (variables != null && variables.size() > 0) { + if (variables != null && !variables.isEmpty()) { bindings = new SimpleBindings(variables); result = this.scriptEngine.eval(script, bindings); } diff --git a/spring-integration-stream/src/main/java/org/springframework/integration/stream/ByteStreamReadingMessageSource.java b/spring-integration-stream/src/main/java/org/springframework/integration/stream/ByteStreamReadingMessageSource.java index d92401d526..db417b4003 100644 --- a/spring-integration-stream/src/main/java/org/springframework/integration/stream/ByteStreamReadingMessageSource.java +++ b/spring-integration-stream/src/main/java/org/springframework/integration/stream/ByteStreamReadingMessageSource.java @@ -31,6 +31,7 @@ import org.springframework.messaging.MessagingException; * @author Mark Fisher * @author Artem Bilan * @author Christian Tzolov + * @author Ngoc Nhan */ public class ByteStreamReadingMessageSource extends AbstractMessageSource { @@ -47,8 +48,8 @@ public class ByteStreamReadingMessageSource extends AbstractMessageSource 0) { this.stream = new BufferedInputStream(stream, bufferSize); diff --git a/spring-integration-stream/src/main/java/org/springframework/integration/stream/ByteStreamWritingMessageHandler.java b/spring-integration-stream/src/main/java/org/springframework/integration/stream/ByteStreamWritingMessageHandler.java index 234ce71757..d38370b538 100644 --- a/spring-integration-stream/src/main/java/org/springframework/integration/stream/ByteStreamWritingMessageHandler.java +++ b/spring-integration-stream/src/main/java/org/springframework/integration/stream/ByteStreamWritingMessageHandler.java @@ -30,6 +30,7 @@ import org.springframework.messaging.MessagingException; * * @author Mark Fisher * @author Gary Russell + * @author Ngoc Nhan */ public class ByteStreamWritingMessageHandler extends AbstractMessageHandler { @@ -57,11 +58,11 @@ public class ByteStreamWritingMessageHandler extends AbstractMessageHandler { protected void handleMessageInternal(Message message) { Object payload = message.getPayload(); try { - if (payload instanceof String) { - this.stream.write(((String) payload).getBytes()); + if (payload instanceof String string) { + this.stream.write(string.getBytes()); } - else if (payload instanceof byte[]) { - this.stream.write((byte[]) payload); + else if (payload instanceof byte[] bytes) { + this.stream.write(bytes); } else { throw new MessagingException(this.getClass().getSimpleName() + diff --git a/spring-integration-stream/src/main/java/org/springframework/integration/stream/CharacterStreamReadingMessageSource.java b/spring-integration-stream/src/main/java/org/springframework/integration/stream/CharacterStreamReadingMessageSource.java index 54c7f728b6..35793956af 100644 --- a/spring-integration-stream/src/main/java/org/springframework/integration/stream/CharacterStreamReadingMessageSource.java +++ b/spring-integration-stream/src/main/java/org/springframework/integration/stream/CharacterStreamReadingMessageSource.java @@ -37,6 +37,7 @@ import org.springframework.util.Assert; * @author Gary Russell * @author Artem Bilan * @author Christian Tzolov + * @author Ngoc Nhan */ public class CharacterStreamReadingMessageSource extends AbstractMessageSource implements ApplicationEventPublisherAware { @@ -92,8 +93,8 @@ public class CharacterStreamReadingMessageSource extends AbstractMessageSource 0) { this.reader = new BufferedReader(reader, bufferSize); diff --git a/spring-integration-syslog/src/main/java/org/springframework/integration/syslog/inbound/SyslogReceivingChannelAdapterSupport.java b/spring-integration-syslog/src/main/java/org/springframework/integration/syslog/inbound/SyslogReceivingChannelAdapterSupport.java index a381754bf5..bb683ba54d 100644 --- a/spring-integration-syslog/src/main/java/org/springframework/integration/syslog/inbound/SyslogReceivingChannelAdapterSupport.java +++ b/spring-integration-syslog/src/main/java/org/springframework/integration/syslog/inbound/SyslogReceivingChannelAdapterSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-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. @@ -27,6 +27,7 @@ import org.springframework.messaging.support.ErrorMessage; * Base support class for inbound channel adapters. The default port is 514. * * @author Gary Russell + * @author Ngoc Nhan * @since 3.0 * */ @@ -79,9 +80,9 @@ public abstract class SyslogReceivingChannelAdapterSupport extends MessageProduc protected void convertAndSend(Message message) { try { - if (message instanceof ErrorMessage) { + if (message instanceof ErrorMessage errorMessage) { if (this.logger.isDebugEnabled()) { - this.logger.debug("Error on syslog socket:" + ((ErrorMessage) message).getPayload().getMessage()); + this.logger.debug("Error on syslog socket:" + errorMessage.getPayload().getMessage()); } } else { diff --git a/spring-integration-webflux/src/main/java/org/springframework/integration/webflux/config/WebFluxIntegrationConfigurationInitializer.java b/spring-integration-webflux/src/main/java/org/springframework/integration/webflux/config/WebFluxIntegrationConfigurationInitializer.java index 70eaa6d881..73be4785e1 100644 --- a/spring-integration-webflux/src/main/java/org/springframework/integration/webflux/config/WebFluxIntegrationConfigurationInitializer.java +++ b/spring-integration-webflux/src/main/java/org/springframework/integration/webflux/config/WebFluxIntegrationConfigurationInitializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2023 the original author or authors. + * Copyright 2017-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. @@ -37,6 +37,7 @@ import org.springframework.integration.webflux.support.WebFluxContextUtils; * * @author Artem Bilan * @author Chris Bono + * @author Ngoc Nhan * * @since 5.0 */ @@ -46,8 +47,8 @@ public class WebFluxIntegrationConfigurationInitializer implements IntegrationCo @Override public void initialize(ConfigurableListableBeanFactory beanFactory) throws BeansException { - if (beanFactory instanceof BeanDefinitionRegistry) { - registerReactiveRequestMappingHandlerMappingIfNecessary((BeanDefinitionRegistry) beanFactory); + if (beanFactory instanceof BeanDefinitionRegistry beanDefinitionRegistry) { + registerReactiveRequestMappingHandlerMappingIfNecessary(beanDefinitionRegistry); } else { LOGGER.warn("'IntegrationRequestMappingHandlerMapping' isn't registered because 'beanFactory'" + diff --git a/spring-integration-webflux/src/main/java/org/springframework/integration/webflux/inbound/WebFluxInboundEndpoint.java b/spring-integration-webflux/src/main/java/org/springframework/integration/webflux/inbound/WebFluxInboundEndpoint.java index ecad415475..8f83c82b5e 100644 --- a/spring-integration-webflux/src/main/java/org/springframework/integration/webflux/inbound/WebFluxInboundEndpoint.java +++ b/spring-integration-webflux/src/main/java/org/springframework/integration/webflux/inbound/WebFluxInboundEndpoint.java @@ -73,6 +73,7 @@ import org.springframework.web.server.WebHandler; * * @author Artem Bilan * @author Gary Russell + * @author Ngoc Nhan * * @since 5.0 * @@ -362,8 +363,8 @@ public class WebFluxInboundEndpoint extends BaseHttpInboundEndpoint implements W responseContent = replyMessage.getPayload(); } - if (responseContent instanceof HttpStatus) { - response.setStatusCode((HttpStatus) responseContent); + if (responseContent instanceof HttpStatus httpStatus) { + response.setStatusCode(httpStatus); return response.setComplete(); } else { diff --git a/spring-integration-webflux/src/main/java/org/springframework/integration/webflux/inbound/WebFluxIntegrationRequestMappingHandlerMapping.java b/spring-integration-webflux/src/main/java/org/springframework/integration/webflux/inbound/WebFluxIntegrationRequestMappingHandlerMapping.java index 863e8d6f13..fc108cb0ec 100644 --- a/spring-integration-webflux/src/main/java/org/springframework/integration/webflux/inbound/WebFluxIntegrationRequestMappingHandlerMapping.java +++ b/spring-integration-webflux/src/main/java/org/springframework/integration/webflux/inbound/WebFluxIntegrationRequestMappingHandlerMapping.java @@ -76,6 +76,7 @@ import org.springframework.web.server.WebHandler; * * @author Artem Bilan * @author Gary Russell + * @author Ngoc Nhan * * @since 5.0 * @@ -118,8 +119,8 @@ public class WebFluxIntegrationRequestMappingHandlerMapping extends RequestMappi @Override protected void detectHandlerMethods(Object handler) { - if (handler instanceof String) { - handler = getApplicationContext().getBean((String) handler); // NOSONAR never null + if (handler instanceof String string) { + handler = getApplicationContext().getBean(string); // NOSONAR never null } RequestMappingInfo mapping = getMappingForEndpoint((WebFluxInboundEndpoint) handler); if (mapping != null) { diff --git a/spring-integration-webflux/src/main/java/org/springframework/integration/webflux/outbound/WebFluxRequestExecutingMessageHandler.java b/spring-integration-webflux/src/main/java/org/springframework/integration/webflux/outbound/WebFluxRequestExecutingMessageHandler.java index b85c36c11d..1d135f2ac4 100644 --- a/spring-integration-webflux/src/main/java/org/springframework/integration/webflux/outbound/WebFluxRequestExecutingMessageHandler.java +++ b/spring-integration-webflux/src/main/java/org/springframework/integration/webflux/outbound/WebFluxRequestExecutingMessageHandler.java @@ -61,6 +61,7 @@ import org.springframework.web.util.DefaultUriBuilderFactory; * @author Gary Russell * @author David Graff * @author Jatin Saxena + * @author Ngoc Nhan * * @since 5.0 * @@ -249,8 +250,8 @@ public class WebFluxRequestExecutingMessageHandler extends AbstractHttpRequestEx WebClient.RequestBodyUriSpec requestBodyUriSpec = this.webClient.method(httpMethod); WebClient.RequestBodySpec requestSpec; - if (uri instanceof URI) { - requestSpec = requestBodyUriSpec.uri((URI) uri); + if (uri instanceof URI castUri) { + requestSpec = requestBodyUriSpec.uri(castUri); } else { requestSpec = requestBodyUriSpec.uri((String) uri, uriVariables); @@ -287,14 +288,14 @@ public class WebFluxRequestExecutingMessageHandler extends AbstractHttpRequestEx } BodyInserter inserter; - if (requestBody instanceof Resource) { - inserter = BodyInserters.fromResource((Resource) requestBody); + if (requestBody instanceof Resource resource) { + inserter = BodyInserters.fromResource(resource); } - else if (requestBody instanceof Publisher) { - inserter = buildBodyInserterForPublisher(requestMessage, (Publisher) requestBody); + else if (requestBody instanceof Publisher publisher) { + inserter = buildBodyInserterForPublisher(requestMessage, publisher); } - else if (requestBody instanceof MultiValueMap) { - inserter = buildBodyInserterForMultiValueMap((MultiValueMap) requestBody, + else if (requestBody instanceof MultiValueMap multiValueMap) { + inserter = buildBodyInserterForMultiValueMap(multiValueMap, httpRequest.getHeaders().getContentType()); } else { @@ -350,8 +351,8 @@ public class WebFluxRequestExecutingMessageHandler extends AbstractHttpRequestEx private BodyExtractor, ? super ClientHttpResponse> createBodyExtractor(Object expectedResponseType) { if (expectedResponseType != null) { if (this.replyPayloadToFlux) { - if (expectedResponseType instanceof ParameterizedTypeReference) { - return BodyExtractors.toFlux((ParameterizedTypeReference) expectedResponseType); + if (expectedResponseType instanceof ParameterizedTypeReference parameterizedTypeReference) { + return BodyExtractors.toFlux(parameterizedTypeReference); } else { return BodyExtractors.toFlux((Class) expectedResponseType); @@ -359,8 +360,8 @@ public class WebFluxRequestExecutingMessageHandler extends AbstractHttpRequestEx } else { BodyExtractor, ReactiveHttpInputMessage> monoExtractor; - if (expectedResponseType instanceof ParameterizedTypeReference) { - monoExtractor = BodyExtractors.toMono((ParameterizedTypeReference) expectedResponseType); + if (expectedResponseType instanceof ParameterizedTypeReference parameterizedTypeReference) { + monoExtractor = BodyExtractors.toMono(parameterizedTypeReference); } else { monoExtractor = BodyExtractors.toMono((Class) expectedResponseType); @@ -371,8 +372,8 @@ public class WebFluxRequestExecutingMessageHandler extends AbstractHttpRequestEx else if (this.bodyExtractor != null) { return (inputMessage, context) -> { Object body = this.bodyExtractor.extract(inputMessage, context); - if (body instanceof Publisher) { - return Flux.from((Publisher) body); + if (body instanceof Publisher publisher) { + return Flux.from(publisher); } return Flux.just(body); }; diff --git a/spring-integration-websocket/src/main/java/org/springframework/integration/websocket/config/WebSocketAdapterParsingUtils.java b/spring-integration-websocket/src/main/java/org/springframework/integration/websocket/config/WebSocketAdapterParsingUtils.java index f4a3777a60..917352f456 100644 --- a/spring-integration-websocket/src/main/java/org/springframework/integration/websocket/config/WebSocketAdapterParsingUtils.java +++ b/spring-integration-websocket/src/main/java/org/springframework/integration/websocket/config/WebSocketAdapterParsingUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2022 the original author or authors. + * Copyright 2014-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. @@ -31,6 +31,7 @@ import org.springframework.util.StringUtils; /** * @author Artem Bilan + * @author Ngoc Nhan * @since 4.1 */ abstract class WebSocketAdapterParsingUtils { @@ -48,7 +49,7 @@ abstract class WebSocketAdapterParsingUtils { boolean hasDefaultProtocolHandler = StringUtils.hasText(defaultProtocolHandler); if (hasProtocolHandlers || hasDefaultProtocolHandler) { - List protocolHandlerList = new ManagedList(); + List protocolHandlerList = new ManagedList<>(); String[] ids = StringUtils.commaDelimitedListToStringArray(protocolHandlers); for (String id : ids) { protocolHandlerList.add(new RuntimeBeanReference(id)); @@ -64,7 +65,7 @@ abstract class WebSocketAdapterParsingUtils { String messageConverters = element.getAttribute("message-converters"); if (StringUtils.hasText(messageConverters)) { - List messageConverterList = new ManagedList(); + List messageConverterList = new ManagedList<>(); String[] ids = StringUtils.commaDelimitedListToStringArray(messageConverters); for (String id : ids) { messageConverterList.add(new RuntimeBeanReference(id)); diff --git a/spring-integration-websocket/src/main/java/org/springframework/integration/websocket/config/WebSocketIntegrationConfigurationInitializer.java b/spring-integration-websocket/src/main/java/org/springframework/integration/websocket/config/WebSocketIntegrationConfigurationInitializer.java index 13fc2eb99b..a575da7599 100644 --- a/spring-integration-websocket/src/main/java/org/springframework/integration/websocket/config/WebSocketIntegrationConfigurationInitializer.java +++ b/spring-integration-websocket/src/main/java/org/springframework/integration/websocket/config/WebSocketIntegrationConfigurationInitializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2023 the original author or authors. + * Copyright 2014-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. @@ -43,6 +43,7 @@ import org.springframework.web.util.pattern.PathPatternParser; * @author Artem Bilan * @author Gary Russell * @author Chris Bono + * @author Ngoc Nhan * * @since 4.1 */ @@ -56,8 +57,8 @@ public class WebSocketIntegrationConfigurationInitializer implements Integration @Override public void initialize(ConfigurableListableBeanFactory beanFactory) throws BeansException { - if (beanFactory instanceof BeanDefinitionRegistry) { - registerEnableWebSocketIfNecessary((BeanDefinitionRegistry) beanFactory); + if (beanFactory instanceof BeanDefinitionRegistry beanDefinitionRegistry) { + registerEnableWebSocketIfNecessary(beanDefinitionRegistry); } else { LOGGER.warn("'DelegatingWebSocketConfiguration' isn't registered because 'beanFactory'" + diff --git a/spring-integration-websocket/src/main/java/org/springframework/integration/websocket/inbound/WebSocketInboundChannelAdapter.java b/spring-integration-websocket/src/main/java/org/springframework/integration/websocket/inbound/WebSocketInboundChannelAdapter.java index 08b251f22b..a1c398199a 100644 --- a/spring-integration-websocket/src/main/java/org/springframework/integration/websocket/inbound/WebSocketInboundChannelAdapter.java +++ b/spring-integration-websocket/src/main/java/org/springframework/integration/websocket/inbound/WebSocketInboundChannelAdapter.java @@ -66,6 +66,7 @@ import org.springframework.web.socket.messaging.SubProtocolHandler; * The {@link MessageProducerSupport} for inbound WebSocket messages. * * @author Artem Bilan + * @author Ngoc Nhan * * @since 4.1 */ @@ -281,15 +282,15 @@ public class WebSocketInboundChannelAdapter extends MessageProducerSupport @Override protected void doStart() { - if (this.webSocketContainer instanceof Lifecycle) { - ((Lifecycle) this.webSocketContainer).start(); + if (this.webSocketContainer instanceof Lifecycle lifecycle) { + lifecycle.start(); } } @Override protected void doStop() { - if (this.webSocketContainer instanceof Lifecycle) { - ((Lifecycle) this.webSocketContainer).stop(); + if (this.webSocketContainer instanceof Lifecycle lifecycle) { + lifecycle.stop(); } } diff --git a/spring-integration-ws/src/main/java/org/springframework/integration/ws/AbstractWebServiceInboundGateway.java b/spring-integration-ws/src/main/java/org/springframework/integration/ws/AbstractWebServiceInboundGateway.java index 64fbef299e..b70684db98 100644 --- a/spring-integration-ws/src/main/java/org/springframework/integration/ws/AbstractWebServiceInboundGateway.java +++ b/spring-integration-ws/src/main/java/org/springframework/integration/ws/AbstractWebServiceInboundGateway.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-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. @@ -36,6 +36,7 @@ import org.springframework.ws.soap.SoapMessage; /** * @author Oleg Zhurakousky * @author Artem Bilan + * @author Ngoc Nhan * * @since 2.1 */ @@ -73,8 +74,8 @@ public abstract class AbstractWebServiceInboundGateway extends MessagingGatewayS } catch (Exception e) { while ((e instanceof MessagingException || e instanceof ExpressionException) && // NOSONAR - e.getCause() instanceof Exception) { - e = (Exception) e.getCause(); + e.getCause() instanceof Exception exception) { + e = exception; } throw e; } @@ -91,8 +92,7 @@ public abstract class AbstractWebServiceInboundGateway extends MessagingGatewayS builder.setHeader(propertyName, messageContext.getProperty(propertyName)); } } - if (request instanceof SoapMessage) { - SoapMessage soapMessage = (SoapMessage) request; + if (request instanceof SoapMessage soapMessage) { Map headers = this.headerMapper.toHeadersFromRequest(soapMessage); if (!CollectionUtils.isEmpty(headers)) { builder.copyHeaders(headers); @@ -101,9 +101,9 @@ public abstract class AbstractWebServiceInboundGateway extends MessagingGatewayS } protected void toSoapHeaders(WebServiceMessage response, Message replyMessage) { - if (response instanceof SoapMessage) { + if (response instanceof SoapMessage soapMessage) { this.headerMapper.fromHeadersToReply( - replyMessage.getHeaders(), (SoapMessage) response); + replyMessage.getHeaders(), soapMessage); } } diff --git a/spring-integration-ws/src/main/java/org/springframework/integration/ws/AbstractWebServiceOutboundGateway.java b/spring-integration-ws/src/main/java/org/springframework/integration/ws/AbstractWebServiceOutboundGateway.java index 377abca9c3..f053ad65bd 100644 --- a/spring-integration-ws/src/main/java/org/springframework/integration/ws/AbstractWebServiceOutboundGateway.java +++ b/spring-integration-ws/src/main/java/org/springframework/integration/ws/AbstractWebServiceOutboundGateway.java @@ -58,6 +58,7 @@ import org.springframework.xml.transform.TransformerObjectSupport; * @author Gary Russell * @author Artem Bilan * @author Christian Tzolov + * @author Ngoc Nhan */ public abstract class AbstractWebServiceOutboundGateway extends AbstractReplyProducingMessageHandler { @@ -206,8 +207,8 @@ public abstract class AbstractWebServiceOutboundGateway extends AbstractReplyPro } Object responsePayload = doHandle(uriWithVariables.toString(), requestMessage, this.requestCallback); if (responsePayload != null && !(this.ignoreEmptyResponses - && responsePayload instanceof String - && !StringUtils.hasText((String) responsePayload))) { + && responsePayload instanceof String string + && !StringUtils.hasText(string))) { return responsePayload; } @@ -247,9 +248,9 @@ public abstract class AbstractWebServiceOutboundGateway extends AbstractReplyPro public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException { Object payload = this.requestMessage.getPayload(); doWithMessageInternal(message, payload); - if (message instanceof SoapMessage) { + if (message instanceof SoapMessage soapMessage) { AbstractWebServiceOutboundGateway.this.headerMapper - .fromHeadersToRequest(this.requestMessage.getHeaders(), (SoapMessage) message); + .fromHeadersToRequest(this.requestMessage.getHeaders(), soapMessage); } if (this.reqCallback != null) { this.reqCallback.doWithMessage(message); @@ -270,9 +271,9 @@ public abstract class AbstractWebServiceOutboundGateway extends AbstractReplyPro Object resultObject = this.doExtractData(message); - if (resultObject != null && message instanceof SoapMessage) { + if (resultObject != null && message instanceof SoapMessage soapMessage) { Map mappedMessageHeaders = - AbstractWebServiceOutboundGateway.this.headerMapper.toHeadersFromReply((SoapMessage) message); + AbstractWebServiceOutboundGateway.this.headerMapper.toHeadersFromReply(soapMessage); return getMessageBuilderFactory() .withPayload(resultObject) .copyHeaders(mappedMessageHeaders) diff --git a/spring-integration-ws/src/main/java/org/springframework/integration/ws/config/WsIntegrationConfigurationInitializer.java b/spring-integration-ws/src/main/java/org/springframework/integration/ws/config/WsIntegrationConfigurationInitializer.java index 8a2efac481..03889c7be9 100644 --- a/spring-integration-ws/src/main/java/org/springframework/integration/ws/config/WsIntegrationConfigurationInitializer.java +++ b/spring-integration-ws/src/main/java/org/springframework/integration/ws/config/WsIntegrationConfigurationInitializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 the original author or authors. + * Copyright 2016-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. @@ -39,6 +39,7 @@ import org.springframework.ws.server.endpoint.adapter.MessageEndpointAdapter; * * @author Artem Bilan * @author Chris Bono + * @author Ngoc Nhan * * @since 4.3 * @@ -53,12 +54,12 @@ public class WsIntegrationConfigurationInitializer implements IntegrationConfigu @Override public void initialize(ConfigurableListableBeanFactory beanFactory) throws BeansException { - if (beanFactory instanceof BeanDefinitionRegistry) { + if (beanFactory instanceof BeanDefinitionRegistry beanDefinitionRegistry) { if (beanFactory.getBeanNamesForType(EndpointAdapter.class, false, false).length > 0) { BeanDefinitionBuilder requestMappingBuilder = BeanDefinitionBuilder.genericBeanDefinition(MessageEndpointAdapter.class) .setRole(BeanDefinition.ROLE_INFRASTRUCTURE); - ((BeanDefinitionRegistry) beanFactory).registerBeanDefinition(MESSAGE_ENDPOINT_ADAPTER_BEAN_NAME, + beanDefinitionRegistry.registerBeanDefinition(MESSAGE_ENDPOINT_ADAPTER_BEAN_NAME, requestMappingBuilder.getBeanDefinition()); } } diff --git a/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XPathExpressionParser.java b/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XPathExpressionParser.java index ff715aeb89..cb799c92bb 100644 --- a/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XPathExpressionParser.java +++ b/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XPathExpressionParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-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. @@ -37,6 +37,7 @@ import org.springframework.xml.xpath.XPathExpressionFactory; * @author Jonas Partner * @author Soby Chacko * @author Artem Bilan + * @author Ngoc Nhan */ public class XPathExpressionParser extends AbstractSingleBeanDefinitionParser { @@ -94,7 +95,7 @@ public class XPathExpressionParser extends AbstractSingleBeanDefinitionParser { } if (prefixProvided) { - Map namespaceMap = new HashMap(1); + Map namespaceMap = new HashMap<>(1); namespaceMap.put(nsPrefix, nsUri); builder.addConstructorArgValue(namespaceMap); } diff --git a/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XsltPayloadTransformerParser.java b/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XsltPayloadTransformerParser.java index 80a405045e..bcdc4e4cd1 100644 --- a/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XsltPayloadTransformerParser.java +++ b/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XsltPayloadTransformerParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-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. @@ -39,6 +39,7 @@ import org.springframework.util.xml.DomUtils; * @author Mike Bazos * @author liujiong * @author Gary Russell + * @author Ngoc Nhan */ public class XsltPayloadTransformerParser extends AbstractTransformerParser { @@ -72,7 +73,7 @@ public class XsltPayloadTransformerParser extends AbstractTransformerParser { } List xslParameterElements = DomUtils.getChildElementsByTagName(element, "xslt-param"); if (!CollectionUtils.isEmpty(xslParameterElements)) { - Map xslParameterMappings = new ManagedMap(); + Map xslParameterMappings = new ManagedMap<>(); for (Element xslParameterElement : xslParameterElements) { String name = xslParameterElement.getAttribute("name"); String expression = xslParameterElement.getAttribute("expression"); diff --git a/spring-integration-xml/src/main/java/org/springframework/integration/xml/selector/AbstractXPathMessageSelector.java b/spring-integration-xml/src/main/java/org/springframework/integration/xml/selector/AbstractXPathMessageSelector.java index 990f6a8f0a..8ddb2eba6b 100644 --- a/spring-integration-xml/src/main/java/org/springframework/integration/xml/selector/AbstractXPathMessageSelector.java +++ b/spring-integration-xml/src/main/java/org/springframework/integration/xml/selector/AbstractXPathMessageSelector.java @@ -29,6 +29,7 @@ import org.springframework.xml.xpath.XPathExpressionFactory; * Base class for XPath {@link MessageSelector} implementations. * * @author Jonas Partner + * @author Ngoc Nhan */ public abstract class AbstractXPathMessageSelector implements MessageSelector { @@ -49,7 +50,7 @@ public abstract class AbstractXPathMessageSelector implements MessageSelector { * @param namespace namespace URI */ public AbstractXPathMessageSelector(String xPathExpression, String prefix, String namespace) { - Map namespaces = new HashMap(); + Map namespaces = new HashMap<>(); namespaces.put(prefix, namespace); this.xPathExpresion = XPathExpressionFactory.createXPathExpression(xPathExpression, namespaces); } diff --git a/spring-integration-xml/src/main/java/org/springframework/integration/xml/splitter/XPathMessageSplitter.java b/spring-integration-xml/src/main/java/org/springframework/integration/xml/splitter/XPathMessageSplitter.java index 13eb365388..c0d86b163a 100644 --- a/spring-integration-xml/src/main/java/org/springframework/integration/xml/splitter/XPathMessageSplitter.java +++ b/spring-integration-xml/src/main/java/org/springframework/integration/xml/splitter/XPathMessageSplitter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-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. @@ -70,6 +70,7 @@ import org.springframework.xml.xpath.XPathExpressionFactory; * @author Artem Bilan * @author Gary Russell * @author Christian Tzolov + * @author Ngoc Nhan */ public class XPathMessageSplitter extends AbstractMessageSplitter { @@ -216,8 +217,8 @@ public class XPathMessageSplitter extends AbstractMessageSplitter { try { Object payload = message.getPayload(); Object result; - if (payload instanceof Node) { - result = splitNode((Node) payload); + if (payload instanceof Node node) { + result = splitNode(node); } else { Document document = this.xmlPayloadConverter.convertToDocument(payload); @@ -239,12 +240,12 @@ public class XPathMessageSplitter extends AbstractMessageSplitter { protected int obtainSizeIfPossible(Iterator iterator) { Iterator theIterator = iterator; - if (iterator instanceof TransformFunctionIterator) { - theIterator = ((TransformFunctionIterator) iterator).delegate; + if (iterator instanceof TransformFunctionIterator transformFunctionIterator) { + theIterator = transformFunctionIterator.delegate; } - if (theIterator instanceof NodeListIterator) { - return ((NodeListIterator) theIterator).nodeList.getLength(); + if (theIterator instanceof NodeListIterator nodeListIterator) { + return nodeListIterator.nodeList.getLength(); } return 0; diff --git a/spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/UnmarshallingTransformer.java b/spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/UnmarshallingTransformer.java index 4cded9da25..f20e11f58f 100644 --- a/spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/UnmarshallingTransformer.java +++ b/spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/UnmarshallingTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-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. @@ -55,6 +55,7 @@ import org.springframework.xml.transform.StringSource; * @author Jonas Partner * @author Artem Bilan * @author Gary Russell + * @author Ngoc Nhan */ public class UnmarshallingTransformer extends AbstractPayloadTransformer { @@ -113,22 +114,21 @@ public class UnmarshallingTransformer extends AbstractPayloadTransformer) { return (T) expression.evaluateAsObject(node, (NodeMapper) resultType); } - else if (resultType instanceof String && RESULT_TYPES.contains(resultType)) { - String resType = (String) resultType; + else if (resultType instanceof String resType && RESULT_TYPES.contains(resultType)) { if (DOCUMENT_LIST.equals(resType)) { List nodeList = (List) XPathEvaluationType.NODE_LIST_RESULT.evaluateXPath(expression, node); diff --git a/spring-integration-zip/src/main/java/org/springframework/integration/zip/transformer/UnZipTransformer.java b/spring-integration-zip/src/main/java/org/springframework/integration/zip/transformer/UnZipTransformer.java index 8e576c380f..b073f07712 100644 --- a/spring-integration-zip/src/main/java/org/springframework/integration/zip/transformer/UnZipTransformer.java +++ b/spring-integration-zip/src/main/java/org/springframework/integration/zip/transformer/UnZipTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2023 the original author or authors. + * Copyright 2015-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. @@ -42,6 +42,7 @@ import org.springframework.messaging.MessagingException; * @author Gunnar Hillert * @author Artem Bilan * @author Ingo Dueppe + * @author Ngoc Nhan * * @since 6.1 */ @@ -86,11 +87,11 @@ public class UnZipTransformer extends AbstractZipTransformer { inputStream = new FileInputStream(filePayload); } - else if (payload instanceof InputStream) { - inputStream = (InputStream) payload; + else if (payload instanceof InputStream castInputStream) { + inputStream = castInputStream; } - else if (payload instanceof byte[]) { - inputStream = new ByteArrayInputStream((byte[]) payload); + else if (payload instanceof byte[] bytes) { + inputStream = new ByteArrayInputStream(bytes); } else { throw new IllegalArgumentException("Unsupported payload type '" + payload.getClass().getSimpleName()