Use jdk 5 for-each loop

Replace simple uses of Iterator with a corresponding for-loop. Also add
missing braces on loops as necessary.


Change-Id: Ic951555a6a16cb5ea54f6150bb55254f6b17fe03
Signed-off-by: Carsten Hammer <carsten.hammer@t-online.de>
diff --git a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EclipseLauncherParser.java b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EclipseLauncherParser.java
index 4d264f8..65958eb 100644
--- a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EclipseLauncherParser.java
+++ b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EclipseLauncherParser.java
@@ -328,8 +328,7 @@
 		//only write the file if we actually have content
 		if (newlines.size() > 0) {
 			try (BufferedWriter bw = new BufferedWriter(new FileWriter(launcherConfigFile));) {
-				for (int j = 0; j < newlines.size(); j++) {
-					String arg = newlines.get(j);
+				for (String arg : newlines) {
 					if (arg == null)
 						continue;
 					bw.write(arg);
diff --git a/bundles/org.eclipse.equinox.p2.garbagecollector/src/org/eclipse/equinox/internal/p2/garbagecollector/CoreGarbageCollector.java b/bundles/org.eclipse.equinox.p2.garbagecollector/src/org/eclipse/equinox/internal/p2/garbagecollector/CoreGarbageCollector.java
index fe31939..5a75a5e 100644
--- a/bundles/org.eclipse.equinox.p2.garbagecollector/src/org/eclipse/equinox/internal/p2/garbagecollector/CoreGarbageCollector.java
+++ b/bundles/org.eclipse.equinox.p2.garbagecollector/src/org/eclipse/equinox/internal/p2/garbagecollector/CoreGarbageCollector.java
@@ -39,10 +39,8 @@
 		Set<IArtifactKey> set = new HashSet<>(Arrays.asList(markSet));
 		//this query will match all artifact keys that are not in the given set
 		IQuery<IArtifactKey> query = QueryUtil.createQuery(IArtifactKey.class, "unique($0)", set); //$NON-NLS-1$
-		final IQueryResult<IArtifactKey> inactive = aRepository.query(query, null);
 		aRepository.executeBatch(monitor -> {
-			for (Iterator<IArtifactKey> iterator = inactive.iterator(); iterator.hasNext();) {
-				IArtifactKey key = iterator.next();
+			for (IArtifactKey key : aRepository.query(query, null)) {
 				aRepository.removeDescriptor(key, new NullProgressMonitor());
 				if (debugMode) {
 					Tracing.debug("Key removed:" + key); //$NON-NLS-1$
diff --git a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/CurryedLambdaExpression.java b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/CurryedLambdaExpression.java
index c4401eb..dd2089a 100644
--- a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/CurryedLambdaExpression.java
+++ b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/CurryedLambdaExpression.java
@@ -33,8 +33,8 @@
 	@Override
 	public boolean accept(IExpressionVisitor visitor) {
 		if (super.accept(visitor) && each.accept(visitor)) {
-			for (int idx = 0; idx < assignments.length; ++idx)
-				if (!assignments[idx].accept(visitor))
+			for (Assignment assignment : assignments)
+				if (!assignment.accept(visitor))
 					return false;
 			return true;
 		}
@@ -96,8 +96,8 @@
 	@Override
 	int countAccessToEverything() {
 		int cnt = 0;
-		for (int idx = 0; idx < assignments.length; ++idx)
-			cnt += assignments[idx].countAccessToEverything();
+		for (Assignment assignment : assignments)
+			cnt += assignment.countAccessToEverything();
 		cnt += super.countAccessToEverything();
 		return cnt;
 	}
diff --git a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/Expression.java b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/Expression.java
index b7849d4..6d298fe 100644
--- a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/Expression.java
+++ b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/Expression.java
@@ -107,17 +107,20 @@
 		}
 	}
 
-	public static List<String> getIndexCandidateMembers(Class<?> elementClass, Variable itemVariable, Expression operand) {
+	public static List<String> getIndexCandidateMembers(Class<?> elementClass, Variable itemVariable,
+			Expression operand) {
 		MembersFinder finder = new MembersFinder(elementClass, itemVariable);
 		operand.accept(finder);
 		return finder.getMembers();
 	}
 
 	/**
-	 * Let the visitor visit this instance and all expressions that this
-	 * instance contains.
+	 * Let the visitor visit this instance and all expressions that this instance
+	 * contains.
+	 * 
 	 * @param visitor The visiting visitor.
-	 * @return <code>true</code> if the visitor should continue visiting, <code>false</code> otherwise.
+	 * @return <code>true</code> if the visitor should continue visiting,
+	 *         <code>false</code> otherwise.
 	 */
 	@Override
 	public boolean accept(IExpressionVisitor visitor) {
@@ -146,6 +149,7 @@
 
 	/**
 	 * Evaluate this expression with given context and variables.
+	 * 
 	 * @param context The evaluation context
 	 * @return The result of the evaluation.
 	 */
@@ -218,12 +222,12 @@
 			if (base.getExpressionType() == op)
 				aArr = getFilterImpls(base);
 			else
-				aArr = new Expression[] {base};
+				aArr = new Expression[] { base };
 
 			if (b.getExpressionType() == op)
 				bArr = getFilterImpls(b);
 			else
-				bArr = new Expression[] {b};
+				bArr = new Expression[] { b };
 
 			List<Expression> common = null;
 			List<Expression> onlyA = null;
@@ -388,11 +392,9 @@
 			if (f.getExpressionType() != op)
 				continue;
 
-			Expression[] sfs = getFilterImpls(f);
 			operands.remove(idx);
 			--top;
-			for (int ndx = 0; ndx < sfs.length; ++ndx) {
-				Expression nf = sfs[ndx];
+			for (Expression nf : getFilterImpls(f)) {
 				if (!operands.contains(nf))
 					operands.add(nf);
 			}
@@ -484,7 +486,8 @@
 
 		@Override
 		public boolean visit(IExpression expression) {
-			if (expression.getExpressionType() == TYPE_MEMBER && InstallableUnit.MEMBER_TRANSLATED_PROPERTIES.equals(((Member) expression).getName()))
+			if (expression.getExpressionType() == TYPE_MEMBER
+					&& InstallableUnit.MEMBER_TRANSLATED_PROPERTIES.equals(((Member) expression).getName()))
 				found = true;
 			return !found;
 		}
@@ -495,8 +498,11 @@
 	}
 
 	/**
-	 * Checks if the expression will make repeated requests for the 'everything' iterator.
-	 * @return <code>true</code> if repeated requests will be made, <code>false</code> if not.
+	 * Checks if the expression will make repeated requests for the 'everything'
+	 * iterator.
+	 * 
+	 * @return <code>true</code> if repeated requests will be made,
+	 *         <code>false</code> if not.
 	 */
 	public boolean needsTranslationSupport() {
 		TranslationSupportFinder tsFinder = new TranslationSupportFinder();
diff --git a/bundles/org.eclipse.equinox.p2.publisher.eclipse/src/org/eclipse/equinox/p2/publisher/eclipse/EquinoxExecutableAction.java b/bundles/org.eclipse.equinox.p2.publisher.eclipse/src/org/eclipse/equinox/p2/publisher/eclipse/EquinoxExecutableAction.java
index 862574d..0e8fa0d 100644
--- a/bundles/org.eclipse.equinox.p2.publisher.eclipse/src/org/eclipse/equinox/p2/publisher/eclipse/EquinoxExecutableAction.java
+++ b/bundles/org.eclipse.equinox.p2.publisher.eclipse/src/org/eclipse/equinox/p2/publisher/eclipse/EquinoxExecutableAction.java
@@ -245,9 +245,8 @@
 	private IBrandingAdvice getBrandingAdvice() {
 		// there is expected to only be one branding advice for a given configspec so
 		// just return the first one we find.
-		Collection<IBrandingAdvice> advice = info.getAdvice(configSpec, true, null, null, IBrandingAdvice.class);
-		for (Iterator<IBrandingAdvice> i = advice.iterator(); i.hasNext();)
-			return i.next();
+		for (IBrandingAdvice advice : info.getAdvice(configSpec, true, null, null, IBrandingAdvice.class))
+			return advice;
 		return null;
 	}
 
diff --git a/bundles/org.eclipse.equinox.p2.publisher.eclipse/src/org/eclipse/equinox/p2/publisher/eclipse/FeaturesAction.java b/bundles/org.eclipse.equinox.p2.publisher.eclipse/src/org/eclipse/equinox/p2/publisher/eclipse/FeaturesAction.java
index 5c3d9a2..cbc41b8 100644
--- a/bundles/org.eclipse.equinox.p2.publisher.eclipse/src/org/eclipse/equinox/p2/publisher/eclipse/FeaturesAction.java
+++ b/bundles/org.eclipse.equinox.p2.publisher.eclipse/src/org/eclipse/equinox/p2/publisher/eclipse/FeaturesAction.java
@@ -254,8 +254,7 @@
 		// link in all the children (if any) as requirements.
 		// TODO consider if these should be linked as exact version numbers.  Should be ok but may be brittle.
 		if (childIUs != null) {
-			for (int i = 0; i < childIUs.size(); i++) {
-				IInstallableUnit child = childIUs.get(i);
+			for (IInstallableUnit child : childIUs) {
 				IMatchExpression<IInstallableUnit> filter = child.getFilter();
 				required.add(MetadataFactory.createRequirement(PublisherHelper.IU_NAMESPACE, child.getId(), new VersionRange(child.getVersion(), true, child.getVersion(), true), filter, false, false));
 			}
@@ -340,8 +339,7 @@
 
 		//Always add a requirement on the IU containing the feature jar
 		if (childIUs != null) {
-			for (int i = 0; i < childIUs.size(); i++) {
-				IInstallableUnit child = childIUs.get(i);
+			for (IInstallableUnit child : childIUs) {
 				patchRequirements.add(MetadataFactory.createRequirement(PublisherHelper.IU_NAMESPACE, child.getId(), new VersionRange(child.getVersion(), true, child.getVersion(), true), child.getFilter(), false, false));
 			}
 		}
diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/Disassembler.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/Disassembler.java
index 6bcc5e3..31364d2 100644
--- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/Disassembler.java
+++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/Disassembler.java
@@ -57,8 +57,8 @@
 		if (checkBits == null)
 			return;
 		boolean firstModifier = true;
-		for (int i = 0, max = checkBits.length; i < max; i++) {
-			switch (checkBits[i]) {
+		for (int checkBit : checkBits) {
+			switch (checkBit) {
 				case IModifierConstants.ACC_PUBLIC :
 					firstModifier = appendModifier(buffer, accessFlags, IModifierConstants.ACC_PUBLIC, "public", firstModifier); //$NON-NLS-1$
 					break;
@@ -180,8 +180,7 @@
 
 	static String decodeStringValue(char[] chars) {
 		StringBuilder buffer = new StringBuilder();
-		for (int i = 0, max = chars.length; i < max; i++) {
-			char c = chars[i];
+		for (char c : chars) {
 			switch (c) {
 				case '\b' :
 					buffer.append("\\b"); //$NON-NLS-1$
@@ -248,9 +247,8 @@
 		writeNewLine(buffer, lineSeparator, tabNumber + 1);
 		final char[] typeName = CharOperation.replaceOnCopy(annotation.getTypeName(), '/', '.');
 		buffer.append(NLS.bind(Messages.disassembler_annotationentrystart, new String[] {new String(returnClassName(Signature.toCharArray(typeName), '.', mode))}));
-		final AnnotationComponent[] components = annotation.getComponents();
-		for (int i = 0, max = components.length; i < max; i++) {
-			disassemble(components[i], buffer, lineSeparator, tabNumber + 1, mode);
+		for (AnnotationComponent component : annotation.getComponents()) {
+			disassemble(component, buffer, lineSeparator, tabNumber + 1, mode);
 		}
 		writeNewLine(buffer, lineSeparator, tabNumber + 1);
 		buffer.append(Messages.disassembler_annotationentryend);
@@ -323,12 +321,13 @@
 				Annotation annotation = annotationComponentValue.getAnnotationValue();
 				disassemble(annotation, buffer, lineSeparator, tabNumber + 1, mode);
 				break;
-			case AnnotationComponentValue.ARRAY_TAG :
+			case AnnotationComponentValue.ARRAY_TAG:
 				buffer.append(Messages.disassembler_annotationarrayvaluestart);
-				final AnnotationComponentValue[] annotationComponentValues = annotationComponentValue.getAnnotationComponentValues();
-				for (int i = 0, max = annotationComponentValues.length; i < max; i++) {
+				final AnnotationComponentValue[] annotationComponentValues = annotationComponentValue
+					.getAnnotationComponentValues();
+				for (AnnotationComponentValue annotationComponentValue2 : annotationComponentValues) {
 					writeNewLine(buffer, lineSeparator, tabNumber + 1);
-					disassemble(annotationComponentValues[i], buffer, lineSeparator, tabNumber + 1, mode);
+					disassemble(annotationComponentValue2, buffer, lineSeparator, tabNumber + 1, mode);
 				}
 				writeNewLine(buffer, lineSeparator, tabNumber + 1);
 				buffer.append(Messages.disassembler_annotationarrayvalueend);
@@ -567,8 +566,7 @@
 		if (innerClassesAttribute != null) {
 			// search the right entry
 			InnerClassesAttributeEntry[] entries = innerClassesAttribute.getInnerClassAttributesEntries();
-			for (int i = 0, max = entries.length; i < max; i++) {
-				InnerClassesAttributeEntry entry = entries[i];
+			for (InnerClassesAttributeEntry entry : entries) {
 				char[] innerClassName = entry.getInnerClassName();
 				if (innerClassName != null) {
 					if (Arrays.equals(classFileReader.getClassName(), innerClassName)) {
@@ -876,8 +874,8 @@
 		Annotation[] annotations = parameterAnnotation.getAnnotations();
 		writeNewLine(buffer, lineSeparator, tabNumber + 1);
 		buffer.append(NLS.bind(Messages.disassembler_parameterannotationentrystart, new String[] {Integer.toString(index), Integer.toString(annotations.length)}));
-		for (int i = 0, max = annotations.length; i < max; i++) {
-			disassemble(annotations[i], buffer, lineSeparator, tabNumber + 1, mode);
+		for (Annotation annotation : annotations) {
+			disassemble(annotation, buffer, lineSeparator, tabNumber + 1, mode);
 		}
 	}
 
@@ -885,8 +883,8 @@
 		writeNewLine(buffer, lineSeparator, tabNumber + 1);
 		buffer.append(Messages.disassembler_runtimeinvisibleannotationsattributeheader);
 		Annotation[] annotations = runtimeInvisibleAnnotationsAttribute.getAnnotations();
-		for (int i = 0, max = annotations.length; i < max; i++) {
-			disassemble(annotations[i], buffer, lineSeparator, tabNumber + 1, mode);
+		for (Annotation annotation : annotations) {
+			disassemble(annotation, buffer, lineSeparator, tabNumber + 1, mode);
 		}
 	}
 
@@ -903,8 +901,8 @@
 		writeNewLine(buffer, lineSeparator, tabNumber + 1);
 		buffer.append(Messages.disassembler_runtimevisibleannotationsattributeheader);
 		Annotation[] annotations = runtimeVisibleAnnotationsAttribute.getAnnotations();
-		for (int i = 0, max = annotations.length; i < max; i++) {
-			disassemble(annotations[i], buffer, lineSeparator, tabNumber + 1, mode);
+		for (Annotation annotation : annotations) {
+			disassemble(annotation, buffer, lineSeparator, tabNumber + 1, mode);
 		}
 	}
 
@@ -1019,9 +1017,8 @@
 	}
 
 	private void disassembleAsModifier(RuntimeInvisibleAnnotationsAttribute runtimeInvisibleAnnotationsAttribute, StringBuffer buffer, String lineSeparator, int tabNumber, int mode) {
-		Annotation[] annotations = runtimeInvisibleAnnotationsAttribute.getAnnotations();
-		for (int i = 0, max = annotations.length; i < max; i++) {
-			disassembleAsModifier(annotations[i], buffer, lineSeparator, tabNumber + 1, mode);
+		for (Annotation annotation : runtimeInvisibleAnnotationsAttribute.getAnnotations()) {
+			disassembleAsModifier(annotation, buffer, lineSeparator, tabNumber + 1, mode);
 		}
 	}
 
@@ -1069,9 +1066,9 @@
 			}
 			return compare;
 		});
-		for (int i = 0, max = fields.length; i < max; i++) {
+		for (FieldInfo field : fields) {
 			writeNewLine(buffer, lineSeparator, tabNumber);
-			disassemble(fields[i], buffer, lineSeparator, tabNumber, mode);
+			disassemble(field, buffer, lineSeparator, tabNumber, mode);
 		}
 		MethodInfo[] methods = classFileReader.getMethodInfos();
 		// sort methods
@@ -1082,9 +1079,9 @@
 			}
 			return compare;
 		});
-		for (int i = 0, max = methods.length; i < max; i++) {
+		for (MethodInfo method : methods) {
 			writeNewLine(buffer, lineSeparator, tabNumber);
-			disassemble(classFileReader, className, methods[i], buffer, lineSeparator, tabNumber, mode);
+			disassemble(classFileReader, className, method, buffer, lineSeparator, tabNumber, mode);
 		}
 	}
 
@@ -1095,10 +1092,9 @@
 	}
 
 	private EnclosingMethodAttribute getEnclosingMethodAttribute(ClassFileReader classFileReader) {
-		ClassFileAttribute[] attributes = classFileReader.getAttributes();
-		for (int i = 0, max = attributes.length; i < max; i++) {
-			if (Arrays.equals(attributes[i].getAttributeName(), AttributeNamesConstants.ENCLOSING_METHOD)) {
-				return (EnclosingMethodAttribute) attributes[i];
+		for (ClassFileAttribute attribute : classFileReader.getAttributes()) {
+			if (Arrays.equals(attribute.getAttributeName(), AttributeNamesConstants.ENCLOSING_METHOD)) {
+				return (EnclosingMethodAttribute) attribute;
 			}
 		}
 		return null;
@@ -1113,9 +1109,8 @@
 	}
 
 	private boolean isDeprecated(ClassFileReader classFileReader) {
-		ClassFileAttribute[] attributes = classFileReader.getAttributes();
-		for (int i = 0, max = attributes.length; i < max; i++) {
-			if (Arrays.equals(attributes[i].getAttributeName(), AttributeNamesConstants.DEPRECATED)) {
+		for (ClassFileAttribute attribute : classFileReader.getAttributes()) {
+			if (Arrays.equals(attribute.getAttributeName(), AttributeNamesConstants.DEPRECATED)) {
 				return true;
 			}
 		}
@@ -1127,9 +1122,8 @@
 		if ((flags & IModifierConstants.ACC_SYNTHETIC) != 0) {
 			return true;
 		}
-		ClassFileAttribute[] attributes = classFileReader.getAttributes();
-		for (int i = 0, max = attributes.length; i < max; i++) {
-			if (Arrays.equals(attributes[i].getAttributeName(), AttributeNamesConstants.SYNTHETIC)) {
+		for (ClassFileAttribute attribute : classFileReader.getAttributes()) {
+			if (Arrays.equals(attribute.getAttributeName(), AttributeNamesConstants.SYNTHETIC)) {
 				return true;
 			}
 		}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/FoldersRepositoryTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/FoldersRepositoryTest.java
index 583bf1d..fbc651f 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/FoldersRepositoryTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/FoldersRepositoryTest.java
@@ -17,7 +17,6 @@
 import java.io.File;
 import java.io.FileFilter;
 import java.net.URL;
-import java.util.Iterator;
 import junit.framework.TestCase;
 import org.eclipse.core.runtime.FileLocator;
 import org.eclipse.core.runtime.IProgressMonitor;
@@ -96,8 +95,7 @@
 		}
 		IQueryResult<IArtifactKey> keys = repo.query(ArtifactKeyQuery.ALL_KEYS, null);
 		assertEquals(2, AbstractProvisioningTest.queryResultSize(keys));
-		for (Iterator<IArtifactKey> iterator = keys.iterator(); iterator.hasNext();) {
-			IArtifactKey key = iterator.next();
+		for (IArtifactKey key : keys) {
 			repo.removeDescriptor(key, monitor);
 		}
 
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/expression/FilterTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/expression/FilterTest.java
index b25134d..597e8bd 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/expression/FilterTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/expression/FilterTest.java
@@ -24,7 +24,6 @@
 import java.util.Dictionary;
 import java.util.HashMap;
 import java.util.Hashtable;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import org.eclipse.equinox.p2.metadata.Version;
@@ -241,8 +240,8 @@
 			this.dictionary = dictionary;
 			List<String> keyList = new ArrayList<>(dictionary.size());
 			for (String key : dictionary.keySet()) {
-				for (Iterator<String> i = keyList.iterator(); i.hasNext();) {
-					if (key.equalsIgnoreCase(i.next())) {
+				for (String string : keyList) {
+					if (key.equalsIgnoreCase(string)) {
 						throw new IllegalArgumentException();
 					}
 				}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/omniVersion/FormatDTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/omniVersion/FormatDTest.java
index 201170e..6266ae9 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/omniVersion/FormatDTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/omniVersion/FormatDTest.java
@@ -64,11 +64,11 @@
 		String formatString = "format(ndn):";
 		Integer one = Integer.valueOf(1);
 		Integer two = Integer.valueOf(2);
-		for (int i = 0; i < s_delim.length; i++) {
+		for (char delim : s_delim) {
 			StringBuilder buf = new StringBuilder();
 			buf.append(formatString);
 			buf.append("1");
-			buf.append(s_delim[i]);
+			buf.append(delim);
 			buf.append("2");
 			v = Version.parseVersion(buf.toString());
 			assertNotNull(v);
@@ -82,11 +82,11 @@
 		String formatString = "format(sds):";
 		String one = "abc";
 		String two = "def";
-		for (int i = 0; i < s_delim.length; i++) {
+		for (char delim : s_delim) {
 			StringBuilder buf = new StringBuilder();
 			buf.append(formatString);
 			buf.append(one);
-			buf.append(s_delim[i]);
+			buf.append(delim);
 			buf.append(two);
 			v = Version.parseVersion(buf.toString());
 			assertNotNull(v);
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/EPPPackageInstallStability_bug323322.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/EPPPackageInstallStability_bug323322.java
index e6fe1f7..e82e23c 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/EPPPackageInstallStability_bug323322.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/EPPPackageInstallStability_bug323322.java
@@ -18,7 +18,6 @@
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 import org.eclipse.core.runtime.NullProgressMonitor;
@@ -63,8 +62,7 @@
 
 			//Extract all the unresolved IUs.
 			Set<IInstallableUnit> tmp = plan.getAdditions().query(QueryUtil.ALL_UNITS, new NullProgressMonitor()).query(QueryUtil.ALL_UNITS, null).toSet();
-			for (Iterator<IInstallableUnit> iterator = tmp.iterator(); iterator.hasNext();) {
-				IInstallableUnit iu = iterator.next();
+			for (IInstallableUnit iu : tmp) {
 				iusFromFirstResolution.add(iu.unresolved());
 			}
 		}
@@ -84,8 +82,7 @@
 
 			Set<IInstallableUnit> tmp = plan.getAdditions().query(QueryUtil.ALL_UNITS, new NullProgressMonitor()).query(QueryUtil.ALL_UNITS, null).toSet();
 			Set<IInstallableUnit> iusFromSecondResolution = new HashSet<>();
-			for (Iterator<IInstallableUnit> iterator = tmp.iterator(); iterator.hasNext();) {
-				IInstallableUnit iu = iterator.next();
+			for (IInstallableUnit iu : tmp) {
 				iusFromSecondResolution.add(iu.unresolved());
 			}
 
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/ConfigCUsActionTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/ConfigCUsActionTest.java
index db4e098..24b6997 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/ConfigCUsActionTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/ConfigCUsActionTest.java
@@ -95,8 +95,7 @@
 	private void verifyFragment(String cuType) {
 		ArrayList<IInstallableUnit> IUs = new ArrayList<>(publisherResult.getIUs(null, IPublisherResult.NON_ROOT));
 		assertTrue(IUs.size() == 2);
-		for (int i = 0; i < IUs.size(); i++) {
-			InstallableUnit iu = (InstallableUnit) IUs.get(i);
+		for (IInstallableUnit iu : IUs) {
 			if (iu.getId().equals(flavor + id + "." + cuType + "." + configSpec)) { //$NON-NLS-1$ //$NON-NLS-2$
 				assertTrue(iu.getFilter().equals(InstallableUnit.parseFilter("(& (osgi.ws=win32)(osgi.os=win32)(osgi.arch=x86))"))); //$NON-NLS-1$
 				assertTrue(iu.getVersion().equals(version));
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/EquinoxExecutableActionTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/EquinoxExecutableActionTest.java
index 4e502a7..41bf705 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/EquinoxExecutableActionTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/EquinoxExecutableActionTest.java
@@ -139,10 +139,9 @@
 		String _ws = config[0];
 		String _os = config[1];
 		String _arch = config[2];
-		for (int i = 0; i < iuList.size(); i++) {
-			IInstallableUnit possibleEclipse = iuList.get(i);
+		for (IInstallableUnit possibleEclipse : iuList) {
 			if (possibleEclipse.getId().equals(flavorArg + idBase + ".executable." + confSpec)) {//$NON-NLS-1$
-				IInstallableUnitFragment fragment = (IInstallableUnitFragment) iuList.get(i);
+				IInstallableUnitFragment fragment = (IInstallableUnitFragment) possibleEclipse;
 				Collection<IProvidedCapability> providedCapability = fragment.getProvidedCapabilities();
 				verifyProvidedCapability(providedCapability, IInstallableUnit.NAMESPACE_IU_ID, flavorArg + idBase + ".executable." + confSpec, version); //$NON-NLS-1$
 				assertTrue(providedCapability.size() == 1);
@@ -161,8 +160,7 @@
 	}
 
 	private void verifyEclipseIU(ArrayList<IInstallableUnit> iuList, String idBase, String confSpec) {
-		for (int i = 0; i < iuList.size(); i++) {
-			IInstallableUnit possibleEclipse = iuList.get(i);
+		for (IInstallableUnit possibleEclipse : iuList) {
 			if (possibleEclipse.getId().equals((idBase + ".executable." + confSpec + "." + EXECUTABLE_NAME))) { //$NON-NLS-1$//$NON-NLS-2$
 				assertTrue(possibleEclipse.getVersion().equals(version));
 				Collection<IProvidedCapability> providedCapability = possibleEclipse.getProvidedCapabilities();
@@ -181,8 +179,7 @@
 		String _ws = config[0];
 		String _os = config[1];
 		String _arch = config[2];
-		for (int i = 0; i < iuList.size(); i++) {
-			IInstallableUnit possibleExec = iuList.get(i);
+		for (IInstallableUnit possibleExec : iuList) {
 			if (possibleExec.getId().equals(idBase + ".executable." + confSpec)) { //$NON-NLS-1$
 				//keep checking
 				assertTrue(possibleExec.getFilter().equals(InstallableUnit.parseFilter("(& (osgi.ws=" + _ws + ")(osgi.os=" + _os + ")(osgi.arch=" + _arch + "))"))); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/EquinoxLauncherCUActionTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/EquinoxLauncherCUActionTest.java
index 558bf7a..95442d1 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/EquinoxLauncherCUActionTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/EquinoxLauncherCUActionTest.java
@@ -67,10 +67,7 @@
 	}
 
 	private void verifyResults() {
-		ArrayList<IInstallableUnit> ius = new ArrayList<>(publisherResult.getIUs(null, null));
-		IInstallableUnit iu;
-		for (int i = 0; i < ius.size(); i++) {
-			iu = ius.get(i);
+		for (IInstallableUnit iu : new ArrayList<>(publisherResult.getIUs(null, null))) {
 			if (iu.getId().equals(flavorArg + EquinoxLauncherCUAction.ORG_ECLIPSE_EQUINOX_LAUNCHER)) {
 				assertTrue(iu instanceof InstallableUnitFragment);
 				//verify required capability
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/reconciler/dropins/ConfigurationTests.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/reconciler/dropins/ConfigurationTests.java
index e0564fe..e68e5d5 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/reconciler/dropins/ConfigurationTests.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/reconciler/dropins/ConfigurationTests.java
@@ -16,7 +16,6 @@
 import java.io.File;
 import java.io.IOException;
 import java.net.URISyntaxException;
-import java.util.Iterator;
 import junit.framework.Test;
 import junit.framework.TestSuite;
 import org.eclipse.equinox.internal.p2.update.*;
@@ -387,8 +386,7 @@
 		assertFalse("7.3", isInstalled("ccc", "1.0.0"));
 		assertFalse("7.4", isInstalled("bbb.feature.feature.group", "1.0.0"));
 		boolean found = false;
-		for (Iterator<Site> iter = getConfiguration().getSites().iterator(); iter.hasNext();) {
-			Site site = iter.next();
+		for (Site site : getConfiguration().getSites()) {
 			String link = site.getLinkFile();
 			if (link != null && link.contains("myLink"))
 				found = true;
diff --git a/bundles/org.eclipse.equinox.p2.ui.discovery/src/org/eclipse/equinox/internal/p2/ui/discovery/operations/DiscoveryInstallOperation.java b/bundles/org.eclipse.equinox.p2.ui.discovery/src/org/eclipse/equinox/internal/p2/ui/discovery/operations/DiscoveryInstallOperation.java
index e93fc97..6160d53 100644
--- a/bundles/org.eclipse.equinox.p2.ui.discovery/src/org/eclipse/equinox/internal/p2/ui/discovery/operations/DiscoveryInstallOperation.java
+++ b/bundles/org.eclipse.equinox.p2.ui.discovery/src/org/eclipse/equinox/internal/p2/ui/discovery/operations/DiscoveryInstallOperation.java
@@ -27,7 +27,8 @@
 import org.eclipse.equinox.p2.metadata.IInstallableUnit;
 import org.eclipse.equinox.p2.metadata.Version;
 import org.eclipse.equinox.p2.operations.*;
-import org.eclipse.equinox.p2.query.*;
+import org.eclipse.equinox.p2.query.IQuery;
+import org.eclipse.equinox.p2.query.QueryUtil;
 import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
 import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
 import org.eclipse.equinox.p2.ui.ProvisioningUI;
@@ -255,9 +256,7 @@
 		for (final IMetadataRepository repository : repositories) {
 			checkCancelled(monitor);
 			final Set<String> installableUnitIdsThisRepository = getDescriptorIds(repository);
-			IQueryResult<IInstallableUnit> result = repository.query(createInstalledIUsQuery(), monitor.newChild(1));
-			for (Iterator<IInstallableUnit> iter = result.iterator(); iter.hasNext();) {
-				IInstallableUnit iu = iter.next();
+			for (IInstallableUnit iu : repository.query(createInstalledIUsQuery(), monitor.newChild(1))) {
 				String id = iu.getId();
 				if (installableUnitIdsThisRepository.contains(id))
 					installableUnits.add(iu);
diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/actions/ExistingIUInProfileAction.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/actions/ExistingIUInProfileAction.java
index 38bfa1e..dbd5b36 100644
--- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/actions/ExistingIUInProfileAction.java
+++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/actions/ExistingIUInProfileAction.java
@@ -47,9 +47,9 @@
 		// referred to by the element itself..
 		IProfile profile = getProfile();
 		if (selectionArray.length > 0) {
-			for (int i = 0; i < selectionArray.length; i++) {
-				if (selectionArray[i] instanceof InstalledIUElement) {
-					InstalledIUElement element = (InstalledIUElement) selectionArray[i];
+			for (Object selection : selectionArray) {
+				if (selection instanceof InstalledIUElement) {
+					InstalledIUElement element = (InstalledIUElement) selection;
 					// If the parents are different, then they are either from 
 					// different profiles or are nested in different parts of the tree.
 					// Either way, this makes the selection invalid.
@@ -62,7 +62,7 @@
 					if (!isSelectable(element.getIU(), profile))
 						return false;
 				} else {
-					IInstallableUnit iu = ProvUI.getAdapter(selectionArray[i], IInstallableUnit.class);
+					IInstallableUnit iu = ProvUI.getAdapter(selection, IInstallableUnit.class);
 					if (iu == null || !isSelectable(iu))
 						return false;
 				}
diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/DelayedFilterCheckboxTree.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/DelayedFilterCheckboxTree.java
index 300ce8c..df44074 100644
--- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/DelayedFilterCheckboxTree.java
+++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/DelayedFilterCheckboxTree.java
@@ -282,10 +282,10 @@
 		if (checkState == null) {
 			checkState = new HashSet<>(checked.length);
 		}
-		for (int i = 0; i < checked.length; i++) {
-			if (!v.getGrayed(checked[i]) && contentProvider.getChildren(checked[i]).length == 0) {
-				if (!checkState.contains(checked[i])) {
-					checkState.add(checked[i]);
+		for (Object element : checked) {
+			if (!v.getGrayed(element) && contentProvider.getChildren(element).length == 0) {
+				if (!checkState.contains(element)) {
+					checkState.add(element);
 				}
 			}
 		}
diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/InstallWizard.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/InstallWizard.java
index 6a1dbe8..5f00533 100644
--- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/InstallWizard.java
+++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/InstallWizard.java
@@ -78,8 +78,8 @@
 		} else {
 			ArrayList<AvailableIUElement> list = new ArrayList<>(selectedElements.length);
 			ArrayList<AvailableIUElement> selections = new ArrayList<>(selectedElements.length);
-			for (int i = 0; i < selectedElements.length; i++) {
-				IInstallableUnit iu = ElementUtils.getIU(selectedElements[i]);
+			for (Object selectedElement : selectedElements) {
+				IInstallableUnit iu = ElementUtils.getIU(selectedElement);
 				if (iu != null) {
 					AvailableIUElement element = new AvailableIUElement(root, iu, getProfileId(), shouldShowProvisioningPlanChildren());
 					list.add(element);
diff --git a/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/ConfigApplier.java b/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/ConfigApplier.java
index 61999ce..eb18ada 100644
--- a/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/ConfigApplier.java
+++ b/bundles/org.eclipse.equinox.simpleconfigurator/src/org/eclipse/equinox/internal/simpleconfigurator/ConfigApplier.java
@@ -245,8 +245,8 @@
 			List<InputStream> sourceStreams = new ArrayList<>(sourcesLocation.size() + 1);
 			sourceStreams.add(url.openStream());
 			if (Activator.EXTENDED) {
-				for (int i = 0; i < sourcesLocation.size(); i++) {
-					sourceStreams.add(new FileInputStream(sourcesLocation.get(i)));
+				for (File source : sourcesLocation) {
+					sourceStreams.add(new FileInputStream(source));
 				}
 			}
 			SimpleConfiguratorUtils.transferStreams(sourceStreams, destinationStream);