Replace for loops with enhanced for loop where appropriate

This commit is contained in:
Mahmoud Ben Hassine
2023-06-12 16:05:44 +02:00
parent 8c5456cff6
commit 7babb341f5
10 changed files with 44 additions and 44 deletions

View File

@@ -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.
@@ -231,8 +231,8 @@ public abstract class AbstractJob implements Job, StepLocator, BeanNameAware, In
* @param listeners the listeners to set.
*/
public void setJobExecutionListeners(JobExecutionListener[] listeners) {
for (int i = 0; i < listeners.length; i++) {
this.listener.register(listeners[i]);
for (JobExecutionListener jobExecutionListener : listeners) {
this.listener.register(jobExecutionListener);
}
}

View File

@@ -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.
@@ -379,8 +379,8 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw
* @param listeners an array of listener objects of known types.
*/
public void setStepExecutionListeners(StepExecutionListener[] listeners) {
for (int i = 0; i < listeners.length; i++) {
registerStepExecutionListener(listeners[i]);
for (StepExecutionListener listener : listeners) {
registerStepExecutionListener(listener);
}
}

View File

@@ -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.
@@ -167,8 +167,8 @@ public class TaskletStep extends AbstractStep {
* @param listeners an array of listener objects of known types.
*/
public void setChunkListeners(ChunkListener[] listeners) {
for (int i = 0; i < listeners.length; i++) {
registerChunkListener(listeners[i]);
for (ChunkListener listener : listeners) {
registerChunkListener(listener);
}
}
@@ -182,8 +182,8 @@ public class TaskletStep extends AbstractStep {
* @param streams an array of {@link ItemStream} objects.
*/
public void setStreams(ItemStream[] streams) {
for (int i = 0; i < streams.length; i++) {
registerStream(streams[i]);
for (ItemStream itemStream : streams) {
registerStream(itemStream);
}
}

View File

@@ -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.
@@ -83,8 +83,7 @@ public class DataSourceInitializer implements InitializingBean {
private void initialize() {
if (!initialized) {
if (initScripts != null) {
for (int i = 0; i < initScripts.length; i++) {
Resource script = initScripts[i];
for (Resource script : initScripts) {
doExecuteScript(script);
}
}
@@ -112,8 +111,8 @@ public class DataSourceInitializer implements InitializingBean {
catch (IOException e) {
throw new BeanInitializationException("Cannot load script from [" + scriptResource + "]", e);
}
for (int i = 0; i < scripts.length; i++) {
String script = scripts[i].trim();
for (String s : scripts) {
String script = s.trim();
if (StringUtils.hasText(script)) {
try {
jdbcTemplate.execute(script);

View File

@@ -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.
@@ -35,6 +35,7 @@ import java.util.List;
* @author Arjen Poutsma
* @author Juergen Hoeller
* @author Dave Syer
* @author Mahmoud Ben Hassine
* @since 1.0
* @see #forProperty(String, Class)
*/
@@ -128,9 +129,9 @@ final class PropertyMatches {
*/
private String[] calculateMatches(PropertyDescriptor[] propertyDescriptors, int maxDistance) {
List<String> candidates = new ArrayList<>();
for (int i = 0; i < propertyDescriptors.length; i++) {
if (propertyDescriptors[i].getWriteMethod() != null) {
String possibleAlternative = propertyDescriptors[i].getName();
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
if (propertyDescriptor.getWriteMethod() != null) {
String possibleAlternative = propertyDescriptor.getName();
int distance = calculateStringDistance(this.propertyName, possibleAlternative);
if (distance <= maxDistance) {
candidates.add(possibleAlternative);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2014 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.
@@ -29,6 +29,7 @@ import java.util.List;
* @author Dave Syer
* @author Lucas Ward
* @author Michael Minella
* @author Mahmoud Ben Hassine
*/
public class FixedLengthTokenizer extends AbstractLineTokenizer {
@@ -67,13 +68,13 @@ public class FixedLengthTokenizer extends AbstractLineTokenizer {
open = false;
maxRange = ranges[0].getMin();
for (int i = 0; i < ranges.length; i++) {
for (Range range : ranges) {
int upperBound;
if (ranges[i].hasMaxValue()) {
upperBound = ranges[i].getMax();
if (range.hasMaxValue()) {
upperBound = range.getMax();
}
else {
upperBound = ranges[i].getMin();
upperBound = range.getMin();
if (upperBound > maxRange) {
open = true;
}
@@ -110,10 +111,10 @@ public class FixedLengthTokenizer extends AbstractLineTokenizer {
line);
}
for (int i = 0; i < ranges.length; i++) {
for (Range range : ranges) {
int startPos = ranges[i].getMin() - 1;
int endPos = ranges[i].getMax();
int startPos = range.getMin() - 1;
int endPos = range.getMax();
if (lineLength >= endPos) {
token = line.substring(startPos, endPos);

View File

@@ -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.
@@ -24,6 +24,7 @@ import org.springframework.batch.repeat.RepeatContext;
* Composite {@link ExceptionHandler} that loops though a list of delegates.
*
* @author Dave Syer
* @author Mahmoud Ben Hassine
*
*/
public class CompositeExceptionHandler implements ExceptionHandler {
@@ -42,8 +43,7 @@ public class CompositeExceptionHandler implements ExceptionHandler {
*/
@Override
public void handleException(RepeatContext context, Throwable throwable) throws Throwable {
for (int i = 0; i < handlers.length; i++) {
ExceptionHandler handler = handlers[i];
for (ExceptionHandler handler : handlers) {
handler.handleException(context, throwable);
}
}

View File

@@ -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.
@@ -30,6 +30,7 @@ import org.springframework.batch.repeat.context.RepeatContextSupport;
* consensus.
*
* @author Dave Syer
* @author Mahmoud Ben Hassine
*
*/
public class CompositeCompletionPolicy implements CompletionPolicy {
@@ -88,8 +89,8 @@ public class CompositeCompletionPolicy implements CompletionPolicy {
@Override
public RepeatContext start(RepeatContext context) {
List<RepeatContext> list = new ArrayList<>();
for (int i = 0; i < policies.length; i++) {
list.add(policies[i].start(context));
for (CompletionPolicy policy : policies) {
list.add(policy.start(context));
}
return new CompositeBatchContext(context, list);

View File

@@ -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.
@@ -60,6 +60,7 @@ import org.springframework.util.Assert;
* interceptor.
*
* @author Dave Syer
* @author Mahmoud Ben Hassine
*
*/
public class RepeatTemplate implements RepeatOperations {
@@ -190,8 +191,7 @@ public class RepeatTemplate implements RepeatOperations {
* all happen in the same thread - it's easier for tracking batch status,
* amongst other things.
*/
for (int i = 0; i < listeners.length; i++) {
RepeatListener interceptor = listeners[i];
for (RepeatListener interceptor : listeners) {
interceptor.before(context);
// Allow before interceptors to veto the batch by setting
// flag.

View File

@@ -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.
@@ -86,8 +86,7 @@ public class DataSourceInitializer implements InitializingBean, DisposableBean {
public void doDestroy() {
if (destroyScripts == null)
return;
for (int i = 0; i < destroyScripts.length; i++) {
Resource destroyScript = destroyScripts[i];
for (Resource destroyScript : destroyScripts) {
try {
doExecuteScript(destroyScript);
}
@@ -112,8 +111,7 @@ public class DataSourceInitializer implements InitializingBean, DisposableBean {
if (!initialized) {
doDestroy();
if (initScripts != null) {
for (int i = 0; i < initScripts.length; i++) {
Resource initScript = initScripts[i];
for (Resource initScript : initScripts) {
doExecuteScript(initScript);
}
}
@@ -140,8 +138,8 @@ public class DataSourceInitializer implements InitializingBean, DisposableBean {
catch (IOException e) {
throw new BeanInitializationException("Cannot load script from [" + scriptResource + "]", e);
}
for (int i = 0; i < scripts.length; i++) {
String script = scripts[i].trim();
for (String s : scripts) {
String script = s.trim();
if (StringUtils.hasText(script)) {
try {
jdbcTemplate.execute(script);