From 72194b7982ddfa8e9864d0a9934905bb76b90f33 Mon Sep 17 00:00:00 2001 From: Lars Grefer Date: Sat, 8 Aug 2020 03:06:37 +0200 Subject: 'for' loop replaceable with enhanced 'for' loop Reports for loops which iterate over collections or arrays, and can be replaced with an enhanced for loop (i.e. the foreach iteration syntax). Signed-off-by: Lars Grefer --- .../src/main/java/org/aspectj/testing/util/TestUtil.java | 16 ++++++++-------- .../test/java/org/aspectj/testingutil/TestUtilTest.java | 12 ++++++------ 2 files changed, 14 insertions(+), 14 deletions(-) (limited to 'testing-util') diff --git a/testing-util/src/main/java/org/aspectj/testing/util/TestUtil.java b/testing-util/src/main/java/org/aspectj/testing/util/TestUtil.java index ef6109e37..6be6cc61e 100644 --- a/testing-util/src/main/java/org/aspectj/testing/util/TestUtil.java +++ b/testing-util/src/main/java/org/aspectj/testing/util/TestUtil.java @@ -126,8 +126,8 @@ public final class TestUtil { // TODO support others loaded dynamically Map map = new HashMap<>(); - for (Iterator iter = LIB_RPATHS.keySet().iterator(); iter.hasNext();) { - String key = (String) iter.next(); + for (Object o : LIB_RPATHS.keySet()) { + String key = (String) o; String path = LIB_RPATHS.getProperty(key); File file = null; URL url = null; @@ -206,14 +206,14 @@ public final class TestUtil { } StringBuffer path = new StringBuffer(); boolean started = false; - for (int i = 0; i < entries.length; i++) { - if (null != entries[i]) { + for (Object entry : entries) { + if (null != entry) { if (started) { path.append(File.pathSeparator); } else { started = true; } - path.append(entries[i].toString()); + path.append(entry.toString()); } } return path.toString(); @@ -476,11 +476,11 @@ public final class TestUtil { } String[] paths = FileUtil.listFiles(expectedBaseDir); boolean result = true; - for (int i = 0; i < paths.length; i++) { - if (-1 != paths[i].indexOf("CVS")) { + for (String path : paths) { + if (-1 != path.indexOf("CVS")) { continue; } - if (!sameFiles(handler, expectedBaseDir, actualBaseDir, paths[i]) && result) { + if (!sameFiles(handler, expectedBaseDir, actualBaseDir, path) && result) { result = false; if (fastFail) { break; diff --git a/testing-util/src/test/java/org/aspectj/testingutil/TestUtilTest.java b/testing-util/src/test/java/org/aspectj/testingutil/TestUtilTest.java index 3a514a0ed..0807bd2a3 100644 --- a/testing-util/src/test/java/org/aspectj/testingutil/TestUtilTest.java +++ b/testing-util/src/test/java/org/aspectj/testingutil/TestUtilTest.java @@ -96,15 +96,15 @@ public class TestUtilTest extends TestCase { public void testParseBoolean() { { String[] trues = {"true", "TRUE", "on", "ON" }; - for (int i = 0; i < trues.length; i++) { - assertTrue(trues[i], TestUtil.parseBoolean(trues[i])); - } + for (String aTrue : trues) { + assertTrue(aTrue, TestUtil.parseBoolean(aTrue)); + } } { String[] falses = {"false", "FALSE", "off", "off" }; - for (int i = 0; i < falses.length; i++) { - assertTrue(falses[i], !TestUtil.parseBoolean(falses[i])); - } + for (String fals : falses) { + assertTrue(fals, !TestUtil.parseBoolean(fals)); + } } String[] errors = {"fals", "tru", "T", "on of" }; boolean fail = false; -- cgit v1.2.3