From 512ffc9e7f006677ddd7cc000a510121f93cb6bd Mon Sep 17 00:00:00 2001 From: Lars Vogel Date: Thu, 27 Feb 2020 11:05:23 +0100 Subject: [PATCH] Using for-each loop in jdt Running the JDT cleanup action for using a for-each loop on jgit Change-Id: Ie724d8bbdff786ab0167089e90a9914a8135103c Signed-off-by: Lars Vogel --- org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java | 3 +-- .../src/org/eclipse/jgit/fnmatch/FileNameMatcher.java | 4 ++-- .../org/eclipse/jgit/internal/storage/pack/DeltaIndex.java | 4 ++-- .../eclipse/jgit/revwalk/filter/PatternMatchRevFilter.java | 4 ++-- .../src/org/eclipse/jgit/transport/HttpAuthMethod.java | 3 +-- org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java | 4 ++-- org.eclipse.jgit/src/org/eclipse/jgit/util/QuotedString.java | 4 ++-- org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java | 4 ++-- 8 files changed, 14 insertions(+), 16 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java index b722fbe9d..6678af163 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java @@ -338,8 +338,7 @@ public class RebaseCommand extends GitCommand { steps, false); } checkSteps(steps); - for (int i = 0; i < steps.size(); i++) { - RebaseTodoLine step = steps.get(i); + for (RebaseTodoLine step : steps) { popSteps(1); RebaseResult result = processStep(step, true); if (result != null) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/fnmatch/FileNameMatcher.java b/org.eclipse.jgit/src/org/eclipse/jgit/fnmatch/FileNameMatcher.java index 3a6c413a0..57b90e966 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/fnmatch/FileNameMatcher.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/fnmatch/FileNameMatcher.java @@ -380,8 +380,8 @@ public class FileNameMatcher { * @return a boolean. */ public boolean canAppendMatch() { - for (int i = 0; i < heads.size(); i++) { - if (heads.get(i) != LastHead.INSTANCE) { + for (Head head : heads) { + if (head != LastHead.INSTANCE) { return true; } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/DeltaIndex.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/DeltaIndex.java index 79eaea093..7ed5defbe 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/DeltaIndex.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/DeltaIndex.java @@ -122,8 +122,8 @@ public class DeltaIndex { // logic linear in the size of the input rather than quadratic. // int cnt = 0; - for (int i = 0; i < table.length; i++) { - int h = table[i]; + for (int element : table) { + int h = element; if (h == 0) continue; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/PatternMatchRevFilter.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/PatternMatchRevFilter.java index 0d782e0a3..efb5ee5e4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/PatternMatchRevFilter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/PatternMatchRevFilter.java @@ -42,8 +42,8 @@ public abstract class PatternMatchRevFilter extends RevFilter { protected static final String forceToRaw(String patternText) { final byte[] b = Constants.encode(patternText); final StringBuilder needle = new StringBuilder(b.length); - for (int i = 0; i < b.length; i++) - needle.append((char) (b[i] & 0xff)); + for (byte element : b) + needle.append((char) (element & 0xff)); return needle.toString(); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpAuthMethod.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpAuthMethod.java index adc85a18e..aec5b89c7 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpAuthMethod.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpAuthMethod.java @@ -423,8 +423,7 @@ abstract class HttpAuthMethod { private static String LHEX(byte[] bin) { StringBuilder r = new StringBuilder(bin.length * 2); - for (int i = 0; i < bin.length; i++) { - byte b = bin[i]; + for (byte b : bin) { r.append(LHEX[(b >>> 4) & 0x0f]); r.append(LHEX[b & 0x0f]); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java index 858d1f7b6..06520ec4c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java @@ -303,8 +303,8 @@ public class URIish implements Serializable { return null; ByteArrayOutputStream os = new ByteArrayOutputStream(s.length()); byte[] bytes = s.getBytes(UTF_8); - for (int i = 0; i < bytes.length; ++i) { - int b = bytes[i] & 0xFF; + for (byte c : bytes) { + int b = c & 0xFF; if (b <= 32 || (encodeNonAscii && b > 127) || b == '%' || (escapeReservedChars && reservedChars.get(b))) { os.write('%'); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/QuotedString.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/QuotedString.java index c45f0095d..493ca312d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/QuotedString.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/QuotedString.java @@ -243,8 +243,8 @@ public abstract class QuotedString { final byte[] out = new byte[4 * in.length + 2]; int o = 0; out[o++] = '"'; - for (int i = 0; i < in.length; i++) { - final int c = in[i] & 0xff; + for (byte element : in) { + final int c = element & 0xff; if (c < quote.length) { final byte style = quote[c]; if (style == 0) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java index 669f73842..df9c6c78f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java @@ -559,8 +559,8 @@ public final class RawParseUtils { } while (ptr < b.length - (headerName.length + 1)) { boolean found = true; - for (int i = 0; i < headerName.length; i++) { - if (headerName[i] != b[ptr++]) { + for (byte element : headerName) { + if (element != b[ptr++]) { found = false; break; }