This is an automated email from the ASF dual-hosted git repository. epugh pushed a commit to branch branch_9x in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/branch_9x by this push: new 88eb816ce43 SOLR-16280: simplify for-loops in tests (#929) 88eb816ce43 is described below commit 88eb816ce438c65d5a7aee91f175cd179e79add1 Author: Eric Pugh <ep...@opensourceconnections.com> AuthorDate: Thu Jul 7 08:21:32 2022 -0400 SOLR-16280: simplify for-loops in tests (#929) Co-authored-by: Christine Poerschke <cpoersc...@apache.org> --- .../org/apache/solr/BasicFunctionalityTest.java | 10 +++---- .../org/apache/solr/TestDistributedSearch.java | 3 +- .../org/apache/solr/cloud/DeleteReplicaTest.java | 4 +-- .../apache/solr/cloud/DocValuesNotIndexedTest.java | 3 +- .../solr/cloud/SystemCollectionCompatTest.java | 3 +- .../org/apache/solr/cloud/TestHashPartitioner.java | 6 ++-- .../test/org/apache/solr/cloud/TestLockTree.java | 3 +- .../solr/cloud/TestStressInPlaceUpdates.java | 7 +++-- .../CollectionsAPIAsyncDistributedZkTest.java | 4 +-- .../component/DistributedExpandComponentTest.java | 6 ++-- .../DistributedFacetPivotLongTailTest.java | 4 +-- .../solr/handler/component/StatsComponentTest.java | 4 +-- .../handler/component/TermVectorComponentTest.java | 6 ++-- .../solr/handler/export/TestExportWriter.java | 10 +++---- .../apache/solr/internal/csv/CSVParserTest.java | 35 +++++++++------------- .../apache/solr/legacy/TestLegacyNumericUtils.java | 20 ++++++------- .../org/apache/solr/schema/TestPointFields.java | 8 ++--- .../org/apache/solr/search/QueryEqualityTest.java | 8 ++--- .../solr/search/TestCollapseQParserPlugin.java | 6 ++-- .../apache/solr/search/TestFilteredDocIdSet.java | 6 ++-- .../apache/solr/search/TestHashQParserPlugin.java | 5 +--- .../solr/spelling/IndexBasedSpellCheckerTest.java | 4 +-- .../solr/update/TestInPlaceUpdatesDistrib.java | 19 ++++++------ .../SignatureUpdateProcessorFactoryTest.java | 16 +++++----- 24 files changed, 91 insertions(+), 109 deletions(-) diff --git a/solr/core/src/test/org/apache/solr/BasicFunctionalityTest.java b/solr/core/src/test/org/apache/solr/BasicFunctionalityTest.java index cac8cdc99fc..ed119a01c92 100644 --- a/solr/core/src/test/org/apache/solr/BasicFunctionalityTest.java +++ b/solr/core/src/test/org/apache/solr/BasicFunctionalityTest.java @@ -798,9 +798,9 @@ public class BasicFunctionalityTest extends SolrTestCaseJ4 { assertFalse(d1.getField("id") instanceof LazyDocument.LazyField); values1 = d1.getFields("test_hlt"); assertEquals(4, values1.length); - for (int i = 0; i < values1.length; i++) { - assertTrue(values1[i] instanceof LazyDocument.LazyField); - LazyDocument.LazyField f = (LazyDocument.LazyField) values1[i]; + for (IndexableField field : values1) { + assertTrue(field instanceof LazyDocument.LazyField); + LazyDocument.LazyField f = (LazyDocument.LazyField) field; assertFalse(f.hasBeenLoaded()); } req.close(); @@ -825,9 +825,9 @@ public class BasicFunctionalityTest extends SolrTestCaseJ4 { } assertNotNull(values2[0].stringValue()); // actuallize one value - for (int i = 0; i < values2.length; i++) { + for (IndexableField indexableField : values2) { // now all values for this field should be loaded & cached - LazyDocument.LazyField f = (LazyDocument.LazyField) values2[i]; + LazyDocument.LazyField f = (LazyDocument.LazyField) indexableField; assertTrue(f.hasBeenLoaded()); } diff --git a/solr/core/src/test/org/apache/solr/TestDistributedSearch.java b/solr/core/src/test/org/apache/solr/TestDistributedSearch.java index 90465206bf8..613ec0bd2dd 100644 --- a/solr/core/src/test/org/apache/solr/TestDistributedSearch.java +++ b/solr/core/src/test/org/apache/solr/TestDistributedSearch.java @@ -2004,8 +2004,7 @@ public class TestDistributedSearch extends BaseDistributedSearchTestCase { String shard = entry.getKey(); NamedList<?> info = (NamedList<?>) entry.getValue(); boolean found = false; - for (int i = 0; i < shardsArr.length; i++) { - String s = shardsArr[i]; + for (String s : shardsArr) { if (shard.contains(s)) { found = true; // make sure that it responded if it's up and the landing node didn't error before sending diff --git a/solr/core/src/test/org/apache/solr/cloud/DeleteReplicaTest.java b/solr/core/src/test/org/apache/solr/cloud/DeleteReplicaTest.java index a71e71401f9..2dc533da945 100644 --- a/solr/core/src/test/org/apache/solr/cloud/DeleteReplicaTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/DeleteReplicaTest.java @@ -537,8 +537,8 @@ public class DeleteReplicaTest extends SolrCloudTestCase { CollectionAdminRequest.deleteReplica(collectionName, "shard1", nonLeader.getName()) .process(cluster.getSolrClient()); closed.set(true); - for (int i = 0; i < threads.length; i++) { - threads[i].join(); + for (Thread thread : threads) { + thread.join(); } try { diff --git a/solr/core/src/test/org/apache/solr/cloud/DocValuesNotIndexedTest.java b/solr/core/src/test/org/apache/solr/cloud/DocValuesNotIndexedTest.java index a3d0d39cce4..b26a126d441 100644 --- a/solr/core/src/test/org/apache/solr/cloud/DocValuesNotIndexedTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/DocValuesNotIndexedTest.java @@ -410,8 +410,7 @@ public class DocValuesNotIndexedTest extends SolrCloudTestCase { int nullCount = 0; int sevenCount = 0; int boolCount = 0; - for (int idx = 0; idx < commands.size(); ++idx) { - GroupCommand fieldCommand = commands.get(idx); + for (GroupCommand fieldCommand : commands) { for (Group grp : fieldCommand.getValues()) { switch (grp.getResult().size()) { case 7: diff --git a/solr/core/src/test/org/apache/solr/cloud/SystemCollectionCompatTest.java b/solr/core/src/test/org/apache/solr/cloud/SystemCollectionCompatTest.java index 2572aeae244..e9c2bf7e012 100644 --- a/solr/core/src/test/org/apache/solr/cloud/SystemCollectionCompatTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/SystemCollectionCompatTest.java @@ -182,8 +182,7 @@ public class SystemCollectionCompatTest extends SolrCloudTestCase { log.info("Overseer Status indicates that the overseer is: {}", leader); JettySolrRunner overseerNode = null; List<JettySolrRunner> jettySolrRunners = cluster.getJettySolrRunners(); - for (int i = 0; i < jettySolrRunners.size(); i++) { - JettySolrRunner runner = jettySolrRunners.get(i); + for (JettySolrRunner runner : jettySolrRunners) { if (runner.getNodeName().equals(leader)) { overseerNode = runner; break; diff --git a/solr/core/src/test/org/apache/solr/cloud/TestHashPartitioner.java b/solr/core/src/test/org/apache/solr/cloud/TestHashPartitioner.java index 20297d09b80..6fd9d2d4901 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestHashPartitioner.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestHashPartitioner.java @@ -217,12 +217,12 @@ public class TestHashPartitioner extends SolrTestCaseJ4 { "!!A/1000", "A//8!B///10!C////" }; - for (int i = 0; i < ids.length; ++i) { + for (String id : ids) { try { - Slice targetSlice = coll.getRouter().getTargetSlice(ids[i], null, null, null, coll); + Slice targetSlice = coll.getRouter().getTargetSlice(id, null, null, null, coll); assertNotNull(targetSlice); } catch (Exception e) { - throw new Exception("Exception routing id '" + ids[i] + "'", e); + throw new Exception("Exception routing id '" + id + "'", e); } } } diff --git a/solr/core/src/test/org/apache/solr/cloud/TestLockTree.java b/solr/core/src/test/org/apache/solr/cloud/TestLockTree.java index e855011ca63..5696134315a 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestLockTree.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestLockTree.java @@ -81,8 +81,7 @@ public class TestLockTree extends SolrTestCaseJ4 { List<Pair<CollectionAction, List<String>>> completedOps = new CopyOnWriteArrayList<>(); List<Lock> locks = new CopyOnWriteArrayList<>(); List<Thread> threads = new ArrayList<>(); - for (int i = 0; i < operations.size(); i++) { - Pair<CollectionAction, List<String>> operation = operations.get(i); + for (Pair<CollectionAction, List<String>> operation : operations) { final Lock lock = session.lock(operation.first(), operation.second()); if (lock != null) { Thread thread = new Thread(getRunnable(completedOps, operation, locks, lock)); diff --git a/solr/core/src/test/org/apache/solr/cloud/TestStressInPlaceUpdates.java b/solr/core/src/test/org/apache/solr/cloud/TestStressInPlaceUpdates.java index 8be2199f91f..d4165ff3e9a 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestStressInPlaceUpdates.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestStressInPlaceUpdates.java @@ -682,10 +682,11 @@ public class TestStressInPlaceUpdates extends AbstractFullDistribZkTestBase { Slice shard1 = clusterState.getCollection(DEFAULT_COLLECTION).getSlice(SHARD1); leader = shard1.getLeader(); - for (int i = 0; i < clients.size(); i++) { + for (SolrClient client : clients) { String leaderBaseUrl = zkStateReader.getBaseUrlForNodeName(leader.getNodeName()); - if (((HttpSolrClient) clients.get(i)).getBaseURL().startsWith(leaderBaseUrl)) - return clients.get(i); + if (((HttpSolrClient) client).getBaseURL().startsWith(leaderBaseUrl)) { + return client; + } } return null; diff --git a/solr/core/src/test/org/apache/solr/cloud/api/collections/CollectionsAPIAsyncDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/api/collections/CollectionsAPIAsyncDistributedZkTest.java index 4707f2a73ea..587292d67a6 100644 --- a/solr/core/src/test/org/apache/solr/cloud/api/collections/CollectionsAPIAsyncDistributedZkTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/api/collections/CollectionsAPIAsyncDistributedZkTest.java @@ -296,8 +296,8 @@ public class CollectionsAPIAsyncDistributedZkTest extends SolrCloudTestCase { assertEquals(1, numSuccess.get()); assertEquals(numThreads - 1, numFailure.get()); } finally { - for (int i = 0; i < clients.length; i++) { - clients[i].close(); + for (SolrClient client : clients) { + client.close(); } } } diff --git a/solr/core/src/test/org/apache/solr/handler/component/DistributedExpandComponentTest.java b/solr/core/src/test/org/apache/solr/handler/component/DistributedExpandComponentTest.java index 095ff3a3ca3..6191d4807fc 100644 --- a/solr/core/src/test/org/apache/solr/handler/component/DistributedExpandComponentTest.java +++ b/solr/core/src/test/org/apache/solr/handler/component/DistributedExpandComponentTest.java @@ -498,10 +498,10 @@ public class DistributedExpandComponentTest extends BaseDistributedSearchTestCas private void assertExpandGroups(Map<String, SolrDocumentList> expandedResults, String... groups) throws Exception { - for (int i = 0; i < groups.length; i++) { - if (!expandedResults.containsKey(groups[i])) { + for (String group : groups) { + if (!expandedResults.containsKey(group)) { throw new Exception( - "Expanded Group Not Found:" + groups[i] + ", Found:" + exportGroups(expandedResults)); + "Expanded Group Not Found:" + group + ", Found:" + exportGroups(expandedResults)); } } } diff --git a/solr/core/src/test/org/apache/solr/handler/component/DistributedFacetPivotLongTailTest.java b/solr/core/src/test/org/apache/solr/handler/component/DistributedFacetPivotLongTailTest.java index 8315d2c57d4..69060841a6a 100644 --- a/solr/core/src/test/org/apache/solr/handler/component/DistributedFacetPivotLongTailTest.java +++ b/solr/core/src/test/org/apache/solr/handler/component/DistributedFacetPivotLongTailTest.java @@ -82,8 +82,8 @@ public class DistributedFacetPivotLongTailTest extends BaseDistributedSearchTest List<PivotField> pivots = null; List<List<PivotField>> shardPivots = new ArrayList<>(clients.size()); - for (int i = 0; i < clients.size(); i++) { - shardPivots.add(clients.get(i).query(req).getFacetPivot().get("foo_s,bar_s")); + for (org.apache.solr.client.solrj.SolrClient client : clients) { + shardPivots.add(client.query(req).getFacetPivot().get("foo_s,bar_s")); } // top 5 same on all shards diff --git a/solr/core/src/test/org/apache/solr/handler/component/StatsComponentTest.java b/solr/core/src/test/org/apache/solr/handler/component/StatsComponentTest.java index 1fb6fb634b6..fb18a2ea2ba 100644 --- a/solr/core/src/test/org/apache/solr/handler/component/StatsComponentTest.java +++ b/solr/core/src/test/org/apache/solr/handler/component/StatsComponentTest.java @@ -2368,8 +2368,8 @@ public class StatsComponentTest extends SolrTestCaseJ4 { public EnumSet<Stat> next() { EnumSet<Stat> result = EnumSet.noneOf(Stat.class); int[] indexes = wrapped.next(); - for (int i = 0; i < indexes.length; i++) { - result.add(all[indexes[i]]); + for (int index : indexes) { + result.add(all[index]); } return result; } diff --git a/solr/core/src/test/org/apache/solr/handler/component/TermVectorComponentTest.java b/solr/core/src/test/org/apache/solr/handler/component/TermVectorComponentTest.java index cf52416418a..f5d206aa3a2 100644 --- a/solr/core/src/test/org/apache/solr/handler/component/TermVectorComponentTest.java +++ b/solr/core/src/test/org/apache/solr/handler/component/TermVectorComponentTest.java @@ -406,16 +406,16 @@ public class TermVectorComponentTest extends SolrTestCaseJ4 { }; StringBuilder expected = new StringBuilder("/termVectors/0/test_posofftv/anoth=={"); boolean first = true; - for (int i = 0; i < options.length; i++) { + for (String[] option : options) { final boolean use = random().nextBoolean(); if (use) { if (!first) { expected.append(", "); } first = false; - expected.append(options[i][1]); + expected.append(option[1]); } - list.add(options[i][0]); + list.add(option[0]); list.add(use ? "true" : "false"); } diff --git a/solr/core/src/test/org/apache/solr/handler/export/TestExportWriter.java b/solr/core/src/test/org/apache/solr/handler/export/TestExportWriter.java index 718dea2a049..a81b4c6bef4 100644 --- a/solr/core/src/test/org/apache/solr/handler/export/TestExportWriter.java +++ b/solr/core/src/test/org/apache/solr/handler/export/TestExportWriter.java @@ -1235,8 +1235,8 @@ public class TestExportWriter extends SolrTestCaseJ4 { for (int i = 0; i < 100; i++) { boolean found = false; String si = String.valueOf(i); - for (int j = 0; j < docs.size(); j++) { - if (docs.get(j).get("sortabledv_udvas").equals(si)) { + for (Map<String, Object> doc : docs) { + if (doc.get("sortabledv_udvas").equals(si)) { found = true; break; } @@ -1362,9 +1362,9 @@ public class TestExportWriter extends SolrTestCaseJ4 { ((LinkedHashMap) doclist.get(i)).get("id"), String.valueOf(((HashMap<?, ?>) docs.get(i)).get("id"))); - for (int j = 0; j < fieldSorts.length; j++) { // fields .. - String field = fieldSorts[j].getField(); - String sort = fieldSorts[j].getSort(); + for (SortFields fieldSort : fieldSorts) { // fields .. + String field = fieldSort.getField(); + String sort = fieldSort.getSort(); String fieldVal1 = String.valueOf(((HashMap) docs.get(i)).get(field)); // 1st doc String fieldVal2 = String.valueOf(((HashMap) docs.get(i + 1)).get(field)); // 2nd obj if (fieldVal1.equals(fieldVal2)) { diff --git a/solr/core/src/test/org/apache/solr/internal/csv/CSVParserTest.java b/solr/core/src/test/org/apache/solr/internal/csv/CSVParserTest.java index d7b5e0bcbd8..361678fae89 100644 --- a/solr/core/src/test/org/apache/solr/internal/csv/CSVParserTest.java +++ b/solr/core/src/test/org/apache/solr/internal/csv/CSVParserTest.java @@ -216,9 +216,9 @@ public class CSVParserTest extends TestCase { public void testGetLine() throws IOException { CSVParser parser = new CSVParser(new StringReader(code)); String[] tmp = null; - for (int i = 0; i < res.length; i++) { + for (String[] re : res) { tmp = parser.getLine(); - assertTrue(Arrays.equals(res[i], tmp)); + assertTrue(Arrays.equals(re, tmp)); } tmp = parser.getLine(); assertTrue(tmp == null); @@ -227,10 +227,10 @@ public class CSVParserTest extends TestCase { public void testNextValue() throws IOException { CSVParser parser = new CSVParser(new StringReader(code)); String tmp = null; - for (int i = 0; i < res.length; i++) { - for (int j = 0; j < res[i].length; j++) { + for (String[] re : res) { + for (String r : re) { tmp = parser.nextValue(); - assertEquals(res[i][j], tmp); + assertEquals(r, tmp); } } tmp = parser.nextValue(); @@ -301,9 +301,7 @@ public class CSVParserTest extends TestCase { {""}, // ExcelStrategy does not ignore empty lines {"world", ""} }; - String code; - for (int codeIndex = 0; codeIndex < codes.length; codeIndex++) { - code = codes[codeIndex]; + for (String code : codes) { CSVParser parser = new CSVParser(new StringReader(code), CSVStrategy.EXCEL_STRATEGY); String[][] tmp = parser.getAllValues(); assertEquals(res.length, tmp.length); @@ -329,9 +327,8 @@ public class CSVParserTest extends TestCase { {"hello", ""}, // CSV Strategy ignores empty lines {"world", ""} }; - String code; - for (int codeIndex = 0; codeIndex < codes.length; codeIndex++) { - code = codes[codeIndex]; + + for (String code : codes) { CSVParser parser = new CSVParser(new StringReader(code)); String[][] tmp = parser.getAllValues(); assertEquals(res.length, tmp.length); @@ -351,9 +348,7 @@ public class CSVParserTest extends TestCase { {""}, // ExcelStrategy does not ignore empty lines {""} }; - String code; - for (int codeIndex = 0; codeIndex < codes.length; codeIndex++) { - code = codes[codeIndex]; + for (String code : codes) { CSVParser parser = new CSVParser(new StringReader(code), CSVStrategy.EXCEL_STRATEGY); String[][] tmp = parser.getAllValues(); assertEquals(res.length, tmp.length); @@ -371,9 +366,7 @@ public class CSVParserTest extends TestCase { String[][] res = { {"hello", ""} // CSV Strategy ignores empty lines }; - String code; - for (int codeIndex = 0; codeIndex < codes.length; codeIndex++) { - code = codes[codeIndex]; + for (String code : codes) { CSVParser parser = new CSVParser(new StringReader(code)); String[][] tmp = parser.getAllValues(); assertEquals(res.length, tmp.length); @@ -579,10 +572,10 @@ public class CSVParserTest extends TestCase { String[][] data = parser.getAllValues(); parser = new CSVParser(new StringReader(code)); CSVParser parser1 = new CSVParser(new StringReader(code)); - for (int i = 0; i < data.length; i++) { - assertTrue(Arrays.equals(parser1.getLine(), data[i])); - for (int j = 0; j < data[i].length; j++) { - assertEquals(parser.nextValue(), data[i][j]); + for (String[] datum : data) { + assertTrue(Arrays.equals(parser1.getLine(), datum)); + for (String d : datum) { + assertEquals(parser.nextValue(), d); } } } diff --git a/solr/core/src/test/org/apache/solr/legacy/TestLegacyNumericUtils.java b/solr/core/src/test/org/apache/solr/legacy/TestLegacyNumericUtils.java index 81843565925..155ea24a4e0 100644 --- a/solr/core/src/test/org/apache/solr/legacy/TestLegacyNumericUtils.java +++ b/solr/core/src/test/org/apache/solr/legacy/TestLegacyNumericUtils.java @@ -124,15 +124,15 @@ public class TestLegacyNumericUtils extends SolrTestCase { // check the prefix encoding, lower precision should have the difference to original value equal // to the lower removed bits final BytesRefBuilder ref = new BytesRefBuilder(); - for (int i = 0; i < vals.length; i++) { + for (long val : vals) { for (int j = 0; j < 64; j++) { - LegacyNumericUtils.longToPrefixCoded(vals[i], j, ref); + LegacyNumericUtils.longToPrefixCoded(val, j, ref); long prefixVal = LegacyNumericUtils.prefixCodedToLong(ref.get()); long mask = (1L << j) - 1L; assertEquals( - "difference between prefix val and original value for " + vals[i] + " with shift=" + j, - vals[i] & mask, - vals[i] - prefixVal); + "difference between prefix val and original value for " + val + " with shift=" + j, + val & mask, + val - prefixVal); } } } @@ -187,15 +187,15 @@ public class TestLegacyNumericUtils extends SolrTestCase { // check the prefix encoding, lower precision should have the difference to original value equal // to the lower removed bits final BytesRefBuilder ref = new BytesRefBuilder(); - for (int i = 0; i < vals.length; i++) { + for (int val : vals) { for (int j = 0; j < 32; j++) { - LegacyNumericUtils.intToPrefixCoded(vals[i], j, ref); + LegacyNumericUtils.intToPrefixCoded(val, j, ref); int prefixVal = LegacyNumericUtils.prefixCodedToInt(ref.get()); int mask = (1 << j) - 1; assertEquals( - "difference between prefix val and original value for " + vals[i] + " with shift=" + j, - vals[i] & mask, - vals[i] - prefixVal); + "difference between prefix val and original value for " + val + " with shift=" + j, + val & mask, + val - prefixVal); } } } diff --git a/solr/core/src/test/org/apache/solr/schema/TestPointFields.java b/solr/core/src/test/org/apache/solr/schema/TestPointFields.java index 70a55534e27..6fb9ff3aa01 100644 --- a/solr/core/src/test/org/apache/solr/schema/TestPointFields.java +++ b/solr/core/src/test/org/apache/solr/schema/TestPointFields.java @@ -5289,9 +5289,9 @@ public class TestPointFields extends SolrTestCaseJ4 { SchemaField sf = h.getCore().getLatestSchema().getField(fieldName); assertTrue(sf.getType() instanceof PointField); - for (int i = 0; i < values.length; i++) { + for (String value : values) { assertQ( - req("q", "{!term f='" + fieldName + "'}" + values[i], "fl", "id," + fieldName), + req("q", "{!term f='" + fieldName + "'}" + value, "fl", "id," + fieldName), "//*[@numFound='1']"); } @@ -5360,9 +5360,9 @@ public class TestPointFields extends SolrTestCaseJ4 { values[(i + 1) % values.length])); } assertU(commit()); - for (int i = 0; i < values.length; i++) { + for (String value : values) { assertQ( - req("q", "{!term f='" + fieldName + "'}" + values[i], "fl", "id," + fieldName), + req("q", "{!term f='" + fieldName + "'}" + value, "fl", "id," + fieldName), "//*[@numFound='2']"); } diff --git a/solr/core/src/test/org/apache/solr/search/QueryEqualityTest.java b/solr/core/src/test/org/apache/solr/search/QueryEqualityTest.java index 97235d23109..3b2a8dde808 100644 --- a/solr/core/src/test/org/apache/solr/search/QueryEqualityTest.java +++ b/solr/core/src/test/org/apache/solr/search/QueryEqualityTest.java @@ -1351,13 +1351,13 @@ public class QueryEqualityTest extends SolrTestCaseJ4 { SolrRequestInfo.clearRequestInfo(); } - for (int i = 0; i < queries.length; i++) { - QueryUtils.check(queries[i]); + for (Query query1 : queries) { + QueryUtils.check(query1); // yes starting j=0 is redundent, we're making sure every query // is equal to itself, and that the quality checks work regardless // of which caller/callee is used. - for (int j = 0; j < queries.length; j++) { - QueryUtils.checkEqual(queries[i], queries[j]); + for (Query query2 : queries) { + QueryUtils.checkEqual(query1, query2); } } } diff --git a/solr/core/src/test/org/apache/solr/search/TestCollapseQParserPlugin.java b/solr/core/src/test/org/apache/solr/search/TestCollapseQParserPlugin.java index ba34b465d2c..c6a7ac9cbc5 100644 --- a/solr/core/src/test/org/apache/solr/search/TestCollapseQParserPlugin.java +++ b/solr/core/src/test/org/apache/solr/search/TestCollapseQParserPlugin.java @@ -334,8 +334,7 @@ public class TestCollapseQParserPlugin extends SolrTestCaseJ4 { List<Integer> boostedResults = new ArrayList<>(); - for (int i = 0; i < resultsArray.length; i++) { - int result = resultsArray[i]; + for (int result : resultsArray) { if (mergeBoost.boost(result)) { boostedResults.add(result); } @@ -343,8 +342,7 @@ public class TestCollapseQParserPlugin extends SolrTestCaseJ4 { List<Integer> controlResults = new ArrayList<>(); - for (int i = 0; i < resultsArray.length; i++) { - int result = resultsArray[i]; + for (int result : resultsArray) { if (Arrays.binarySearch(boostedArray, result) > -1) { controlResults.add(result); } diff --git a/solr/core/src/test/org/apache/solr/search/TestFilteredDocIdSet.java b/solr/core/src/test/org/apache/solr/search/TestFilteredDocIdSet.java index 8bed7195b66..353743d4381 100644 --- a/solr/core/src/test/org/apache/solr/search/TestFilteredDocIdSet.java +++ b/solr/core/src/test/org/apache/solr/search/TestFilteredDocIdSet.java @@ -19,7 +19,6 @@ package org.apache.solr.search; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; -import java.util.Iterator; import junit.framework.Assert; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; @@ -102,9 +101,8 @@ public class TestFilteredDocIdSet extends SolrTestCase { int[] docs = new int[list.size()]; int c = 0; - Iterator<Integer> intIter = list.iterator(); - while (intIter.hasNext()) { - docs[c++] = intIter.next(); + for (Integer integer : list) { + docs[c++] = integer.intValue(); } int[] answer = new int[] {4, 6, 8}; boolean same = Arrays.equals(answer, docs); diff --git a/solr/core/src/test/org/apache/solr/search/TestHashQParserPlugin.java b/solr/core/src/test/org/apache/solr/search/TestHashQParserPlugin.java index fcf45e6554b..433a0e975ab 100644 --- a/solr/core/src/test/org/apache/solr/search/TestHashQParserPlugin.java +++ b/solr/core/src/test/org/apache/solr/search/TestHashQParserPlugin.java @@ -300,10 +300,7 @@ public class TestHashQParserPlugin extends SolrTestCaseJ4 { private void assertNoOverLap( @SuppressWarnings({"rawtypes"}) Set setA, @SuppressWarnings({"rawtypes"}) Set setB) throws Exception { - @SuppressWarnings({"rawtypes"}) - Iterator it = setA.iterator(); - while (it.hasNext()) { - Object o = it.next(); + for (Object o : setA) { if (setB.contains(o)) { throw new Exception("Overlapping sets for value:" + o.toString()); } diff --git a/solr/core/src/test/org/apache/solr/spelling/IndexBasedSpellCheckerTest.java b/solr/core/src/test/org/apache/solr/spelling/IndexBasedSpellCheckerTest.java index b16f5d09e45..9ff92d73826 100644 --- a/solr/core/src/test/org/apache/solr/spelling/IndexBasedSpellCheckerTest.java +++ b/solr/core/src/test/org/apache/solr/spelling/IndexBasedSpellCheckerTest.java @@ -319,9 +319,9 @@ public class IndexBasedSpellCheckerTest extends SolrTestCaseJ4 { File altIndexDir = new File(tmpDir, "alternateIdx" + new Date().getTime()); Directory dir = newFSDirectory(altIndexDir.toPath()); IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig(new WhitespaceAnalyzer())); - for (int i = 0; i < ALT_DOCS.length; i++) { + for (String alt_doc : ALT_DOCS) { Document doc = new Document(); - doc.add(new TextField("title", ALT_DOCS[i], Field.Store.YES)); + doc.add(new TextField("title", alt_doc, Field.Store.YES)); iw.addDocument(doc); } iw.forceMerge(1); diff --git a/solr/core/src/test/org/apache/solr/update/TestInPlaceUpdatesDistrib.java b/solr/core/src/test/org/apache/solr/update/TestInPlaceUpdatesDistrib.java index 7230b317987..d1cb35ed94a 100644 --- a/solr/core/src/test/org/apache/solr/update/TestInPlaceUpdatesDistrib.java +++ b/solr/core/src/test/org/apache/solr/update/TestInPlaceUpdatesDistrib.java @@ -220,9 +220,10 @@ public class TestInPlaceUpdatesDistrib extends AbstractFullDistribZkTestBase { leader = shard1.getLeader(); String leaderBaseUrl = zkStateReader.getBaseUrlForNodeName(leader.getNodeName()); - for (int i = 0; i < clients.size(); i++) { - if (((HttpSolrClient) clients.get(i)).getBaseURL().startsWith(leaderBaseUrl)) - LEADER = clients.get(i); + for (SolrClient solrClient : clients) { + if (((HttpSolrClient) solrClient).getBaseURL().startsWith(leaderBaseUrl)) { + LEADER = solrClient; + } } NONLEADERS = new ArrayList<>(); @@ -231,9 +232,10 @@ public class TestInPlaceUpdatesDistrib extends AbstractFullDistribZkTestBase { continue; } String baseUrl = zkStateReader.getBaseUrlForNodeName(rep.getNodeName()); - for (int i = 0; i < clients.size(); i++) { - if (((HttpSolrClient) clients.get(i)).getBaseURL().startsWith(baseUrl)) - NONLEADERS.add(clients.get(i)); + for (SolrClient client : clients) { + if (((HttpSolrClient) client).getBaseURL().startsWith(baseUrl)) { + NONLEADERS.add(client); + } } } @@ -1194,10 +1196,7 @@ public class TestInPlaceUpdatesDistrib extends AbstractFullDistribZkTestBase { log.info("Doc in both replica 0: {}", doc0); log.info("Doc in both replica 1: {}", doc1); // assert both replicas have same effect - for (int i = 0; - i < NONLEADERS.size(); - i++) { // 0th is re-ordered replica, 1st is well-ordered replica - SolrClient client = NONLEADERS.get(i); + for (SolrClient client : NONLEADERS) { // 0th is re-ordered replica, 1st is well-ordered replica SolrDocument doc = client.getById(String.valueOf(0), params("distrib", "false")); assertNotNull("Client: " + ((HttpSolrClient) client).getBaseURL(), doc); assertEquals( diff --git a/solr/core/src/test/org/apache/solr/update/processor/SignatureUpdateProcessorFactoryTest.java b/solr/core/src/test/org/apache/solr/update/processor/SignatureUpdateProcessorFactoryTest.java index 0d7788decf2..fa75b9c7c47 100644 --- a/solr/core/src/test/org/apache/solr/update/processor/SignatureUpdateProcessorFactoryTest.java +++ b/solr/core/src/test/org/apache/solr/update/processor/SignatureUpdateProcessorFactoryTest.java @@ -179,20 +179,20 @@ public class SignatureUpdateProcessorFactoryTest extends SolrTestCaseJ4 { threads2[i].setName("testThread2-" + i); } - for (int i = 0; i < threads.length; i++) { - threads[i].start(); + for (Thread thread : threads) { + thread.start(); } - for (int i = 0; i < threads2.length; i++) { - threads2[i].start(); + for (Thread thread2 : threads2) { + thread2.start(); } - for (int i = 0; i < threads.length; i++) { - threads[i].join(); + for (Thread thread : threads) { + thread.join(); } - for (int i = 0; i < threads2.length; i++) { - threads2[i].join(); + for (Thread thread2 : threads2) { + thread2.join(); } SolrCore core = h.getCore();