From dfb3cd51bcc717ccbf38b5627756fe64532bed96 Mon Sep 17 00:00:00 2001 From: igor-suhorukov Date: Tue, 25 Dec 2018 00:06:13 +0300 Subject: [PATCH 1/2] Simplify code by using for-each loop See gh-15563 --- .../boot/autoconfigure/session/SessionAutoConfiguration.java | 4 ++-- .../boot/configurationprocessor/json/JSONArray.java | 4 ++-- .../org/springframework/boot/loader/tools/Repackager.java | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionAutoConfiguration.java index e61c513f74..420bed0aa4 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionAutoConfiguration.java @@ -164,9 +164,9 @@ public class SessionAutoConfiguration { protected final String[] selectImports(WebApplicationType webApplicationType) { List imports = new ArrayList<>(); StoreType[] types = StoreType.values(); - for (int i = 0; i < types.length; i++) { + for (StoreType type : types) { imports.add(SessionStoreMappings.getConfigurationClass(webApplicationType, - types[i])); + type)); } return StringUtils.toStringArray(imports); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSONArray.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSONArray.java index 73370fdd41..c79b862052 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSONArray.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSONArray.java @@ -65,8 +65,8 @@ public class JSONArray { public JSONArray(Collection copyFrom) { this(); if (copyFrom != null) { - for (Iterator it = copyFrom.iterator(); it.hasNext();) { - put(JSONObject.wrap(it.next())); + for (Object value : copyFrom) { + put(JSONObject.wrap(value)); } } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Repackager.java b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Repackager.java index 4c764dea7d..17fd19f121 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Repackager.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Repackager.java @@ -270,8 +270,8 @@ public class Repackager { } private boolean isZip(InputStream inputStream) throws IOException { - for (int i = 0; i < ZIP_FILE_HEADER.length; i++) { - if (inputStream.read() != ZIP_FILE_HEADER[i]) { + for (byte magicByte : ZIP_FILE_HEADER) { + if (inputStream.read() != magicByte) { return false; } } From 1223355fe6f76542b41d2b25d0ce7fd33cb3e9a1 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 25 Dec 2018 09:59:41 +0100 Subject: [PATCH 2/2] Polish "Simplify code by using for-each loop" Closes gh-15563 --- .../boot/configurationprocessor/json/JSONArray.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSONArray.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSONArray.java index c79b862052..73370fdd41 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSONArray.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSONArray.java @@ -65,8 +65,8 @@ public class JSONArray { public JSONArray(Collection copyFrom) { this(); if (copyFrom != null) { - for (Object value : copyFrom) { - put(JSONObject.wrap(value)); + for (Iterator it = copyFrom.iterator(); it.hasNext();) { + put(JSONObject.wrap(it.next())); } } }