diff options
author | Carsten Hammer | 2019-11-20 19:06:13 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2019-12-11 15:28:48 +0000 |
commit | 10ae1613f5f13a85ab86a52b7259c42d0cd41eca (patch) | |
tree | 890e59f7682e4e67f531ef8e62e64cefe646f6ca | |
parent | e5cf1508417c3c563dab9e5583dfeaac8865d9aa (diff) | |
download | rt.equinox.p2-10ae1613f5f13a85ab86a52b7259c42d0cd41eca.tar.gz rt.equinox.p2-10ae1613f5f13a85ab86a52b7259c42d0cd41eca.tar.xz rt.equinox.p2-10ae1613f5f13a85ab86a52b7259c42d0cd41eca.zip |
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: I68b50b917c924907f63fd58831535da490b5ef86
Signed-off-by: Carsten Hammer <carsten.hammer@t-online.de>
20 files changed, 89 insertions, 104 deletions
diff --git a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/ParserUtils.java b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/ParserUtils.java index 1c17cbfc4..e9a245a1c 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/ParserUtils.java +++ b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/ParserUtils.java @@ -131,10 +131,10 @@ public class ParserUtils { public static boolean isArgumentSet(String arg, List<String> args) { if (arg == null || args == null) return false; - for (int i = 0; i < args.size(); i++) { - if (args.get(i) == null) + for (String arg2 : args) { + if (arg2 == null) continue; - if ((args.get(i)).equalsIgnoreCase(arg)) { + if ((arg2).equalsIgnoreCase(arg)) { return true; } } diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/OptimizationFunction.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/OptimizationFunction.java index 34015e6c6..51050fb7c 100644 --- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/OptimizationFunction.java +++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/OptimizationFunction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2018 Rapicorp Inc. and others. + * Copyright (c) 2013, 2018 Rapicorp Inc. and others. * * This * program and the accompanying materials are made available under the terms of @@ -9,7 +9,7 @@ * * SPDX-License-Identifier: EPL-2.0 * - * Contributors: + * Contributors: * Rapicorp, Inc. - initial API and implementation ******************************************************************************/ package org.eclipse.equinox.internal.p2.director; @@ -110,12 +110,10 @@ public class OptimizationFunction { //Now we deal the optional IUs, long countOptional = 1; List<IInstallableUnit> requestedPatches = new ArrayList<>(); - Collection<IRequirement> reqs = metaIu.getRequirements(); - for (IRequirement req : reqs) { + for (IRequirement req : metaIu.getRequirements()) { if (req.getMin() > 0 || !req.isGreedy()) continue; - IQueryResult<IInstallableUnit> matches = picker.query(QueryUtil.createMatchQuery(req.getMatches()), null); - for (IInstallableUnit match : matches) { + for (IInstallableUnit match : picker.query(QueryUtil.createMatchQuery(req.getMatches()), null)) { if (match instanceof IInstallableUnitPatch) { requestedPatches.add(match); countOptional = countOptional + 1; @@ -125,8 +123,8 @@ public class OptimizationFunction { // and we make sure that patches are always favored BigInteger patchWeight = maxWeight.multiply(POWER).multiply(BigInteger.valueOf(countOptional)).negate(); - for (Iterator<IInstallableUnit> iterator = requestedPatches.iterator(); iterator.hasNext();) { - weightedObjects.add(WeightedObject.newWO(iterator.next(), patchWeight)); + for (IInstallableUnit iu : requestedPatches) { + weightedObjects.add(WeightedObject.newWO(iu, patchWeight)); } return weightedObjects; } diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/MetadataWriter.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/MetadataWriter.java index 95036613e..c60e29bf2 100644 --- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/MetadataWriter.java +++ b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/MetadataWriter.java @@ -233,8 +233,8 @@ public class MetadataWriter extends XMLWriter implements XMLConstants { protected void writeRequirementsChange(List<IRequirementChange> changes) { start(REQUIREMENT_CHANGES); - for (int i = 0; i < changes.size(); i++) { - writeRequirementChange(changes.get(i)); + for (IRequirementChange change : changes) { + writeRequirementChange(change); } end(REQUIREMENT_CHANGES); } diff --git a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/Member.java b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/Member.java index 0d29c650f..16079f8ea 100644 --- a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/Member.java +++ b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/Member.java @@ -172,8 +172,8 @@ public abstract class Member extends Unary { @Override public boolean accept(IExpressionVisitor visitor) { if (super.accept(visitor)) - for (int idx = 0; idx < argExpressions.length; ++idx) - if (!argExpressions[idx].accept(visitor)) + for (Expression expression : argExpressions) + if (!expression.accept(visitor)) return false; return true; } diff --git a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/NAry.java b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/NAry.java index 22a4df85b..c43285377 100644 --- a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/NAry.java +++ b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/NAry.java @@ -28,8 +28,8 @@ public abstract class NAry extends Expression { @Override public boolean accept(IExpressionVisitor visitor) { if (super.accept(visitor)) - for (int idx = 0; idx < operands.length; ++idx) - if (!operands[idx].accept(visitor)) + for (Expression operand : operands) + if (!operand.accept(visitor)) return false; return true; } @@ -69,8 +69,8 @@ public abstract class NAry extends Expression { @Override int countAccessToEverything() { int cnt = 0; - for (int idx = 0; idx < operands.length; ++idx) - cnt += operands[idx].countAccessToEverything(); + for (Expression operand : operands) + cnt += operand.countAccessToEverything(); return cnt; } } diff --git a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/Or.java b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/Or.java index e6b159ad8..a42110bd5 100644 --- a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/Or.java +++ b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/Or.java @@ -26,8 +26,8 @@ final class Or extends NAry { @Override public Object evaluate(IEvaluationContext context) { - for (int idx = 0; idx < operands.length; ++idx) { - if (operands[idx].evaluate(context) == Boolean.TRUE) + for (Expression operand : operands) { + if (operand.evaluate(context) == Boolean.TRUE) return Boolean.TRUE; } return Boolean.FALSE; @@ -51,8 +51,8 @@ final class Or extends NAry { @Override public void toLDAPString(StringBuffer buf) { buf.append("(|"); //$NON-NLS-1$ - for (int idx = 0; idx < operands.length; ++idx) - operands[idx].toLDAPString(buf); + for (Expression operand : operands) + operand.toLDAPString(buf); buf.append(')'); } } diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/JarComparator.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/JarComparator.java index da9914a31..dab298fb7 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/JarComparator.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/JarComparator.java @@ -330,8 +330,8 @@ public class JarComparator implements IArtifactComparator { return newErrorStatus(NLS.bind(Messages.propertiesSizesDifferent, entryName, String.valueOf(Math.abs(props1.size() - props2.size())))); props1.keys(); - for (Iterator<Object> iterator = props1.keySet().iterator(); iterator.hasNext();) { - String key = (String) iterator.next(); + for (Object object : props1.keySet()) { + String key = (String) object; if (!props2.containsKey(key)) return newErrorStatus(NLS.bind(Messages.missingProperty, key, entryName)); String prop1 = props1.getProperty(key); @@ -396,8 +396,7 @@ public class JarComparator implements IArtifactComparator { private String normalize(String entryName) { StringBuffer buffer = new StringBuffer(); char[] chars = entryName.toCharArray(); - for (int i = 0, max = chars.length; i < max; i++) { - char currentChar = chars[i]; + for (char currentChar : chars) { if (!Character.isJavaIdentifierPart(currentChar)) { buffer.append('_'); } else { diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java index 3a918b62e..d09ea5084 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java @@ -231,8 +231,7 @@ public class MirrorApplication extends AbstractApplication implements IApplicati IQueryResult<IInstallableUnit> ius = slice.query(QueryUtil.createIUAnyQuery(), monitor); boolean iusSpecified = !ius.isEmpty(); // call before ius.iterator() to avoid bug 420318 ArrayList<IArtifactKey> keys = new ArrayList<>(); - for (Iterator<IInstallableUnit> iterator = ius.iterator(); iterator.hasNext();) { - IInstallableUnit iu = iterator.next(); + for (IInstallableUnit iu : ius) { keys.addAll(iu.getArtifacts()); } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ant/MirrorTaskTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ant/MirrorTaskTest.java index 1f4146d07..a97ca935a 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ant/MirrorTaskTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ant/MirrorTaskTest.java @@ -24,7 +24,6 @@ import java.net.URISyntaxException; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; import java.util.Properties; import java.util.zip.ZipEntry; @@ -854,8 +853,8 @@ public class MirrorTaskTest extends AbstractAntProvisioningTest { */ protected int getArtifactKeyCount(IQueryResult<IInstallableUnit> ius) { int count = 0; - for (Iterator<IInstallableUnit> iter = ius.iterator(); iter.hasNext();) - count += iter.next().getArtifacts().size(); + for (IInstallableUnit iu : ius) + count += iu.getArtifacts().size(); return count; } @@ -877,8 +876,7 @@ public class MirrorTaskTest extends AbstractAntProvisioningTest { protected void addAllIUs(AntTaskElement parent, IMetadataRepository repo) { IQueryResult<IInstallableUnit> queryResult = repo.query(QueryUtil.createIUAnyQuery(), null); - for (Iterator<IInstallableUnit> iter = queryResult.iterator(); iter.hasNext();) { - IInstallableUnit iu = iter.next(); + for (IInstallableUnit iu : queryResult) { parent.addElement(createIUElement(iu)); } } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/MD5Tests.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/MD5Tests.java index 1e8808a8f..44d7a1e6a 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/MD5Tests.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/MD5Tests.java @@ -15,7 +15,6 @@ package org.eclipse.equinox.p2.tests.artifact.repository; import java.io.ByteArrayOutputStream; import java.io.File; -import java.util.Iterator; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.equinox.internal.p2.metadata.ArtifactKey; @@ -40,8 +39,7 @@ public class MD5Tests extends AbstractProvisioningTest { public void DISABLE_testCheckMD5() { IQueryResult<IArtifactDescriptor> descriptors = repo.descriptorQueryable().query(ArtifactDescriptorQuery.ALL_DESCRIPTORS, null); - for (Iterator<IArtifactDescriptor> iterator = descriptors.iterator(); iterator.hasNext();) { - IArtifactDescriptor desc = iterator.next(); + for (IArtifactDescriptor desc : descriptors) { IStatus status = repo.getArtifact(desc, new ByteArrayOutputStream(500), new NullProgressMonitor()); //All artifacts that are expected to fail MD5 check are those whose id starts with bogus if (desc.getArtifactKey().getId().startsWith("bogus")) { diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/director/OperationGenerationTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/director/OperationGenerationTest.java index 84d30c9fb..a8c5524cc 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/director/OperationGenerationTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/director/OperationGenerationTest.java @@ -246,9 +246,9 @@ public class OperationGenerationTest extends AbstractProvisioningTest { new OperationGenerator(plan).generateOperation(from, to); List<Operand> operands = Arrays.asList(plan.getOperands()); //We are uninstalling myBundle 1.0 and 2.0. 3.0 stays unchanged. - for (int i = 0; i < operands.size(); i++) { - assertNotSame("3.0", three, ((InstallableUnitOperand) operands.get(i)).first()); - assertNotSame("3.0.1", three, ((InstallableUnitOperand) operands.get(i)).second()); + for (Operand operand : operands) { + assertNotSame("3.0", three, ((InstallableUnitOperand) operand).first()); + assertNotSame("3.0.1", three, ((InstallableUnitOperand) operand).second()); } assertEquals("3.1", one, ((InstallableUnitOperand) operands.get(0)).first()); assertNull("3.2", ((InstallableUnitOperand) operands.get(0)).second()); @@ -278,9 +278,9 @@ public class OperationGenerationTest extends AbstractProvisioningTest { new OperationGenerator(plan).generateOperation(from, to); List<Operand> operands = Arrays.asList(plan.getOperands()); //Two is already in the system therefore it will not be in the operands - for (int i = 0; i < operands.size(); i++) { - assertNotSame("2.0", two, ((InstallableUnitOperand) operands.get(i)).first()); - assertNotSame("2.1", two, ((InstallableUnitOperand) operands.get(i)).second()); + for (Operand operand : operands) { + assertNotSame("2.0", two, ((InstallableUnitOperand) operand).first()); + assertNotSame("2.1", two, ((InstallableUnitOperand) operand).second()); } //three is an update of one assertEquals("2.2", 1, operands.size()); @@ -311,9 +311,9 @@ public class OperationGenerationTest extends AbstractProvisioningTest { new OperationGenerator(plan).generateOperation(from, to); List<Operand> operands = Arrays.asList(plan.getOperands()); //Two is already in the system therefore it will not be in the operands - for (int i = 0; i < operands.size(); i++) { - assertNotSame("2.0", two, ((InstallableUnitOperand) operands.get(i)).first()); - assertNotSame("2.1", two, ((InstallableUnitOperand) operands.get(i)).second()); + for (Operand operand : operands) { + assertNotSame("2.0", two, ((InstallableUnitOperand) operand).first()); + assertNotSame("2.1", two, ((InstallableUnitOperand) operand).second()); } //We install three and uninstall one assertEquals("2.2", 2, operands.size()); @@ -374,10 +374,10 @@ public class OperationGenerationTest extends AbstractProvisioningTest { } private void assertContainsInstallableUnitOperand(String message, List<Operand> operands, InstallableUnitOperand operand) { - for (int i = 0; i < operands.size(); i++) { - if (!(operands.get(i) instanceof InstallableUnitOperand)) + for (Operand op : operands) { + if (!(op instanceof InstallableUnitOperand)) continue; - InstallableUnitOperand cmp = (InstallableUnitOperand) operands.get(i); + InstallableUnitOperand cmp = (InstallableUnitOperand) op; if (cmp.first() != null && cmp.first().equals(operand.first()) && cmp.second() != null && cmp.second().equals(operand.second())) return; } @@ -505,10 +505,10 @@ public class OperationGenerationTest extends AbstractProvisioningTest { } public void assertContainsConfigurationChange(String message, List<Operand> operands) { - for (int i = 0; i < operands.size(); i++) { - if (!(operands.get(i) instanceof InstallableUnitOperand)) + for (Operand operand : operands) { + if (!(operand instanceof InstallableUnitOperand)) continue; - InstallableUnitOperand op = (InstallableUnitOperand) operands.get(i); + InstallableUnitOperand op = (InstallableUnitOperand) operand; if (op.first() != null && op.first().equals(op.second())) { return; } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/IUPersistenceTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/IUPersistenceTest.java index c777ddccb..718fd3c1c 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/IUPersistenceTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/IUPersistenceTest.java @@ -19,7 +19,6 @@ import java.io.StringReader; import java.net.URI; import java.util.ArrayList; import java.util.Collection; -import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -271,23 +270,23 @@ public class IUPersistenceTest extends AbstractProvisioningTest { } private static String[][] extractRequires(IInstallableUnit iu) { - Collection<IRequirement> requyres = iu.getRequirements(); - String[][] tuples = new String[requyres.size()][4]; + Collection<IRequirement> requirements = iu.getRequirements(); + String[][] tuples = new String[requirements.size()][4]; int i = 0; - for (Iterator<IRequirement> iterator = requyres.iterator(); iterator.hasNext();) { - IRequiredCapability next = (IRequiredCapability) iterator.next(); - tuples[i++] = new String[] {next.getNamespace(), next.getName(), next.getRange().toString(), Boolean.valueOf(next.getMin() == 0).toString()}; + for (IRequirement requirement : requirements) { + IRequiredCapability capability = (IRequiredCapability) requirement; + tuples[i++] = new String[] {capability.getNamespace(), capability.getName(), capability.getRange().toString(), Boolean.valueOf(capability.getMin() == 0).toString()}; } return tuples; } private static String[][] extractMetaRequires(IInstallableUnit iu) { - Collection<IRequirement> requyres = iu.getMetaRequirements(); - String[][] tuples = new String[requyres.size()][4]; + Collection<IRequirement> requirements = iu.getMetaRequirements(); + String[][] tuples = new String[requirements.size()][4]; int i = 0; - for (IRequirement iRequirement : requyres) { - IRequiredCapability next = (IRequiredCapability) iRequirement; - tuples[i++] = new String[] {next.getNamespace(), next.getName(), next.getRange().toString(), Boolean.valueOf(next.getMin() == 0).toString()}; + for (IRequirement requirement : requirements) { + IRequiredCapability capability = (IRequiredCapability) requirement; + tuples[i++] = new String[] {capability.getNamespace(), capability.getName(), capability.getRange().toString(), Boolean.valueOf(capability.getMin() == 0).toString()}; } return tuples; } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/MetadataRepositoryManagerExceptionsTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/MetadataRepositoryManagerExceptionsTest.java index 5184b2e32..74722e340 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/MetadataRepositoryManagerExceptionsTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/MetadataRepositoryManagerExceptionsTest.java @@ -17,7 +17,6 @@ import java.io.File; import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import junit.framework.Test; import junit.framework.TestSuite; @@ -52,8 +51,9 @@ public class MetadataRepositoryManagerExceptionsTest extends AbstractProvisionin @Override protected void tearDown() throws Exception { super.tearDown(); - for (Iterator<File> it = toDelete.iterator(); it.hasNext();) - delete(it.next()); + for (File file : toDelete) { + delete(file); + } toDelete.clear(); } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/MetadataRepositoryManagerTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/MetadataRepositoryManagerTest.java index 1aaa7a533..2b4ebef6a 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/MetadataRepositoryManagerTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/MetadataRepositoryManagerTest.java @@ -21,7 +21,6 @@ import java.lang.reflect.Field; import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import junit.framework.Test; import junit.framework.TestSuite; @@ -78,8 +77,9 @@ public class MetadataRepositoryManagerTest extends AbstractProvisioningTest { @Override protected void tearDown() throws Exception { super.tearDown(); - for (Iterator<File> it = toDelete.iterator(); it.hasNext();) - delete(it.next()); + for (File file : toDelete) { + delete(file); + } toDelete.clear(); FailingMetadataRepositoryFactory.FAIL = false; } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/NewMirrorApplicationArtifactTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/NewMirrorApplicationArtifactTest.java index 4a9719f50..37d2b4927 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/NewMirrorApplicationArtifactTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/NewMirrorApplicationArtifactTest.java @@ -954,12 +954,8 @@ public class NewMirrorApplicationArtifactTest extends AbstractProvisioningTest { fail(""); } - IQueryResult<IArtifactKey> keys = packedRepo.query(ArtifactKeyQuery.ALL_KEYS, null); - for (Iterator<IArtifactKey> iterator = keys.iterator(); iterator.hasNext();) { - IArtifactKey key = iterator.next(); - IArtifactDescriptor[] srcDescriptors = packedRepo.getArtifactDescriptors(key); - - for (IArtifactDescriptor srcDescriptor : srcDescriptors) { + for (IArtifactKey key : packedRepo.query(ArtifactKeyQuery.ALL_KEYS, null)) { + for (IArtifactDescriptor srcDescriptor : packedRepo.getArtifactDescriptors(key)) { if (!(srcDescriptor.getProperty(IArtifactDescriptor.FORMAT) == null) && srcDescriptor.getProperty(IArtifactDescriptor.FORMAT).equals(IArtifactDescriptor.FORMAT_PACKED)) { //if we have a packed artifact IArtifactDescriptor newDescriptor = new ArtifactDescriptor(key); diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/NonMinimalState.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/NonMinimalState.java index 3d021e50e..e24f54d0d 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/NonMinimalState.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/NonMinimalState.java @@ -15,13 +15,18 @@ package org.eclipse.equinox.p2.tests.planner; import java.io.File; import java.net.URI; -import java.util.*; +import java.util.HashSet; +import java.util.Set; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.equinox.internal.p2.director.ProfileChangeRequest; import org.eclipse.equinox.internal.p2.engine.SimpleProfileRegistry; -import org.eclipse.equinox.p2.engine.*; +import org.eclipse.equinox.p2.engine.IProfile; +import org.eclipse.equinox.p2.engine.IProvisioningPlan; +import org.eclipse.equinox.p2.engine.ProvisioningContext; import org.eclipse.equinox.p2.engine.query.IUProfilePropertyQuery; -import org.eclipse.equinox.p2.metadata.*; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.metadata.IInstallableUnitFragment; +import org.eclipse.equinox.p2.metadata.IRequirement; import org.eclipse.equinox.p2.planner.IPlanner; import org.eclipse.equinox.p2.query.IQueryResult; import org.eclipse.equinox.p2.query.QueryUtil; @@ -76,8 +81,7 @@ public class NonMinimalState extends AbstractProvisioningTest { visited = new HashSet<>(); IQueryResult<IInstallableUnit> roots = profile.query(new IUProfilePropertyQuery("org.eclipse.equinox.p2.type.root", "true"), null); searchedId = id; - for (Iterator<IInstallableUnit> iterator = roots.iterator(); iterator.hasNext();) { - IInstallableUnit type = iterator.next(); + for (IInstallableUnit type : roots) { if (type instanceof IInstallableUnitFragment) { visited.add(type); continue; @@ -93,8 +97,7 @@ public class NonMinimalState extends AbstractProvisioningTest { visited.add(iu); return false; } - Collection<IRequirement> reqs = iu.getRequirements(); - for (IRequirement req : reqs) { + for (IRequirement req : iu.getRequirements()) { boolean result = expandRequirement(iu, req); if (result) { System.out.println(iu + " because " + req.toString()); @@ -105,9 +108,7 @@ public class NonMinimalState extends AbstractProvisioningTest { } private boolean expandRequirement(IInstallableUnit iu, IRequirement req) { - IQueryResult<IInstallableUnit> matches = profile.query(QueryUtil.createMatchQuery(req.getMatches()), null); - for (Iterator<IInstallableUnit> iterator = matches.iterator(); iterator.hasNext();) { - IInstallableUnit match = iterator.next(); + for (IInstallableUnit match : profile.query(QueryUtil.createMatchQuery(req.getMatches()), null)) { if (match.getId().equals(searchedId)) return true; if (!visited.contains(match)) { diff --git a/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/migration/MigrationPage.java b/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/migration/MigrationPage.java index 25b911a93..8a52a05e5 100644 --- a/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/migration/MigrationPage.java +++ b/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/migration/MigrationPage.java @@ -893,9 +893,7 @@ public class MigrationPage extends WizardPage implements ISelectableIUsPage, Lis SubMonitor sub = SubMonitor.convert(monitor, 1000); IQueryable<IInstallableUnit> queryable = context.getMetadata(sub.newChild(500)); - IQueryResult<IInstallableUnit> matches = queryable.query(new UpdateQuery(toUpdate), sub.newChild(500)); - for (Iterator<IInstallableUnit> it = matches.iterator(); it.hasNext();) { - IInstallableUnit iu = it.next(); + for (IInstallableUnit iu : queryable.query(new UpdateQuery(toUpdate), sub.newChild(500))) { String key = iu.getId() + "_" + iu.getVersion().toString(); //$NON-NLS-1$ IInstallableUnit currentIU = resultsMap.get(key); if (currentIU == null || hasHigherFidelity(iu, currentIU)) diff --git a/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/migration/MigrationWizard.java b/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/migration/MigrationWizard.java index 03f1b4f4e..37848bae8 100644 --- a/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/migration/MigrationWizard.java +++ b/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/migration/MigrationWizard.java @@ -146,11 +146,10 @@ public class MigrationWizard extends InstallWizard implements IImportWizard { private void cleanupProfileRegistry() { IProfileRegistry registry = ProvisioningUI.getDefaultUI().getSession().getProvisioningAgent() .getService(IProfileRegistry.class); - long[] history = registry.listProfileTimestamps(toImportFrom.getProfileId()); - for (int i = 0; i < history.length; i++) { - if (history[i] < toImportFrom.getTimestamp()) + for (long timestamp : registry.listProfileTimestamps(toImportFrom.getProfileId())) { + if (timestamp < toImportFrom.getTimestamp()) try { - registry.removeProfile(toImportFrom.getProfileId(), history[i]); + registry.removeProfile(toImportFrom.getProfileId(), timestamp); } catch (ProvisionException e) { // Can't happen } diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/viewers/IUComparator.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/viewers/IUComparator.java index 944dec2d3..aa78321ea 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/viewers/IUComparator.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/viewers/IUComparator.java @@ -7,7 +7,7 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 - * + * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ @@ -30,18 +30,18 @@ public class IUComparator extends ViewerComparator { } /** - * Use the specified column config to determine - * whether the id should be used in lieu of an empty name - * when sorting. - * - * @param columnConfig + * Use the specified column config to determine whether the id should be used in + * lieu of an empty name when sorting. + * + * @param columnConfigs */ - public void useColumnConfig(IUColumnConfig[] columnConfig) { - for (int i = 0; i < columnConfig.length; i++) - if (columnConfig[i].getColumnType() == IUColumnConfig.COLUMN_ID) { + public void useColumnConfig(IUColumnConfig[] columnConfigs) { + for (IUColumnConfig columnConfig : columnConfigs) { + if (columnConfig.getColumnType() == IUColumnConfig.COLUMN_ID) { showingId = true; break; } + } } @Override @@ -56,7 +56,7 @@ public class IUComparator extends ViewerComparator { if (key == IU_NAME) { // Compare the iu names in the default locale. // If a name is not defined, we use blank if we know the id is shown in another - // column. If the id is not shown elsewhere, then we are displaying it, so use + // column. If the id is not shown elsewhere, then we are displaying it, so use // the id instead. key1 = iu1.getProperty(IInstallableUnit.PROP_NAME, null); if (key1 == null) diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/viewers/IUDragAdapter.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/viewers/IUDragAdapter.java index cc071c6ef..92fb9cd0b 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/viewers/IUDragAdapter.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/viewers/IUDragAdapter.java @@ -65,8 +65,8 @@ public class IUDragAdapter extends DragSourceAdapter { // Get a text description of each IU and set as the drag data final StringBuilder buffer = new StringBuilder(); - for (int i = 0; i < ius.length; i++) { - buffer.append(ius[i].toString()); + for (IInstallableUnit iu : ius) { + buffer.append(iu.toString()); buffer.append('\n'); } event.data = buffer.toString(); |