diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java b/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java index 3c9aab7d8..151acd237 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.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. @@ -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); } } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/AbstractStep.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/AbstractStep.java index c14f7e670..f116e2d56 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/AbstractStep.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/AbstractStep.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. @@ -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); } } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/TaskletStep.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/TaskletStep.java index 5c0c5f6ce..cbc541ea6 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/TaskletStep.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/TaskletStep.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. @@ -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); } } diff --git a/spring-batch-core/src/test/java/test/jdbc/datasource/DataSourceInitializer.java b/spring-batch-core/src/test/java/test/jdbc/datasource/DataSourceInitializer.java index 0a344cb8b..4f09a1e2d 100644 --- a/spring-batch-core/src/test/java/test/jdbc/datasource/DataSourceInitializer.java +++ b/spring-batch-core/src/test/java/test/jdbc/datasource/DataSourceInitializer.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. @@ -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); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/PropertyMatches.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/PropertyMatches.java index 24420f9b5..6ca49fb7b 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/PropertyMatches.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/PropertyMatches.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. @@ -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 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); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/FixedLengthTokenizer.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/FixedLengthTokenizer.java index 47c703af0..8d27812a7 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/FixedLengthTokenizer.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/FixedLengthTokenizer.java @@ -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); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/CompositeExceptionHandler.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/CompositeExceptionHandler.java index 62185e713..50c10338a 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/CompositeExceptionHandler.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/CompositeExceptionHandler.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. @@ -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); } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/policy/CompositeCompletionPolicy.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/policy/CompositeCompletionPolicy.java index d5d32c79c..b8177a17d 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/policy/CompositeCompletionPolicy.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/policy/CompositeCompletionPolicy.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. @@ -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 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); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/RepeatTemplate.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/RepeatTemplate.java index 5690655c6..4e81315d1 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/RepeatTemplate.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/RepeatTemplate.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. @@ -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. diff --git a/spring-batch-infrastructure/src/test/java/test/jdbc/datasource/DataSourceInitializer.java b/spring-batch-infrastructure/src/test/java/test/jdbc/datasource/DataSourceInitializer.java index f1ef5bd74..563394e80 100644 --- a/spring-batch-infrastructure/src/test/java/test/jdbc/datasource/DataSourceInitializer.java +++ b/spring-batch-infrastructure/src/test/java/test/jdbc/datasource/DataSourceInitializer.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. @@ -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);