Skip to content

Commit

Permalink
Replace Enumeration with Iterator
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Jungmann <[email protected]>
  • Loading branch information
lukasj committed Jan 30, 2024
1 parent 6c49784 commit a5cdf1d
Show file tree
Hide file tree
Showing 77 changed files with 595 additions and 632 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
public class Tests {

public static void main(String s) {
public static void main(String[] s) {
System.out.println("An artifact with tests only.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ public Vector cursoredStreamNextPage(RemoteCursoredStream remoteCursoredStream,
Vector<Object> clientNextPageObjects = serverNextPageObjects;
if (query.isReadAllQuery() && (!query.isReportQuery())) {// could be DataReadQuery
clientNextPageObjects = new Vector<>(serverNextPageObjects.size());
for (Enumeration<Object> objEnum = serverNextPageObjects.elements(); objEnum.hasMoreElements();) {
for (Iterator<Object> iterator = serverNextPageObjects.iterator(); iterator.hasNext();) {
// 2612538 - the default size of Map (32) is appropriate
Object clientObject = session.getObjectCorrespondingTo(objEnum.nextElement(), transporter.getObjectDescriptors(), new IdentityHashMap(), (ObjectLevelReadQuery)query);
Object clientObject = session.getObjectCorrespondingTo(iterator.next(), transporter.getObjectDescriptors(), new IdentityHashMap(), (ObjectLevelReadQuery)query);
clientNextPageObjects.addElement(clientObject);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

import java.rmi.RemoteException;
import java.rmi.server.ObjID;
import java.util.Enumeration;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;

Expand Down Expand Up @@ -201,9 +201,9 @@ public Vector cursoredStreamNextPage(RemoteCursoredStream remoteCursoredStream,
Vector<Object> clientNextPageObjects = serverNextPageObjects;
if (query.isReadAllQuery() && (!query.isReportQuery())) {// could be DataReadQuery
clientNextPageObjects = new Vector<>(serverNextPageObjects.size());
for (Enumeration<Object> objEnum = serverNextPageObjects.elements(); objEnum.hasMoreElements();) {
for (Iterator<Object> iterator = serverNextPageObjects.iterator(); iterator.hasNext();) {
// 2612538 - the default size of Map (32) is appropriate
Object clientObject = session.getObjectCorrespondingTo(objEnum.nextElement(), transporter.getObjectDescriptors(), new IdentityHashMap(), (ObjectLevelReadQuery)query);
Object clientObject = session.getObjectCorrespondingTo(iterator.next(), transporter.getObjectDescriptors(), new IdentityHashMap(), (ObjectLevelReadQuery)query);
clientNextPageObjects.addElement(clientObject);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import java.net.InetAddress;
import java.sql.Timestamp;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Vector;

/**
Expand Down Expand Up @@ -108,10 +108,10 @@ public void addSummary(TestResultsSummary summary) {
} else if (summaries.getValue() == null) {
summaries.setValue(new Vector<>());
}
for (Enumeration<TestResultsSummary> enumtr = getSummaries().elements(); enumtr.hasMoreElements();) {
TestResultsSummary element = enumtr.nextElement();
for (Iterator<TestResultsSummary> iterator = getSummaries().iterator(); iterator.hasNext();) {
TestResultsSummary element = iterator.next();
if (element.getName().equals(summary.getName())) {
getSummaries().removeElement(element);
iterator.remove();
}
}
getSummaries().addElement(summary);
Expand All @@ -122,21 +122,21 @@ public void computeNumberOfTestsAndErrors() {
numberOfTests = 0;
errors = 0;
fatalErrors = 0;
for (Enumeration<TestResultsSummary> enumtr = getSummaries().elements(); enumtr.hasMoreElements();) {
TestResultsSummary summary = enumtr.nextElement();
for (Iterator<TestResultsSummary> iterator = getSummaries().iterator(); iterator.hasNext();) {
TestResultsSummary summary = iterator.next();
if (summary.getParent() == null) {
rootSummaries.addElement(summary);
}
}
for (Enumeration<TestResultsSummary> enumtr = rootSummaries.elements(); enumtr.hasMoreElements();) {
TestResultsSummary summary = enumtr.nextElement();
for (Iterator<TestResultsSummary> iterator = rootSummaries.iterator(); iterator.hasNext();) {
TestResultsSummary summary = iterator.next();
numberOfTests += summary.getTotalTests();
errors += summary.getErrors();
fatalErrors += summary.getFatalErrors();
}

for (Enumeration<TestResult> enumtr = getResults().elements(); enumtr.hasMoreElements();) {
TestResult result = enumtr.nextElement();
for (Iterator<TestResult> iterator = getResults().iterator(); iterator.hasNext();) {
TestResult result = iterator.next();
if (result.hasError()) {
errors++;
} else if (result.hasFatalError()) {
Expand Down Expand Up @@ -178,17 +178,17 @@ public ValueHolderInterface<? extends Vector<TestResultsSummary>> getSummariesHo

public void initializeLoadBuild() {
if (getResults() != null) {
for (Enumeration<TestResult> enumtr = getResults().elements(); enumtr.hasMoreElements();) {
TestResult result = enumtr.nextElement();
for (Iterator<TestResult> iterator = getResults().iterator(); iterator.hasNext();) {
TestResult result = iterator.next();
result.setLoadBuildSummary(this);
}
}
if (getSummaries() != null) {
for (Enumeration<TestResultsSummary> enum1 = getSummaries().elements(); enum1.hasMoreElements();) {
TestResultsSummary summary = enum1.nextElement();
for (Iterator<TestResultsSummary> iterator1 = getSummaries().iterator(); iterator1.hasNext();) {
TestResultsSummary summary = iterator1.next();
summary.setLoadBuildSummary(this);
for (Enumeration<TestResult> enum2 = summary.getResults().elements(); enum2.hasMoreElements();) {
TestResult result = enum2.nextElement();
for (Iterator<TestResult> iterator = summary.getResults().iterator(); iterator.hasNext();) {
TestResult result = iterator.next();
result.setLoadBuildSummary(this);
}
}
Expand All @@ -213,17 +213,17 @@ public boolean isEmpty() {

public void setLoadBuildSummaryForTests() {
if (getResults() != null) {
for (Enumeration<TestResult> enumtr = getResults().elements(); enumtr.hasMoreElements();) {
TestResult result = enumtr.nextElement();
for (Iterator<TestResult> iterator = getResults().iterator(); iterator.hasNext();) {
TestResult result = iterator.next();
result.setLoadBuildSummary(this);
}
}
if (getSummaries() != null) {
for (Enumeration<TestResultsSummary> enum1 = getSummaries().elements(); enum1.hasMoreElements();) {
TestResultsSummary summary = enum1.nextElement();
for (Iterator<TestResultsSummary> iterator1 = getSummaries().iterator(); iterator1.hasNext();) {
TestResultsSummary summary = iterator1.next();
summary.setLoadBuildSummary(this);
for (Enumeration<TestResult> enum2 = summary.getResults().elements(); enum2.hasMoreElements();) {
TestResult result = enum2.nextElement();
for (Iterator<TestResult> iterator = summary.getResults().iterator(); iterator.hasNext();) {
TestResult result = iterator.next();
result.setLoadBuildSummary(this);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.io.Writer;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Vector;

/**
Expand Down Expand Up @@ -133,8 +134,8 @@ public void addSRGTests() {
* Adds a test collection to itself
*/
public final void addTests(Vector<? extends Test> theTests) {
for (Enumeration<? extends Test> allTests = theTests.elements(); allTests.hasMoreElements();) {
junit.framework.Test test = allTests.nextElement();
for (Iterator<? extends Test> iterator = theTests.iterator(); iterator.hasNext();) {
junit.framework.Test test = iterator.next();
addTest(test);
}
}
Expand Down Expand Up @@ -395,8 +396,8 @@ public void logResult(Writer log, boolean logOnlyErrors, boolean regression) {
logHeadNote(log);
}

for (Enumeration<Test> tests = getFinishedTests().elements(); tests.hasMoreElements();) {
junit.framework.Test test = tests.nextElement();
for (Iterator<Test> iterator = getFinishedTests().iterator(); iterator.hasNext();) {
junit.framework.Test test = iterator.next();
if (test instanceof TestEntity testEntity) {
if (regression) {
if (!(testEntity instanceof TestCase) || !(testEntity.getReport().hasPassed() || ((TestResult)testEntity.getReport()).hasWarning())) {
Expand Down Expand Up @@ -427,8 +428,8 @@ public void logResult(Writer log, boolean logOnlyErrors, boolean regression) {
*/
public void computeResultSummary() {
getSummary().resetTotals();
for (Enumeration<Test> tests = getFinishedTests().elements(); tests.hasMoreElements();) {
junit.framework.Test test = tests.nextElement();
for (Iterator<Test> iterator = getFinishedTests().iterator(); iterator.hasNext();) {
junit.framework.Test test = iterator.next();
if (test instanceof TestCase testEntity) {
testEntity.appendTestResult(getSummary());
} else if (test instanceof TestCollection testEntity) {
Expand Down Expand Up @@ -462,8 +463,8 @@ public boolean requiresDatabase() {
@Override
public void resetNestedCounter() {
setNestedCounter(INITIAL_VALUE);
for (Enumeration<Test> tests = getTests().elements(); tests.hasMoreElements();) {
Object test = tests.nextElement();
for (Iterator<Test> iterator = getTests().iterator(); iterator.hasNext();) {
Object test = iterator.next();
if (test instanceof TestEntity) {
((TestEntity)test).resetNestedCounter();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import java.util.Vector;

Expand Down Expand Up @@ -183,8 +184,8 @@ public void addConfigureSystem(TestSystem system) {
* The access other model to reuse their to setup.
*/
public void addLoadedModels(Vector<TestModel> models) {
for (Enumeration<TestModel>theModels = models.elements(); theModels.hasMoreElements();) {
TestModel model = theModels.nextElement();
for (Iterator<TestModel> iterator = models.iterator(); iterator.hasNext();) {
TestModel model = iterator.next();
getLoadedModels().put(model.getName(), model);
}
}
Expand All @@ -204,9 +205,9 @@ public void configureSystem(TestSystem system) throws Exception {
* Return true if the configuredSystems contains an instance of the class of the TestSystem parameter.
*/
public boolean configuredSystemsContainsInstanceOf(TestSystem system) {
for (Enumeration<TestSystem> configuredSystemsEnum = getConfiguredSystems().elements();
configuredSystemsEnum.hasMoreElements();) {
if (configuredSystemsEnum.nextElement().getClass().equals(system.getClass())) {
for (Iterator<TestSystem> iterator = getConfiguredSystems().iterator();
iterator.hasNext();) {
if (iterator.next().getClass().equals(system.getClass())) {
return true;
}
}
Expand Down Expand Up @@ -643,18 +644,18 @@ public void removeConfigureSystem(TestSystem system) {
public void removeFromConfiguredSystemsInstanceOf(TestSystem system) {
// find and record the systems to remove
Vector<TestSystem> systemsToRemove = new Vector<>();
for (Enumeration<TestSystem> systemEnum = getConfiguredSystems().elements();
systemEnum.hasMoreElements();) {
TestSystem aSystem = systemEnum.nextElement();
for (Iterator<TestSystem> iterator = getConfiguredSystems().iterator();
iterator.hasNext();) {
TestSystem aSystem = iterator.next();
if (aSystem.getClass().equals(system.getClass())) {
systemsToRemove.addElement(aSystem);
}
}

// Do the removing
for (Enumeration<TestSystem> systemsToRemoveEnum = systemsToRemove.elements();
systemsToRemoveEnum.hasMoreElements();) {
getConfiguredSystems().removeElement(systemsToRemoveEnum.nextElement());
for (Iterator<TestSystem> iterator = systemsToRemove.iterator();
iterator.hasNext();) {
getConfiguredSystems().removeElement(iterator.next());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.io.IOException;
import java.io.Writer;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Vector;
import java.util.concurrent.ConcurrentHashMap;

Expand Down Expand Up @@ -180,8 +181,8 @@ public Vector<TestSystem> buildRequiredSystems() {
private void configure() throws Exception {
Vector<TestSystem> systems = buildRequiredSystems();

for (Enumeration<TestSystem> enumtr = systems.elements(); enumtr.hasMoreElements();) {
TestSystem system = enumtr.nextElement();
for (Iterator<TestSystem> iterator = systems.iterator(); iterator.hasNext();) {
TestSystem system = iterator.next();

// To improve test consistency always force systems to be reset.
if (shouldResetSystemAfterEachTestModel()) {
Expand All @@ -193,8 +194,8 @@ private void configure() throws Exception {

systems = buildForcedRequiredSystems();

for (Enumeration<TestSystem> enumtr = systems.elements(); enumtr.hasMoreElements();) {
TestSystem system = enumtr.nextElement();
for (Iterator<TestSystem> iterator = systems.iterator(); iterator.hasNext();) {
TestSystem system = iterator.next();
getExecutor().forceConfigureSystem(system);
}
}
Expand All @@ -211,8 +212,8 @@ public void execute(TestExecutor executor) throws Throwable {
setupEntity();
setFinishedTests(new Vector<>());
try {
for (Enumeration<Test> tests = getTests().elements(); tests.hasMoreElements();) {
junit.framework.Test test = tests.nextElement();
for (Iterator<Test> iterator = getTests().iterator(); iterator.hasNext();) {
junit.framework.Test test = iterator.next();
if ((TestExecutor.getDefaultJUnitTestResult() != null) && TestExecutor.getDefaultJUnitTestResult().shouldStop()) {
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import java.io.IOException;
import java.io.Writer;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Vector;

/**
Expand Down Expand Up @@ -81,8 +81,8 @@ public void execute(TestExecutor executor) throws Throwable {
System.out.println("Running " + getSummary().getName());
}
long startTime = System.nanoTime();
for (Enumeration<Test> tests = getTests().elements(); tests.hasMoreElements();) {
junit.framework.Test test = tests.nextElement();
for (Iterator<Test> iterator = getTests().iterator(); iterator.hasNext();) {
junit.framework.Test test = iterator.next();
if ((TestExecutor.getDefaultJUnitTestResult() != null) && TestExecutor.getDefaultJUnitTestResult().shouldStop()) {
break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -28,7 +28,7 @@
import org.eclipse.persistence.tools.schemaframework.SchemaManager;
import org.eclipse.persistence.tools.schemaframework.TableDefinition;

import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map;
import java.util.Vector;

Expand Down Expand Up @@ -88,22 +88,22 @@ public void createTables() throws Exception {
public void createTables(DatabaseSession session) throws Exception {
Vector<TableDefinition> tables = buildTables();
SchemaManager schemaManager = new SchemaManager(session);
for (Enumeration<TableDefinition> dropForeignKeyEnum = tables.elements();
dropForeignKeyEnum.hasMoreElements();) {
TableDefinition table = dropForeignKeyEnum.nextElement();
for (Iterator<TableDefinition> iterator = tables.iterator();
iterator.hasNext();) {
TableDefinition table = iterator.next();
try {
schemaManager.dropConstraints(table);
} catch (DatabaseException exception) {
// Ignore
}
}
for (Enumeration<TableDefinition> replaceEnum = tables.elements(); replaceEnum.hasMoreElements();) {
TableDefinition table = replaceEnum.nextElement();
for (Iterator<TableDefinition> iterator = tables.iterator(); iterator.hasNext();) {
TableDefinition table = iterator.next();
schemaManager.replaceObject(table);
}
for (Enumeration<TableDefinition> createForeignKeyEnum = tables.elements();
createForeignKeyEnum.hasMoreElements();) {
TableDefinition table = createForeignKeyEnum.nextElement();
for (Iterator<TableDefinition> iterator = tables.iterator();
iterator.hasNext();) {
TableDefinition table = iterator.next();
schemaManager.createConstraints(table);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Vector;

/**
Expand Down Expand Up @@ -65,9 +65,9 @@ public static Vector<TestCase> get(Object object, String str, Vector<TestCase> t
getMembers(object.getClass(), names, getters, setters, fields, true);
int numberOfTests = (int)java.lang.Math.pow(2, names.size());
for (int i = 0; i < numberOfTests; i++) {
Enumeration<TestCase> enumtr = testsIn.elements();
while (enumtr.hasMoreElements()) {
TestWrapper testWrapper = createTest(i, object, names, getters, setters, fields, enumtr.nextElement());
Iterator<TestCase> iterator = testsIn.iterator();
while (iterator.hasNext()) {
TestWrapper testWrapper = createTest(i, object, names, getters, setters, fields, iterator.next());
testsOut.addElement(testWrapper);
}
}
Expand Down
Loading

0 comments on commit a5cdf1d

Please sign in to comment.