Skip to content

Commit 0f44e2b

Browse files
committed
Use pattern matching variables where appropriate
1 parent a2be6ba commit 0f44e2b

File tree

23 files changed

+52
-67
lines changed

23 files changed

+52
-67
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/Entity.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2022 the original author or authors.
2+
* Copyright 2006-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,6 +27,7 @@
2727
*
2828
* @author Lucas Ward
2929
* @author Dave Syer
30+
* @author Mahmoud Ben Hassine
3031
*
3132
*/
3233
@SuppressWarnings("serial")
@@ -122,10 +123,9 @@ public boolean equals(Object other) {
122123
if (other == null) {
123124
return false;
124125
}
125-
if (!(other instanceof Entity)) {
126+
if (!(other instanceof Entity entity)) {
126127
return false;
127128
}
128-
Entity entity = (Entity) other;
129129
if (id == null || entity.getId() == null) {
130130
return false;
131131
}

spring-batch-core/src/main/java/org/springframework/batch/core/JobParameter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,14 @@ public Class<T> getType() {
9090

9191
@Override
9292
public boolean equals(Object obj) {
93-
if (!(obj instanceof JobParameter)) {
93+
if (!(obj instanceof JobParameter rhs)) {
9494
return false;
9595
}
9696

9797
if (this == obj) {
9898
return true;
9999
}
100100

101-
JobParameter rhs = (JobParameter) obj;
102101
return type == rhs.type && value.equals(rhs.value);
103102
}
104103

spring-batch-core/src/main/java/org/springframework/batch/core/StepContribution.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2022 the original author or authors.
2+
* Copyright 2006-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -212,10 +212,9 @@ public String toString() {
212212
*/
213213
@Override
214214
public boolean equals(Object obj) {
215-
if (!(obj instanceof StepContribution)) {
215+
if (!(obj instanceof StepContribution other)) {
216216
return false;
217217
}
218-
StepContribution other = (StepContribution) obj;
219218
return toString().equals(other.toString());
220219
}
221220

spring-batch-core/src/main/java/org/springframework/batch/core/StepExecution.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2022 the original author or authors.
2+
* Copyright 2006-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -495,10 +495,9 @@ public void addFailureException(Throwable throwable) {
495495
public boolean equals(Object obj) {
496496

497497
Object jobExecutionId = getJobExecutionId();
498-
if (jobExecutionId == null || !(obj instanceof StepExecution) || getId() == null) {
498+
if (jobExecutionId == null || !(obj instanceof StepExecution other) || getId() == null) {
499499
return super.equals(obj);
500500
}
501-
StepExecution other = (StepExecution) obj;
502501

503502
return stepName.equals(other.getStepName()) && (jobExecutionId.equals(other.getJobExecutionId()))
504503
&& getId().equals(other.getId());

spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/AutomaticJobRegistrarBeanPostProcessor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 the original author or authors.
2+
* Copyright 2022-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,8 +42,7 @@ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
4242

4343
@Override
4444
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
45-
if (bean instanceof AutomaticJobRegistrar) {
46-
AutomaticJobRegistrar automaticJobRegistrar = (AutomaticJobRegistrar) bean;
45+
if (bean instanceof AutomaticJobRegistrar automaticJobRegistrar) {
4746
automaticJobRegistrar.setJobLoader(new DefaultJobLoader(this.beanFactory.getBean(JobRegistry.class)));
4847
for (ApplicationContextFactory factory : this.beanFactory.getBeansOfType(ApplicationContextFactory.class)
4948
.values()) {

spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/JobRegistryBeanPostProcessor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2022 the original author or authors.
2+
* Copyright 2006-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,6 +42,7 @@
4242
* {@link Job} to launch.
4343
*
4444
* @author Dave Syer
45+
* @author Mahmoud Ben Hassine
4546
*
4647
*/
4748
public class JobRegistryBeanPostProcessor
@@ -126,8 +127,7 @@ public void destroy() throws Exception {
126127
*/
127128
@Override
128129
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
129-
if (bean instanceof Job) {
130-
Job job = (Job) bean;
130+
if (bean instanceof Job job) {
131131
try {
132132
String groupName = this.groupName;
133133
if (beanFactory != null && beanFactory.containsBean(beanName)) {

spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/AbstractFlowParser.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,8 @@ protected void doParse(Element element, ParserContext parserContext, BeanDefinit
172172
NodeList children = element.getChildNodes();
173173
for (int i = 0; i < children.getLength(); i++) {
174174
Node node = children.item(i);
175-
if (node instanceof Element) {
175+
if (node instanceof Element child) {
176176
String nodeName = node.getLocalName();
177-
Element child = (Element) node;
178177
switch (nodeName) {
179178
case STEP_ELE -> {
180179
stateTransitions.addAll(stepParser.parse(child, parserContext, jobFactoryRef));

spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/AbstractStepParser.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2022 the original author or authors.
2+
* Copyright 2006-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,6 +42,7 @@
4242
* @author Dave Syer
4343
* @author Thomas Risberg
4444
* @author Josh Long
45+
* @author Mahmoud Ben Hassine
4546
* @see JobParser
4647
* @since 2.0
4748
*/
@@ -109,8 +110,7 @@ protected AbstractBeanDefinition parseStep(Element stepElement, ParserContext pa
109110
for (int i = 0; i < children.getLength(); i++) {
110111
Node nd = children.item(i);
111112

112-
if (nd instanceof Element) {
113-
Element nestedElement = (Element) nd;
113+
if (nd instanceof Element nestedElement) {
114114
String name = nestedElement.getLocalName();
115115

116116
if (TASKLET_ELE.equals(name)) {

spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/StepParserStepFactoryBean.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2022 the original author or authors.
2+
* Copyright 2006-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -800,12 +800,10 @@ public void setListeners(Object[] listeners) {
800800
SkipListener<I, O> skipListener = (SkipListener<I, O>) listener;
801801
skipListeners.add(skipListener);
802802
}
803-
if (listener instanceof StepExecutionListener) {
804-
StepExecutionListener stepExecutionListener = (StepExecutionListener) listener;
803+
if (listener instanceof StepExecutionListener stepExecutionListener) {
805804
stepExecutionListeners.add(stepExecutionListener);
806805
}
807-
if (listener instanceof ChunkListener) {
808-
ChunkListener chunkListener = (ChunkListener) listener;
806+
if (listener instanceof ChunkListener chunkListener) {
809807
chunkListeners.add(chunkListener);
810808
}
811809
if (listener instanceof ItemReadListener) {

spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/FlowExecutionStatus.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2013 the original author or authors.
2+
* Copyright 2006-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
2020
*
2121
* @author Dan Garrette
2222
* @author Dave Syer
23+
* @author Mahmoud Ben Hassine
2324
* @since 2.0
2425
*/
2526
public class FlowExecutionStatus implements Comparable<FlowExecutionStatus> {
@@ -127,10 +128,9 @@ public boolean equals(Object object) {
127128
if (object == this) {
128129
return true;
129130
}
130-
if (!(object instanceof FlowExecutionStatus)) {
131+
if (!(object instanceof FlowExecutionStatus other)) {
131132
return false;
132133
}
133-
FlowExecutionStatus other = (FlowExecutionStatus) object;
134134
return name.equals(other.name);
135135
}
136136

0 commit comments

Comments
 (0)