Skip to content

Commit 7babb34

Browse files
committed
Replace for loops with enhanced for loop where appropriate
1 parent 8c5456c commit 7babb34

File tree

10 files changed

+44
-44
lines changed

10 files changed

+44
-44
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.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.
@@ -231,8 +231,8 @@ public JobParametersIncrementer getJobParametersIncrementer() {
231231
* @param listeners the listeners to set.
232232
*/
233233
public void setJobExecutionListeners(JobExecutionListener[] listeners) {
234-
for (int i = 0; i < listeners.length; i++) {
235-
this.listener.register(listeners[i]);
234+
for (JobExecutionListener jobExecutionListener : listeners) {
235+
this.listener.register(jobExecutionListener);
236236
}
237237
}
238238

spring-batch-core/src/main/java/org/springframework/batch/core/step/AbstractStep.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.
@@ -379,8 +379,8 @@ public void registerStepExecutionListener(StepExecutionListener listener) {
379379
* @param listeners an array of listener objects of known types.
380380
*/
381381
public void setStepExecutionListeners(StepExecutionListener[] listeners) {
382-
for (int i = 0; i < listeners.length; i++) {
383-
registerStepExecutionListener(listeners[i]);
382+
for (StepExecutionListener listener : listeners) {
383+
registerStepExecutionListener(listener);
384384
}
385385
}
386386

spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/TaskletStep.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2021 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.
@@ -167,8 +167,8 @@ public void registerChunkListener(ChunkListener listener) {
167167
* @param listeners an array of listener objects of known types.
168168
*/
169169
public void setChunkListeners(ChunkListener[] listeners) {
170-
for (int i = 0; i < listeners.length; i++) {
171-
registerChunkListener(listeners[i]);
170+
for (ChunkListener listener : listeners) {
171+
registerChunkListener(listener);
172172
}
173173
}
174174

@@ -182,8 +182,8 @@ public void setChunkListeners(ChunkListener[] listeners) {
182182
* @param streams an array of {@link ItemStream} objects.
183183
*/
184184
public void setStreams(ItemStream[] streams) {
185-
for (int i = 0; i < streams.length; i++) {
186-
registerStream(streams[i]);
185+
for (ItemStream itemStream : streams) {
186+
registerStream(itemStream);
187187
}
188188
}
189189

spring-batch-core/src/test/java/test/jdbc/datasource/DataSourceInitializer.java

Lines changed: 4 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.
@@ -83,8 +83,7 @@ public void afterPropertiesSet() throws Exception {
8383
private void initialize() {
8484
if (!initialized) {
8585
if (initScripts != null) {
86-
for (int i = 0; i < initScripts.length; i++) {
87-
Resource script = initScripts[i];
86+
for (Resource script : initScripts) {
8887
doExecuteScript(script);
8988
}
9089
}
@@ -112,8 +111,8 @@ public Void doInTransaction(TransactionStatus status) {
112111
catch (IOException e) {
113112
throw new BeanInitializationException("Cannot load script from [" + scriptResource + "]", e);
114113
}
115-
for (int i = 0; i < scripts.length; i++) {
116-
String script = scripts[i].trim();
114+
for (String s : scripts) {
115+
String script = s.trim();
117116
if (StringUtils.hasText(script)) {
118117
try {
119118
jdbcTemplate.execute(script);

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/PropertyMatches.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2021 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.
@@ -35,6 +35,7 @@
3535
* @author Arjen Poutsma
3636
* @author Juergen Hoeller
3737
* @author Dave Syer
38+
* @author Mahmoud Ben Hassine
3839
* @since 1.0
3940
* @see #forProperty(String, Class)
4041
*/
@@ -128,9 +129,9 @@ else if (i == this.possibleMatches.length - 2) {
128129
*/
129130
private String[] calculateMatches(PropertyDescriptor[] propertyDescriptors, int maxDistance) {
130131
List<String> candidates = new ArrayList<>();
131-
for (int i = 0; i < propertyDescriptors.length; i++) {
132-
if (propertyDescriptors[i].getWriteMethod() != null) {
133-
String possibleAlternative = propertyDescriptors[i].getName();
132+
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
133+
if (propertyDescriptor.getWriteMethod() != null) {
134+
String possibleAlternative = propertyDescriptor.getName();
134135
int distance = calculateStringDistance(this.propertyName, possibleAlternative);
135136
if (distance <= maxDistance) {
136137
candidates.add(possibleAlternative);

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/FixedLengthTokenizer.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2014 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.
@@ -29,6 +29,7 @@
2929
* @author Dave Syer
3030
* @author Lucas Ward
3131
* @author Michael Minella
32+
* @author Mahmoud Ben Hassine
3233
*/
3334
public class FixedLengthTokenizer extends AbstractLineTokenizer {
3435

@@ -67,13 +68,13 @@ private void calculateMaxRange(Range[] ranges) {
6768
open = false;
6869
maxRange = ranges[0].getMin();
6970

70-
for (int i = 0; i < ranges.length; i++) {
71+
for (Range range : ranges) {
7172
int upperBound;
72-
if (ranges[i].hasMaxValue()) {
73-
upperBound = ranges[i].getMax();
73+
if (range.hasMaxValue()) {
74+
upperBound = range.getMax();
7475
}
7576
else {
76-
upperBound = ranges[i].getMin();
77+
upperBound = range.getMin();
7778
if (upperBound > maxRange) {
7879
open = true;
7980
}
@@ -110,10 +111,10 @@ protected List<String> doTokenize(String line) {
110111
line);
111112
}
112113

113-
for (int i = 0; i < ranges.length; i++) {
114+
for (Range range : ranges) {
114115

115-
int startPos = ranges[i].getMin() - 1;
116-
int endPos = ranges[i].getMax();
116+
int startPos = range.getMin() - 1;
117+
int endPos = range.getMax();
117118

118119
if (lineLength >= endPos) {
119120
token = line.substring(startPos, endPos);

spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/CompositeExceptionHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2007 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.
@@ -24,6 +24,7 @@
2424
* Composite {@link ExceptionHandler} that loops though a list of delegates.
2525
*
2626
* @author Dave Syer
27+
* @author Mahmoud Ben Hassine
2728
*
2829
*/
2930
public class CompositeExceptionHandler implements ExceptionHandler {
@@ -42,8 +43,7 @@ public void setHandlers(ExceptionHandler[] handlers) {
4243
*/
4344
@Override
4445
public void handleException(RepeatContext context, Throwable throwable) throws Throwable {
45-
for (int i = 0; i < handlers.length; i++) {
46-
ExceptionHandler handler = handlers[i];
46+
for (ExceptionHandler handler : handlers) {
4747
handler.handleException(context, throwable);
4848
}
4949
}

spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/policy/CompositeCompletionPolicy.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2007 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.
@@ -30,6 +30,7 @@
3030
* consensus.
3131
*
3232
* @author Dave Syer
33+
* @author Mahmoud Ben Hassine
3334
*
3435
*/
3536
public class CompositeCompletionPolicy implements CompletionPolicy {
@@ -88,8 +89,8 @@ public boolean isComplete(RepeatContext context) {
8889
@Override
8990
public RepeatContext start(RepeatContext context) {
9091
List<RepeatContext> list = new ArrayList<>();
91-
for (int i = 0; i < policies.length; i++) {
92-
list.add(policies[i].start(context));
92+
for (CompletionPolicy policy : policies) {
93+
list.add(policy.start(context));
9394
}
9495
return new CompositeBatchContext(context, list);
9596

spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/RepeatTemplate.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2007 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.
@@ -60,6 +60,7 @@
6060
* interceptor.
6161
*
6262
* @author Dave Syer
63+
* @author Mahmoud Ben Hassine
6364
*
6465
*/
6566
public class RepeatTemplate implements RepeatOperations {
@@ -190,8 +191,7 @@ private RepeatStatus executeInternal(final RepeatCallback callback) {
190191
* all happen in the same thread - it's easier for tracking batch status,
191192
* amongst other things.
192193
*/
193-
for (int i = 0; i < listeners.length; i++) {
194-
RepeatListener interceptor = listeners[i];
194+
for (RepeatListener interceptor : listeners) {
195195
interceptor.before(context);
196196
// Allow before interceptors to veto the batch by setting
197197
// flag.

spring-batch-infrastructure/src/test/java/test/jdbc/datasource/DataSourceInitializer.java

Lines changed: 5 additions & 7 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.
@@ -86,8 +86,7 @@ public void destroy() {
8686
public void doDestroy() {
8787
if (destroyScripts == null)
8888
return;
89-
for (int i = 0; i < destroyScripts.length; i++) {
90-
Resource destroyScript = destroyScripts[i];
89+
for (Resource destroyScript : destroyScripts) {
9190
try {
9291
doExecuteScript(destroyScript);
9392
}
@@ -112,8 +111,7 @@ private void initialize() {
112111
if (!initialized) {
113112
doDestroy();
114113
if (initScripts != null) {
115-
for (int i = 0; i < initScripts.length; i++) {
116-
Resource initScript = initScripts[i];
114+
for (Resource initScript : initScripts) {
117115
doExecuteScript(initScript);
118116
}
119117
}
@@ -140,8 +138,8 @@ public Void doInTransaction(TransactionStatus status) {
140138
catch (IOException e) {
141139
throw new BeanInitializationException("Cannot load script from [" + scriptResource + "]", e);
142140
}
143-
for (int i = 0; i < scripts.length; i++) {
144-
String script = scripts[i].trim();
141+
for (String s : scripts) {
142+
String script = s.trim();
145143
if (StringUtils.hasText(script)) {
146144
try {
147145
jdbcTemplate.execute(script);

0 commit comments

Comments
 (0)