diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/Entity.java b/spring-batch-core/src/main/java/org/springframework/batch/core/Entity.java index 0a37448f7..a662e716d 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/Entity.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/Entity.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2022 the original author or authors. + * Copyright 2006-2023 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.util.ClassUtils; * * @author Lucas Ward * @author Dave Syer + * @author Mahmoud Ben Hassine * */ @SuppressWarnings("serial") @@ -122,10 +123,9 @@ public class Entity implements Serializable { if (other == null) { return false; } - if (!(other instanceof Entity)) { + if (!(other instanceof Entity entity)) { return false; } - Entity entity = (Entity) other; if (id == null || entity.getId() == null) { return false; } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/JobParameter.java b/spring-batch-core/src/main/java/org/springframework/batch/core/JobParameter.java index 5b1811e93..fde86b820 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/JobParameter.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/JobParameter.java @@ -90,7 +90,7 @@ public class JobParameter implements Serializable { @Override public boolean equals(Object obj) { - if (!(obj instanceof JobParameter)) { + if (!(obj instanceof JobParameter rhs)) { return false; } @@ -98,7 +98,6 @@ public class JobParameter implements Serializable { return true; } - JobParameter rhs = (JobParameter) obj; return type == rhs.type && value.equals(rhs.value); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/StepContribution.java b/spring-batch-core/src/main/java/org/springframework/batch/core/StepContribution.java index e879fed98..7aecf8314 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/StepContribution.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/StepContribution.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2022 the original author or authors. + * Copyright 2006-2023 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. @@ -212,10 +212,9 @@ public class StepContribution implements Serializable { */ @Override public boolean equals(Object obj) { - if (!(obj instanceof StepContribution)) { + if (!(obj instanceof StepContribution other)) { return false; } - StepContribution other = (StepContribution) obj; return toString().equals(other.toString()); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/StepExecution.java b/spring-batch-core/src/main/java/org/springframework/batch/core/StepExecution.java index 89498ad82..7c7039f97 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/StepExecution.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/StepExecution.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2022 the original author or authors. + * Copyright 2006-2023 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. @@ -495,10 +495,9 @@ public class StepExecution extends Entity { public boolean equals(Object obj) { Object jobExecutionId = getJobExecutionId(); - if (jobExecutionId == null || !(obj instanceof StepExecution) || getId() == null) { + if (jobExecutionId == null || !(obj instanceof StepExecution other) || getId() == null) { return super.equals(obj); } - StepExecution other = (StepExecution) obj; return stepName.equals(other.getStepName()) && (jobExecutionId.equals(other.getJobExecutionId())) && getId().equals(other.getId()); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/AutomaticJobRegistrarBeanPostProcessor.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/AutomaticJobRegistrarBeanPostProcessor.java index ba8cfbad7..c8db9b731 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/AutomaticJobRegistrarBeanPostProcessor.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/AutomaticJobRegistrarBeanPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-2023 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,8 +42,7 @@ class AutomaticJobRegistrarBeanPostProcessor implements BeanFactoryPostProcessor @Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { - if (bean instanceof AutomaticJobRegistrar) { - AutomaticJobRegistrar automaticJobRegistrar = (AutomaticJobRegistrar) bean; + if (bean instanceof AutomaticJobRegistrar automaticJobRegistrar) { automaticJobRegistrar.setJobLoader(new DefaultJobLoader(this.beanFactory.getBean(JobRegistry.class))); for (ApplicationContextFactory factory : this.beanFactory.getBeansOfType(ApplicationContextFactory.class) .values()) { diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/JobRegistryBeanPostProcessor.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/JobRegistryBeanPostProcessor.java index d62a8c124..55a87483b 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/JobRegistryBeanPostProcessor.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/JobRegistryBeanPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2022 the original author or authors. + * Copyright 2006-2023 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.Assert; * {@link Job} to launch. * * @author Dave Syer + * @author Mahmoud Ben Hassine * */ public class JobRegistryBeanPostProcessor @@ -126,8 +127,7 @@ public class JobRegistryBeanPostProcessor */ @Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { - if (bean instanceof Job) { - Job job = (Job) bean; + if (bean instanceof Job job) { try { String groupName = this.groupName; if (beanFactory != null && beanFactory.containsBean(beanName)) { diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/AbstractFlowParser.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/AbstractFlowParser.java index fde40d5fc..7ea639469 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/AbstractFlowParser.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/AbstractFlowParser.java @@ -172,9 +172,8 @@ public abstract class AbstractFlowParser extends AbstractSingleBeanDefinitionPar NodeList children = element.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node node = children.item(i); - if (node instanceof Element) { + if (node instanceof Element child) { String nodeName = node.getLocalName(); - Element child = (Element) node; switch (nodeName) { case STEP_ELE -> { stateTransitions.addAll(stepParser.parse(child, parserContext, jobFactoryRef)); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/AbstractStepParser.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/AbstractStepParser.java index c00c43a09..168bfa5f0 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/AbstractStepParser.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/AbstractStepParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2022 the original author or authors. + * Copyright 2006-2023 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 Dave Syer * @author Thomas Risberg * @author Josh Long + * @author Mahmoud Ben Hassine * @see JobParser * @since 2.0 */ @@ -109,8 +110,7 @@ public abstract class AbstractStepParser { for (int i = 0; i < children.getLength(); i++) { Node nd = children.item(i); - if (nd instanceof Element) { - Element nestedElement = (Element) nd; + if (nd instanceof Element nestedElement) { String name = nestedElement.getLocalName(); if (TASKLET_ELE.equals(name)) { diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/StepParserStepFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/StepParserStepFactoryBean.java index a41fad9dc..f5a26c706 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/StepParserStepFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/StepParserStepFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2022 the original author or authors. + * Copyright 2006-2023 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. @@ -800,12 +800,10 @@ public class StepParserStepFactoryBean implements FactoryBean, BeanN SkipListener skipListener = (SkipListener) listener; skipListeners.add(skipListener); } - if (listener instanceof StepExecutionListener) { - StepExecutionListener stepExecutionListener = (StepExecutionListener) listener; + if (listener instanceof StepExecutionListener stepExecutionListener) { stepExecutionListeners.add(stepExecutionListener); } - if (listener instanceof ChunkListener) { - ChunkListener chunkListener = (ChunkListener) listener; + if (listener instanceof ChunkListener chunkListener) { chunkListeners.add(chunkListener); } if (listener instanceof ItemReadListener) { diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/FlowExecutionStatus.java b/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/FlowExecutionStatus.java index caa8aa7d1..bb9cdc63b 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/FlowExecutionStatus.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/FlowExecutionStatus.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2013 the original author or authors. + * Copyright 2006-2023 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. @@ -20,6 +20,7 @@ package org.springframework.batch.core.job.flow; * * @author Dan Garrette * @author Dave Syer + * @author Mahmoud Ben Hassine * @since 2.0 */ public class FlowExecutionStatus implements Comparable { @@ -127,10 +128,9 @@ public class FlowExecutionStatus implements Comparable { if (object == this) { return true; } - if (!(object instanceof FlowExecutionStatus)) { + if (!(object instanceof FlowExecutionStatus other)) { return false; } - FlowExecutionStatus other = (FlowExecutionStatus) object; return name.equals(other.name); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/FlowJob.java b/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/FlowJob.java index 314c8a02e..eb565f25a 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/FlowJob.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/FlowJob.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2022 the original author or authors. + * Copyright 2006-2023 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. @@ -95,8 +95,7 @@ public class FlowJob extends AbstractJob { private void findSteps(Flow flow, Map map) { for (State state : flow.getStates()) { - if (state instanceof StepLocator) { - StepLocator locator = (StepLocator) state; + if (state instanceof StepLocator locator) { for (String name : locator.getStepNames()) { map.put(name, locator.getStep(name)); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/MethodInvokerMethodInterceptor.java b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/MethodInvokerMethodInterceptor.java index 180f8dae9..b6cd083e9 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/MethodInvokerMethodInterceptor.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/MethodInvokerMethodInterceptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2023 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.batch.support.MethodInvoker; * which returns ExitStatus. * * @author Lucas Ward + * @author Mahmoud Ben Hassine * @since 2.0 * @see MethodInvoker */ @@ -86,10 +87,9 @@ public class MethodInvokerMethodInterceptor implements MethodInterceptor { */ @Override public boolean equals(Object obj) { - if (!(obj instanceof MethodInvokerMethodInterceptor)) { + if (!(obj instanceof MethodInvokerMethodInterceptor other)) { return false; } - MethodInvokerMethodInterceptor other = (MethodInvokerMethodInterceptor) obj; return invokerMap.equals(other.invokerMap); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/scope/BatchScopeSupport.java b/spring-batch-core/src/main/java/org/springframework/batch/core/scope/BatchScopeSupport.java index 9c7223a2b..1b53891ff 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/scope/BatchScopeSupport.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/scope/BatchScopeSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2023 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.StringValueResolver; * ScopeSupport. * * @author Michael Minella + * @author Mahmoud Ben Hassine * @since 3.0 */ public abstract class BatchScopeSupport implements Scope, BeanFactoryPostProcessor, Ordered { @@ -194,8 +195,7 @@ public abstract class BatchScopeSupport implements Scope, BeanFactoryPostProcess definition = (BeanDefinition) value; beanName = BeanDefinitionReaderUtils.generateBeanName(definition, registry); } - else if (value instanceof BeanDefinitionHolder) { - BeanDefinitionHolder holder = (BeanDefinitionHolder) value; + else if (value instanceof BeanDefinitionHolder holder) { definition = holder.getBeanDefinition(); beanName = holder.getBeanName(); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/scope/context/JobContext.java b/spring-batch-core/src/main/java/org/springframework/batch/core/scope/context/JobContext.java index 913fe2b54..61607825c 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/scope/context/JobContext.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/scope/context/JobContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2022 the original author or authors. + * Copyright 2006-2023 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. @@ -201,13 +201,12 @@ public class JobContext extends SynchronizedAttributeAccessor { */ @Override public boolean equals(Object other) { - if (!(other instanceof JobContext)) { + if (!(other instanceof JobContext context)) { return false; } if (other == this) { return true; } - JobContext context = (JobContext) other; if (context.jobExecution == jobExecution) { return true; } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/scope/context/StepContext.java b/spring-batch-core/src/main/java/org/springframework/batch/core/scope/context/StepContext.java index 71f284923..0e518c3c5 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/scope/context/StepContext.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/scope/context/StepContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2022 the original author or authors. + * Copyright 2006-2023 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. @@ -243,13 +243,12 @@ public class StepContext extends SynchronizedAttributeAccessor { */ @Override public boolean equals(Object other) { - if (!(other instanceof StepContext)) { + if (!(other instanceof StepContext context)) { return false; } if (other == this) { return true; } - StepContext context = (StepContext) other; if (context.stepExecution == stepExecution) { return true; } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/Chunk.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/Chunk.java index fbbe2b43f..4cdfa1c7e 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/Chunk.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/Chunk.java @@ -216,10 +216,9 @@ public class Chunk implements Iterable, Serializable { if (obj == this) { return true; } - if (!(obj instanceof Chunk)) { + if (!(obj instanceof Chunk other)) { return false; } - Chunk other = (Chunk) obj; return Objects.equals(this.items, other.items) && Objects.equals(this.skips, other.skips) && Objects.equals(this.errors, other.errors) && Objects.equals(this.userData, other.userData) && this.end == other.end && this.busy == other.busy; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DefaultFieldSet.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DefaultFieldSet.java index dc161d691..c91d2a63e 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DefaultFieldSet.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DefaultFieldSet.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2023 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.StringUtils; * * @author Rob Harrop * @author Dave Syer + * @author Mahmoud Ben Hassine */ public class DefaultFieldSet implements FieldSet { @@ -669,8 +670,7 @@ public class DefaultFieldSet implements FieldSet { */ @Override public boolean equals(Object object) { - if (object instanceof DefaultFieldSet) { - DefaultFieldSet fs = (DefaultFieldSet) object; + if (object instanceof DefaultFieldSet fs) { if (this.tokens == null) { return fs.tokens == null; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsItemReader.java index b9591dbf1..60d5083b3 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsItemReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2022 the original author or authors. + * Copyright 2006-2023 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. @@ -53,8 +53,7 @@ public class JmsItemReader implements ItemReader, InitializingBean { */ public void setJmsTemplate(JmsOperations jmsTemplate) { this.jmsTemplate = jmsTemplate; - if (jmsTemplate instanceof JmsTemplate) { - JmsTemplate template = (JmsTemplate) jmsTemplate; + if (jmsTemplate instanceof JmsTemplate template) { Assert.isTrue(template.getReceiveTimeout() != JmsTemplate.RECEIVE_TIMEOUT_INDEFINITE_WAIT, "JmsTemplate must have a receive timeout!"); Assert.isTrue(template.getDefaultDestination() != null || template.getDefaultDestinationName() != null, diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsItemWriter.java index 2889120ad..f5576ae23 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsItemWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2022 the original author or authors. + * Copyright 2006-2023 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. @@ -49,8 +49,7 @@ public class JmsItemWriter implements ItemWriter { */ public void setJmsTemplate(JmsOperations jmsTemplate) { this.jmsTemplate = jmsTemplate; - if (jmsTemplate instanceof JmsTemplate) { - JmsTemplate template = (JmsTemplate) jmsTemplate; + if (jmsTemplate instanceof JmsTemplate template) { Assert.isTrue(template.getDefaultDestination() != null || template.getDefaultDestinationName() != null, "JmsTemplate must have a defaultDestination or defaultDestinationName!"); } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/DefaultPropertyEditorRegistrar.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/DefaultPropertyEditorRegistrar.java index 0b9a0f645..99871c07a 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/DefaultPropertyEditorRegistrar.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/DefaultPropertyEditorRegistrar.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2023 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.ClassUtils; * in a standalone application with no threads). * * @author Dave Syer + * @author Mahmoud Ben Hassine * */ public class DefaultPropertyEditorRegistrar implements PropertyEditorRegistrar { @@ -67,8 +68,7 @@ public class DefaultPropertyEditorRegistrar implements PropertyEditorRegistrar { if (key instanceof Class) { requiredType = (Class) key; } - else if (key instanceof String) { - String className = (String) key; + else if (key instanceof String className) { requiredType = ClassUtils.resolveClassName(className, getClass().getClassLoader()); } else { diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/SimpleMethodInvoker.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/SimpleMethodInvoker.java index 1903174e6..04182354b 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/SimpleMethodInvoker.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/support/SimpleMethodInvoker.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2023 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.ClassUtils; * then an exception is thrown. * * @author Lucas Ward + * @author Mahmoud Ben Hassine * @since 2.0 */ public class SimpleMethodInvoker implements MethodInvoker { @@ -133,14 +134,13 @@ public class SimpleMethodInvoker implements MethodInvoker { @Override public boolean equals(Object obj) { - if (!(obj instanceof SimpleMethodInvoker)) { + if (!(obj instanceof SimpleMethodInvoker rhs)) { return false; } if (obj == this) { return true; } - SimpleMethodInvoker rhs = (SimpleMethodInvoker) obj; return (rhs.method.equals(this.method)) && (rhs.object.equals(this.object)); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcBatchItemWriterNamedParameterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcBatchItemWriterNamedParameterTests.java index 1b628d673..ff8930082 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcBatchItemWriterNamedParameterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcBatchItemWriterNamedParameterTests.java @@ -204,10 +204,9 @@ public class JdbcBatchItemWriterNamedParameterTests { @Override public boolean matches(Object actual) { - if (!(actual instanceof SqlParameterSource[])) { + if (!(actual instanceof SqlParameterSource[] actualArray)) { return false; } - SqlParameterSource[] actualArray = (SqlParameterSource[]) actual; if (expected.length != actualArray.length) { return false; } diff --git a/spring-batch-infrastructure/src/test/java/test/jdbc/datasource/DerbyShutdownBean.java b/spring-batch-infrastructure/src/test/java/test/jdbc/datasource/DerbyShutdownBean.java index 11393c99d..ce88d402b 100644 --- a/spring-batch-infrastructure/src/test/java/test/jdbc/datasource/DerbyShutdownBean.java +++ b/spring-batch-infrastructure/src/test/java/test/jdbc/datasource/DerbyShutdownBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2012 the original author or authors. + * Copyright 2010-2023 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,8 +39,7 @@ public class DerbyShutdownBean implements DisposableBean { @Override public void destroy() throws Exception { logger.info("Attempting Derby database shut down on: " + dataSource); - if (!isShutdown && dataSource != null && dataSource instanceof EmbeddedDataSource) { - EmbeddedDataSource ds = (EmbeddedDataSource) dataSource; + if (!isShutdown && dataSource != null && dataSource instanceof EmbeddedDataSource ds) { try { ds.setShutdownDatabase("shutdown"); ds.getConnection();