You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ds...@apache.org on 2025/04/05 17:20:38 UTC
(solr) branch main updated: SOLR-17723: Use NamedList.forEach() or iterator() (#3295)
This is an automated email from the ASF dual-hosted git repository.
dsmiley pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/main by this push:
new 83e98154029 SOLR-17723: Use NamedList.forEach() or iterator() (#3295)
83e98154029 is described below
commit 83e98154029eeddc2645e79a922bd28337600728
Author: David Smiley <ds...@apache.org>
AuthorDate: Sat Apr 5 13:20:32 2025 -0400
SOLR-17723: Use NamedList.forEach() or iterator() (#3295)
In order to be more Map-like.
And avoid some needless indexed method usages.
---
.../java/org/apache/solr/cli/SnapshotListTool.java | 4 +-
.../src/java/org/apache/solr/core/InitParams.java | 7 +-
.../apache/solr/handler/ReplicationHandler.java | 12 +-
.../solr/handler/admin/SolrInfoMBeanHandler.java | 58 +++---
.../solr/handler/component/DebugComponent.java | 2 +
.../solr/handler/component/ExpandComponent.java | 8 +-
.../solr/handler/component/FacetComponent.java | 36 ++--
.../solr/handler/component/PivotFacetHelper.java | 1 +
.../solr/handler/component/PivotFacetValue.java | 42 ++---
.../solr/handler/component/QueryComponent.java | 9 +-
.../solr/handler/component/RangeFacetRequest.java | 1 +
.../handler/component/SpellCheckComponent.java | 8 +-
.../solr/handler/component/StatsComponent.java | 7 +-
.../solr/handler/component/StatsValuesFactory.java | 30 ++-
.../solr/handler/component/SuggestComponent.java | 60 +++---
.../org/apache/solr/request/NumericFacets.java | 5 +-
.../org/apache/solr/response/SchemaXmlWriter.java | 108 +++++------
.../apache/solr/response/SolrQueryResponse.java | 8 +-
.../org/apache/solr/search/facet/FacetBucket.java | 31 ++-
.../TopGroupsResultTransformer.java | 14 +-
.../DocumentExpressionDictionaryFactory.java | 15 +-
...AbstractDefaultValueUpdateProcessorFactory.java | 2 +-
.../CloneFieldUpdateProcessorFactory.java | 21 +--
.../FieldMutatingUpdateProcessorFactory.java | 5 +-
.../IgnoreLargeDocumentProcessorFactory.java | 2 +-
.../update/processor/TolerantUpdateProcessor.java | 5 +-
.../java/org/apache/solr/util/SolrPluginUtils.java | 18 +-
.../test/org/apache/solr/TestTolerantSearch.java | 12 +-
.../cloud/TestTolerantUpdateProcessorCloud.java | 12 +-
.../component/CustomHighlightComponentTest.java | 13 +-
.../solr/handler/component/StatsComponentTest.java | 29 ++-
.../apache/solr/request/TestIntervalFaceting.java | 43 ++---
.../apache/solr/search/RankQueryTestPlugin.java | 12 +-
...ExtractNamedEntitiesUpdateProcessorFactory.java | 21 +--
.../client/solrj/io/stream/ScoreNodesStream.java | 41 ++--
.../solr/client/solrj/response/FieldStatsInfo.java | 7 +-
.../solr/client/solrj/response/QueryResponse.java | 207 ++++++++++-----------
.../client/solrj/response/SpellCheckResponse.java | 75 ++++----
.../client/solrj/response/SuggesterResponse.java | 38 ++--
.../solr/client/solrj/response/TermsResponse.java | 42 ++---
.../solrj/response/schema/SchemaResponse.java | 13 +-
41 files changed, 511 insertions(+), 573 deletions(-)
diff --git a/solr/core/src/java/org/apache/solr/cli/SnapshotListTool.java b/solr/core/src/java/org/apache/solr/cli/SnapshotListTool.java
index 2bbad50688b..be40d0361f6 100644
--- a/solr/core/src/java/org/apache/solr/cli/SnapshotListTool.java
+++ b/solr/core/src/java/org/apache/solr/cli/SnapshotListTool.java
@@ -75,9 +75,7 @@ public class SnapshotListTool extends ToolBase {
NamedList<?> apiResult =
(NamedList<?>) resp.getResponse().get(SolrSnapshotManager.SNAPSHOTS_INFO);
- for (int i = 0; i < apiResult.size(); i++) {
- echo(apiResult.getName(i));
- }
+ apiResult.forEach((name, value) -> echo(name));
} catch (Exception e) {
echo(
diff --git a/solr/core/src/java/org/apache/solr/core/InitParams.java b/solr/core/src/java/org/apache/solr/core/InitParams.java
index 1df9d3b6299..b2c5035693b 100644
--- a/solr/core/src/java/org/apache/solr/core/InitParams.java
+++ b/solr/core/src/java/org/apache/solr/core/InitParams.java
@@ -99,12 +99,12 @@ public class InitParams {
merge((NamedList<?>) info.initArgs.get(APPENDS), appends, info.initArgs, APPENDS, true);
if (pluginInfo.initArgs != null) {
- for (int i = 0; i < pluginInfo.initArgs.size(); i++) {
- String name = pluginInfo.initArgs.getName(i);
+ for (Map.Entry<String, ?> argEntry : pluginInfo.initArgs) {
+ String name = argEntry.getKey();
if (KNOWN_KEYS.contains(name)) continue; // already taken care of
Object val = info.initArgs.get(name);
if (val != null) continue; // this is explicitly specified in the reqhandler , ignore
- info.initArgs.add(name, pluginInfo.initArgs.getVal(i));
+ info.initArgs.add(name, argEntry.getValue());
}
}
}
@@ -137,6 +137,7 @@ public class InitParams {
for (Object v : second.getAll(s)) nl.add(s, v);
}
}
+ // TODO sink should be a Map; just call put(k,v);
if (sink.indexOf(name, 0) > -1) {
sink.setVal(sink.indexOf(name, 0), nl);
} else {
diff --git a/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java b/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java
index bcd08c55ac9..c506a875294 100644
--- a/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java
@@ -717,10 +717,14 @@ public class ReplicationHandler extends RequestHandlerBase
List<FileMetaData> confFiles = new ArrayList<>();
synchronized (confFileInfoCache) {
Checksum checksum = null;
- for (int i = 0; i < nameAndAlias.size(); i++) {
- String cf = nameAndAlias.getName(i);
+
+ for (Map.Entry<String, String> aliasEntry : nameAndAlias) {
+ String cf = aliasEntry.getKey();
+ String aliasValue = aliasEntry.getValue();
+
Path f = core.getResourceLoader().getConfigPath().resolve(cf);
if (!Files.exists(f) || Files.isDirectory(f)) continue; // must not happen
+
FileInfo info = confFileInfoCache.get(cf);
long lastModified = 0;
long size = 0;
@@ -730,13 +734,15 @@ public class ReplicationHandler extends RequestHandlerBase
} catch (IOException e) {
// proceed with zeroes for now, will probably error on checksum anyway
}
+
if (info == null || info.lastmodified != lastModified || info.fileMetaData.size != size) {
if (checksum == null) checksum = new Adler32();
info = new FileInfo(lastModified, cf, size, getCheckSum(checksum, f));
confFileInfoCache.put(cf, info);
}
+
FileMetaData m = info.fileMetaData;
- if (nameAndAlias.getVal(i) != null) m.alias = nameAndAlias.getVal(i);
+ if (aliasValue != null) m.alias = aliasValue;
confFiles.add(m);
}
}
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/SolrInfoMBeanHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/SolrInfoMBeanHandler.java
index b3269738e0d..a9ba9d0bea2 100644
--- a/solr/core/src/java/org/apache/solr/handler/admin/SolrInfoMBeanHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/admin/SolrInfoMBeanHandler.java
@@ -21,6 +21,7 @@ import java.text.NumberFormat;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import org.apache.solr.client.solrj.impl.XMLResponseParser;
import org.apache.solr.common.SolrException;
@@ -158,9 +159,9 @@ public class SolrInfoMBeanHandler extends RequestHandlerBase {
NamedList<NamedList<NamedList<Object>>> changed = new NamedList<>();
// Cycle through each category
- for (int i = 0; i < ref.size(); i++) {
- String category = ref.getName(i);
- NamedList<NamedList<Object>> ref_cat = ref.get(category);
+ for (Entry<String, NamedList<NamedList<Object>>> catEntry : ref) {
+ String category = catEntry.getKey();
+ NamedList<NamedList<Object>> ref_cat = catEntry.getValue();
NamedList<NamedList<Object>> now_cat = now.get(category);
if (now_cat != null) {
String ref_txt = ref_cat + "";
@@ -170,9 +171,9 @@ public class SolrInfoMBeanHandler extends RequestHandlerBase {
// Now iterate the real beans
NamedList<NamedList<Object>> cat = new SimpleOrderedMap<>();
- for (int j = 0; j < ref_cat.size(); j++) {
- String name = ref_cat.getName(j);
- NamedList<Object> ref_bean = ref_cat.get(name);
+ for (Entry<String, NamedList<Object>> beanEntry : ref_cat) {
+ String name = beanEntry.getKey();
+ NamedList<Object> ref_bean = beanEntry.getValue();
NamedList<Object> now_bean = now_cat.get(name);
ref_txt = ref_bean + "";
@@ -204,28 +205,27 @@ public class SolrInfoMBeanHandler extends RequestHandlerBase {
public NamedList<Object> diffNamedList(NamedList<?> ref, NamedList<?> now) {
NamedList<Object> out = new SimpleOrderedMap<>();
- for (int i = 0; i < ref.size(); i++) {
- String name = ref.getName(i);
- Object r = ref.getVal(i);
- Object n = now.get(name);
- if (n == null) {
- if (r != null) {
- out.add("REMOVE " + name, r);
- now.remove(name);
- }
- } else if (r != null) {
- out.add(name, diffObject(r, n));
- now.remove(name);
- }
- }
+ ref.forEach(
+ (name, r) -> {
+ Object n = now.get(name);
+ if (n == null) {
+ if (r != null) {
+ out.add("REMOVE " + name, r);
+ now.remove(name);
+ }
+ } else if (r != null) {
+ out.add(name, diffObject(r, n));
+ now.remove(name);
+ }
+ });
+
+ now.forEach(
+ (name, v) -> {
+ if (v != null) {
+ out.add("ADD " + name, v);
+ }
+ });
- for (int i = 0; i < now.size(); i++) {
- String name = now.getName(i);
- Object v = now.getVal(i);
- if (v != null) {
- out.add("ADD " + name, v);
- }
- }
return out;
}
@@ -266,8 +266,8 @@ public class SolrInfoMBeanHandler extends RequestHandlerBase {
/** The 'avgRequestsPerSecond' field will make everything look like it changed */
public void normalize(NamedList<?> input) {
input.remove("avgRequestsPerSecond");
- for (int i = 0; i < input.size(); i++) {
- Object v = input.getVal(i);
+ for (Entry<String, ?> entry : input) {
+ Object v = entry.getValue();
if (v instanceof NamedList) {
// edit in place so we don't need to return it
normalize((NamedList<?>) v);
diff --git a/solr/core/src/java/org/apache/solr/handler/component/DebugComponent.java b/solr/core/src/java/org/apache/solr/handler/component/DebugComponent.java
index 0adcdb93b1f..7e67d1c3a75 100644
--- a/solr/core/src/java/org/apache/solr/handler/component/DebugComponent.java
+++ b/solr/core/src/java/org/apache/solr/handler/component/DebugComponent.java
@@ -264,6 +264,7 @@ public class DebugComponent extends SearchComponent {
}
}
if (rb.isDebugResults()) {
+ // put()
int idx = info.indexOf("explain", 0);
if (idx >= 0) {
info.setVal(idx, explain);
@@ -342,6 +343,7 @@ public class DebugComponent extends SearchComponent {
NamedList<Object> tmp = new NamedList<>();
@SuppressWarnings("unchecked")
NamedList<Object> dl = (NamedList<Object>) dest;
+ // TODO simplify; drop the same-index optimization and use a Map.compute()
for (int i = 0; i < sl.size(); i++) {
String skey = sl.getName(i);
if (exclude.contains(skey)) continue;
diff --git a/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java b/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java
index e998411ed4a..d366801e22c 100644
--- a/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java
+++ b/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java
@@ -30,6 +30,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.LeafReaderContext;
@@ -61,7 +62,6 @@ import org.apache.lucene.util.BytesRefBuilder;
import org.apache.lucene.util.CharsRefBuilder;
import org.apache.lucene.util.FixedBitSet;
import org.apache.lucene.util.LongValues;
-import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.ExpandParams;
import org.apache.solr.common.params.GroupParams;
@@ -492,10 +492,8 @@ public class ExpandComponent extends SearchComponent implements PluginInfoInitia
if (ex == null) {
continue;
}
- for (int i = 0; i < ex.size(); i++) {
- String name = ex.getName(i);
- SolrDocumentList val = (SolrDocumentList) ex.getVal(i);
- expanded.add(name, val);
+ for (Map.Entry<String, ?> entry : ex) {
+ expanded.add(entry.getKey(), entry.getValue());
}
}
}
diff --git a/solr/core/src/java/org/apache/solr/handler/component/FacetComponent.java b/solr/core/src/java/org/apache/solr/handler/component/FacetComponent.java
index bf3bb17f833..f216e0d6687 100644
--- a/solr/core/src/java/org/apache/solr/handler/component/FacetComponent.java
+++ b/solr/core/src/java/org/apache/solr/handler/component/FacetComponent.java
@@ -496,14 +496,13 @@ public class FacetComponent extends SearchComponent {
shardsRefineRequestPivot.params.set(FacetParams.FACET_PIVOT_MINCOUNT, -1);
shardsRefineRequestPivot.params.remove(FacetParams.FACET_OFFSET);
- for (int pivotIndex = 0; pivotIndex < fi.pivotFacets.size(); pivotIndex++) {
- String pivotFacetKey = fi.pivotFacets.getName(pivotIndex);
- PivotFacet pivotFacet = fi.pivotFacets.getVal(pivotIndex);
+ for (Entry<String, PivotFacet> pfEntry : fi.pivotFacets) {
+ String pivotFacetKey = pfEntry.getKey();
+ PivotFacet pivotFacet = pfEntry.getValue();
List<PivotFacetValue> queuedRefinementsForShard = pivotFacet.getQueuedRefinements(shardNum);
if (!queuedRefinementsForShard.isEmpty()) {
-
String fieldsKey = PivotFacet.REFINE_PARAM + fi.pivotRefinementCounter;
String command;
@@ -730,9 +729,9 @@ public class FacetComponent extends SearchComponent {
// handle facet queries
NamedList<?> facet_queries = (NamedList<?>) facet_counts.get(FACET_QUERY_KEY);
if (facet_queries != null) {
- for (int i = 0; i < facet_queries.size(); i++) {
- String returnedKey = facet_queries.getName(i);
- long count = ((Number) facet_queries.getVal(i)).longValue();
+ for (Map.Entry<String, ?> fqEntry : facet_queries) {
+ String returnedKey = fqEntry.getKey();
+ long count = ((Number) fqEntry.getValue()).longValue();
QueryFacet qf = fi.queryFacets.get(returnedKey);
qf.count += count;
}
@@ -992,16 +991,16 @@ public class FacetComponent extends SearchComponent {
if (facet_fields == null) continue; // this can happen when there's an exception
- for (int i = 0; i < facet_fields.size(); i++) {
- String key = facet_fields.getName(i);
+ for (Map.Entry<String, ?> fieldEntry : facet_fields) {
+ String key = fieldEntry.getKey();
DistribFieldFacet dff = fi.facets.get(key);
if (dff == null) continue;
- NamedList<?> shardCounts = (NamedList<?>) facet_fields.getVal(i);
+ NamedList<?> shardCounts = (NamedList<?>) fieldEntry.getValue();
- for (int j = 0; j < shardCounts.size(); j++) {
- String name = shardCounts.getName(j);
- long count = ((Number) shardCounts.getVal(j)).longValue();
+ for (Map.Entry<String, ?> countEntry : shardCounts) {
+ String name = countEntry.getKey();
+ long count = ((Number) countEntry.getValue()).longValue();
ShardFacetCount sfc = dff.counts.get(name);
if (sfc == null) {
// we got back a term we didn't ask for?
@@ -1470,15 +1469,18 @@ public class FacetComponent extends SearchComponent {
void add(int shardNum, NamedList<?> shardCounts, int numRequested) {
// shardCounts could be null if there was an exception
- int sz = shardCounts == null ? 0 : shardCounts.size();
+ if (shardCounts == null) {
+ shardCounts = SimpleOrderedMap.of();
+ }
+ int sz = shardCounts.size();
int numReceived = sz;
FixedBitSet terms = new FixedBitSet(termNum + sz);
long last = 0;
- for (int i = 0; i < sz; i++) {
- String name = shardCounts.getName(i);
- long count = ((Number) shardCounts.getVal(i)).longValue();
+ for (Entry<String, ?> countEntry : shardCounts) {
+ String name = countEntry.getKey();
+ long count = ((Number) countEntry.getValue()).longValue();
if (name == null) {
missingCount += count;
numReceived--;
diff --git a/solr/core/src/java/org/apache/solr/handler/component/PivotFacetHelper.java b/solr/core/src/java/org/apache/solr/handler/component/PivotFacetHelper.java
index 8fd7957ad2b..12ad91a2327 100644
--- a/solr/core/src/java/org/apache/solr/handler/component/PivotFacetHelper.java
+++ b/solr/core/src/java/org/apache/solr/handler/component/PivotFacetHelper.java
@@ -198,6 +198,7 @@ public class PivotFacetHelper {
if (globalQueryCounts == null) {
return shardQueryCounts;
}
+ // TODO use Map.compute if we switch to Map
for (Entry<String, Number> entry : shardQueryCounts) {
int idx = globalQueryCounts.indexOf(entry.getKey(), 0);
if (idx == -1) {
diff --git a/solr/core/src/java/org/apache/solr/handler/component/PivotFacetValue.java b/solr/core/src/java/org/apache/solr/handler/component/PivotFacetValue.java
index 6ff681a3dce..b13b604d12b 100644
--- a/solr/core/src/java/org/apache/solr/handler/component/PivotFacetValue.java
+++ b/solr/core/src/java/org/apache/solr/handler/component/PivotFacetValue.java
@@ -129,36 +129,24 @@ public class PivotFacetValue {
NamedList<Number> queryCounts = null;
SimpleOrderedMap<SimpleOrderedMap<Object>> ranges = null;
- for (int i = 0; i < pivotData.size(); i++) {
- String key = pivotData.getName(i);
- Object value = pivotData.getVal(i);
- PivotListEntry entry = PivotListEntry.get(key);
+ for (Map.Entry<String, Object> pdEntry : pivotData) {
+ String key = pdEntry.getKey();
+ Object value = pdEntry.getValue();
+ PivotListEntry pivotEntry = PivotListEntry.get(key);
- switch (entry) {
- case VALUE:
- pivotVal = (Comparable) value;
- break;
- case FIELD:
+ switch (pivotEntry) {
+ case VALUE -> pivotVal = (Comparable) value;
+ case FIELD -> {
assert parentField.field.equals(value)
: "Parent Field mismatch: " + parentField.field + "!=" + value;
- break;
- case COUNT:
- pivotCount = (Integer) value;
- break;
- case PIVOT:
- childPivotData = (List<NamedList<Object>>) value;
- break;
- case STATS:
- statsValues = (NamedList<NamedList<NamedList<?>>>) value;
- break;
- case QUERIES:
- queryCounts = (NamedList<Number>) value;
- break;
- case RANGES:
- ranges = (SimpleOrderedMap<SimpleOrderedMap<Object>>) value;
- break;
- default:
- throw new RuntimeException("PivotListEntry contains unaccounted for item: " + entry);
+ }
+ case COUNT -> pivotCount = (Integer) value;
+ case PIVOT -> childPivotData = (List<NamedList<Object>>) value;
+ case STATS -> statsValues = (NamedList<NamedList<NamedList<?>>>) value;
+ case QUERIES -> queryCounts = (NamedList<Number>) value;
+ case RANGES -> ranges = (SimpleOrderedMap<SimpleOrderedMap<Object>>) value;
+ default -> throw new RuntimeException(
+ "PivotListEntry contains unaccounted for item: " + pivotEntry);
}
}
diff --git a/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java b/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java
index 0552c6a0c4e..bed6203d61c 100644
--- a/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java
+++ b/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java
@@ -33,6 +33,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Objects;
import org.apache.lucene.index.ExitableDirectoryReader;
import org.apache.lucene.index.IndexReaderContext;
@@ -1211,7 +1212,7 @@ public class QueryComponent extends SearchComponent {
List<SchemaField> schemaFields = sortSpec.getSchemaFields();
SortField[] sortFields = sortSpec.getSort().getSort();
- int marshalledFieldNum = 0;
+ Iterator<Entry<String, List<Object>>> sortFieldValuesIter = sortFieldValues.iterator();
for (int sortFieldNum = 0; sortFieldNum < sortFields.length; sortFieldNum++) {
final SortField sortField = sortFields[sortFieldNum];
final SortField.Type type = sortField.getType();
@@ -1220,11 +1221,12 @@ public class QueryComponent extends SearchComponent {
if (type == SortField.Type.SCORE || type == SortField.Type.DOC) continue;
final String sortFieldName = sortField.getField();
- final String valueFieldName = sortFieldValues.getName(marshalledFieldNum);
+ Map.Entry<String, List<Object>> sortFieldValuesEntry = sortFieldValuesIter.next();
+ final String valueFieldName = sortFieldValuesEntry.getKey();
assert sortFieldName.equals(valueFieldName)
: "sortFieldValues name key does not match expected SortField.getField";
- List<Object> sortVals = sortFieldValues.getVal(marshalledFieldNum);
+ List<Object> sortVals = sortFieldValuesEntry.getValue();
final SchemaField schemaField = schemaFields.get(sortFieldNum);
if (null == schemaField) {
@@ -1237,7 +1239,6 @@ public class QueryComponent extends SearchComponent {
}
unmarshalledSortValsPerField.add(sortField.getField(), unmarshalledSortVals);
}
- marshalledFieldNum++;
}
return unmarshalledSortValsPerField;
}
diff --git a/solr/core/src/java/org/apache/solr/handler/component/RangeFacetRequest.java b/solr/core/src/java/org/apache/solr/handler/component/RangeFacetRequest.java
index eecb97f0086..6756397cd4e 100644
--- a/solr/core/src/java/org/apache/solr/handler/component/RangeFacetRequest.java
+++ b/solr/core/src/java/org/apache/solr/handler/component/RangeFacetRequest.java
@@ -403,6 +403,7 @@ public class RangeFacetRequest extends FacetComponent.FacetBase {
String name = otherKey.toString();
Integer shardValue = (Integer) rangeFromShard.get(name);
if (shardValue != null && shardValue > 0) {
+ // TODO: rangeFacet.merge(name, shardValue, (a, b) -> ((Integer)a) + ((Integer)b));
Integer existingValue = (Integer) rangeFacet.get(name);
// shouldn't be null
int idx = rangeFacet.indexOf(name, 0);
diff --git a/solr/core/src/java/org/apache/solr/handler/component/SpellCheckComponent.java b/solr/core/src/java/org/apache/solr/handler/component/SpellCheckComponent.java
index a9603de49b8..39a0894fa72 100644
--- a/solr/core/src/java/org/apache/solr/handler/component/SpellCheckComponent.java
+++ b/solr/core/src/java/org/apache/solr/handler/component/SpellCheckComponent.java
@@ -717,9 +717,11 @@ public class SpellCheckComponent extends SearchComponent implements SolrCoreAwar
if (initParams != null) {
log.debug("Initializing spell checkers");
boolean hasDefault = false;
- for (int i = 0; i < initParams.size(); i++) {
- if (initParams.getName(i).equals("spellchecker")) {
- Object cfg = initParams.getVal(i);
+ // TODO addSpellChecker response should set hasDefault!
+
+ for (Map.Entry<String, ?> initEntry : initParams) {
+ if ("spellchecker".equals(initEntry.getKey())) {
+ Object cfg = initEntry.getValue();
if (cfg instanceof NamedList) {
addSpellChecker(core, hasDefault, (NamedList<?>) cfg);
} else if (cfg instanceof Map) {
diff --git a/solr/core/src/java/org/apache/solr/handler/component/StatsComponent.java b/solr/core/src/java/org/apache/solr/handler/component/StatsComponent.java
index 1ef317d30c5..6fefe8ff465 100644
--- a/solr/core/src/java/org/apache/solr/handler/component/StatsComponent.java
+++ b/solr/core/src/java/org/apache/solr/handler/component/StatsComponent.java
@@ -103,12 +103,7 @@ public class StatsComponent extends SearchComponent {
NamedList<NamedList<?>> stats_fields = unwrapStats(stats);
if (stats_fields != null) {
- for (int i = 0; i < stats_fields.size(); i++) {
- String key = stats_fields.getName(i);
- StatsValues stv = allStatsValues.get(key);
- NamedList<?> shardStv = stats_fields.get(key);
- stv.accumulate(shardStv);
- }
+ stats_fields.forEach((key, shardStv) -> allStatsValues.get(key).accumulate(shardStv));
}
}
}
diff --git a/solr/core/src/java/org/apache/solr/handler/component/StatsValuesFactory.java b/solr/core/src/java/org/apache/solr/handler/component/StatsValuesFactory.java
index 8be684e3efa..1c29502b935 100644
--- a/solr/core/src/java/org/apache/solr/handler/component/StatsValuesFactory.java
+++ b/solr/core/src/java/org/apache/solr/handler/component/StatsValuesFactory.java
@@ -239,29 +239,21 @@ public class StatsValuesFactory {
updateTypeSpecificStats(stv);
- NamedList<?> f = (NamedList<?>) stv.get(FACETS);
+ var f = (NamedList<NamedList<NamedList<?>>>) stv.get(FACETS);
if (f == null) {
return;
}
- for (int i = 0; i < f.size(); i++) {
- String field = f.getName(i);
- NamedList<?> vals = (NamedList<?>) f.getVal(i);
- Map<String, StatsValues> addTo = facets.get(field);
- if (addTo == null) {
- addTo = new HashMap<>();
- facets.put(field, addTo);
- }
- for (int j = 0; j < vals.size(); j++) {
- String val = vals.getName(j);
- StatsValues vvals = addTo.get(val);
- if (vvals == null) {
- vvals = createStatsValues(statsField);
- addTo.put(val, vvals);
- }
- vvals.accumulate((NamedList<?>) vals.getVal(j));
- }
- }
+ f.forEach(
+ (field, vals) -> {
+ Map<String, StatsValues> addTo = facets.computeIfAbsent(field, k -> new HashMap<>());
+ vals.forEach(
+ (val, vval) -> {
+ StatsValues vvals =
+ addTo.computeIfAbsent(val, k -> createStatsValues(statsField));
+ vvals.accumulate(vval);
+ });
+ });
}
@Override
diff --git a/solr/core/src/java/org/apache/solr/handler/component/SuggestComponent.java b/solr/core/src/java/org/apache/solr/handler/component/SuggestComponent.java
index 56b72b75ae6..4a306af3022 100644
--- a/solr/core/src/java/org/apache/solr/handler/component/SuggestComponent.java
+++ b/solr/core/src/java/org/apache/solr/handler/component/SuggestComponent.java
@@ -24,7 +24,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -116,9 +115,10 @@ public class SuggestComponent extends SearchComponent
if (initParams != null) {
log.info("Initializing SuggestComponent");
boolean hasDefault = false;
- for (int i = 0; i < initParams.size(); i++) {
- if (initParams.getName(i).equals(CONFIG_PARAM_LABEL)) {
- NamedList<?> suggesterParams = (NamedList<?>) initParams.getVal(i);
+ for (Map.Entry<String, ?> initEntry : initParams) {
+ String name = initEntry.getKey();
+ if (CONFIG_PARAM_LABEL.equals(name)) {
+ NamedList<?> suggesterParams = (NamedList<?>) initEntry.getValue();
SolrSuggester suggester = new SolrSuggester();
String dictionary = suggester.init(suggesterParams, core);
if (dictionary != null) {
@@ -485,34 +485,32 @@ public class SuggestComponent extends SearchComponent
return result;
}
// for each token
- for (Map.Entry<String, SimpleOrderedMap<NamedList<Object>>> entry : suggestionsMap) {
- String suggesterName = entry.getKey();
- for (Iterator<Map.Entry<String, NamedList<Object>>> suggestionsIter =
- entry.getValue().iterator();
- suggestionsIter.hasNext(); ) {
- Map.Entry<String, NamedList<Object>> suggestions = suggestionsIter.next();
- String tokenString = suggestions.getKey();
+ for (Map.Entry<String, SimpleOrderedMap<NamedList<Object>>> suggesterEntry : suggestionsMap) {
+ String suggesterName = suggesterEntry.getKey();
+ for (Map.Entry<String, NamedList<Object>> tokenEntry : suggesterEntry.getValue()) {
+ String tokenString = tokenEntry.getKey();
List<LookupResult> lookupResults = new ArrayList<>();
- NamedList<Object> suggestion = suggestions.getValue();
- // for each suggestion
- for (int j = 0; j < suggestion.size(); j++) {
- String property = suggestion.getName(j);
- if (property.equals(SuggesterResultLabels.SUGGESTIONS)) {
- @SuppressWarnings("unchecked")
- List<NamedList<Object>> suggestionEntries =
- (List<NamedList<Object>>) suggestion.getVal(j);
- for (NamedList<Object> suggestionEntry : suggestionEntries) {
- String term = (String) suggestionEntry.get(SuggesterResultLabels.SUGGESTION_TERM);
- Long weight = (Long) suggestionEntry.get(SuggesterResultLabels.SUGGESTION_WEIGHT);
- String payload =
- (String) suggestionEntry.get(SuggesterResultLabels.SUGGESTION_PAYLOAD);
- LookupResult res =
- new LookupResult(new CharsRef(term), weight, new BytesRef(payload));
- lookupResults.add(res);
- }
- }
- result.add(suggesterName, tokenString, lookupResults);
- }
+ tokenEntry
+ .getValue()
+ .forEach(
+ (property, value) -> {
+ if (property.equals(SuggesterResultLabels.SUGGESTIONS)) {
+ @SuppressWarnings("unchecked")
+ List<NamedList<Object>> suggestionEntries = (List<NamedList<Object>>) value;
+ for (NamedList<Object> suggestionEntry : suggestionEntries) {
+ String term =
+ (String) suggestionEntry.get(SuggesterResultLabels.SUGGESTION_TERM);
+ Long weight =
+ (Long) suggestionEntry.get(SuggesterResultLabels.SUGGESTION_WEIGHT);
+ String payload =
+ (String) suggestionEntry.get(SuggesterResultLabels.SUGGESTION_PAYLOAD);
+ LookupResult res =
+ new LookupResult(new CharsRef(term), weight, new BytesRef(payload));
+ lookupResults.add(res);
+ }
+ }
+ });
+ result.add(suggesterName, tokenString, lookupResults);
}
}
return result;
diff --git a/solr/core/src/java/org/apache/solr/request/NumericFacets.java b/solr/core/src/java/org/apache/solr/request/NumericFacets.java
index 698f14fa3a8..0584a46e5f8 100644
--- a/solr/core/src/java/org/apache/solr/request/NumericFacets.java
+++ b/solr/core/src/java/org/apache/solr/request/NumericFacets.java
@@ -342,9 +342,8 @@ final class NumericFacets {
final FunctionValues values = vs.getValues(Collections.emptyMap(), leaves.get(readerIdx));
alreadySeen.add(values.strVal(entry.docID - leaves.get(readerIdx).docBase));
}
- for (int i = 0; i < result.size(); ++i) {
- alreadySeen.add(result.getName(i));
- }
+ result.forEach((name, __) -> alreadySeen.add(name));
+
final Terms terms = searcher.getSlowAtomicReader().terms(fieldName);
if (terms != null) {
final String prefixStr = TrieField.getMainValuePrefix(ft);
diff --git a/solr/core/src/java/org/apache/solr/response/SchemaXmlWriter.java b/solr/core/src/java/org/apache/solr/response/SchemaXmlWriter.java
index 6d823a51a52..7ea7509564b 100644
--- a/solr/core/src/java/org/apache/solr/response/SchemaXmlWriter.java
+++ b/solr/core/src/java/org/apache/solr/response/SchemaXmlWriter.java
@@ -25,6 +25,7 @@ import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
@@ -109,10 +110,8 @@ public class SchemaXmlWriter extends TextResponseWriter {
List<SimpleOrderedMap<Object>> fieldPropertiesList = (List<SimpleOrderedMap<Object>>) val;
for (SimpleOrderedMap<Object> fieldProperties : fieldPropertiesList) {
openStartTag(IndexSchema.FIELD);
- for (int fieldPropNum = 0; fieldPropNum < fieldProperties.size(); ++fieldPropNum) {
- writeAttr(
- fieldProperties.getName(fieldPropNum),
- fieldProperties.getVal(fieldPropNum).toString());
+ for (Entry<String, Object> fieldProperty : fieldProperties) {
+ writeAttr(fieldProperty.getKey(), fieldProperty.getValue().toString());
}
closeStartTag(true);
}
@@ -121,12 +120,8 @@ public class SchemaXmlWriter extends TextResponseWriter {
(List<SimpleOrderedMap<Object>>) val;
for (SimpleOrderedMap<Object> dynamicFieldProperties : dynamicFieldPropertiesList) {
openStartTag(IndexSchema.DYNAMIC_FIELD);
- for (int dynamicFieldPropNum = 0;
- dynamicFieldPropNum < dynamicFieldProperties.size();
- ++dynamicFieldPropNum) {
- writeAttr(
- dynamicFieldProperties.getName(dynamicFieldPropNum),
- dynamicFieldProperties.getVal(dynamicFieldPropNum).toString());
+ for (Entry<String, Object> dynamicFieldProperty : dynamicFieldProperties) {
+ writeAttr(dynamicFieldProperty.getKey(), dynamicFieldProperty.getValue().toString());
}
closeStartTag(true);
}
@@ -135,12 +130,8 @@ public class SchemaXmlWriter extends TextResponseWriter {
(List<SimpleOrderedMap<Object>>) val;
for (SimpleOrderedMap<Object> copyFieldProperties : copyFieldPropertiesList) {
openStartTag(IndexSchema.COPY_FIELD);
- for (int copyFieldPropNum = 0;
- copyFieldPropNum < copyFieldProperties.size();
- ++copyFieldPropNum) {
- writeAttr(
- copyFieldProperties.getName(copyFieldPropNum),
- copyFieldProperties.getVal(copyFieldPropNum).toString());
+ for (Entry<String, Object> copyFieldProperty : copyFieldProperties) {
+ writeAttr(copyFieldProperty.getKey(), copyFieldProperty.getValue().toString());
}
closeStartTag(true);
}
@@ -162,29 +153,26 @@ public class SchemaXmlWriter extends TextResponseWriter {
SimpleOrderedMap<Object> multiTermAnalyzerProperties = null;
SimpleOrderedMap<Object> perFieldSimilarityProperties = null;
openStartTag(IndexSchema.FIELD_TYPE);
- for (int fieldTypePropNum = 0;
- fieldTypePropNum < fieldTypeProperties.size();
- ++fieldTypePropNum) {
- String fieldTypePropName = fieldTypeProperties.getName(fieldTypePropNum);
- if (fieldTypePropName.equals(FieldType.ANALYZER)) {
- analyzerProperties =
- (SimpleOrderedMap<Object>) fieldTypeProperties.getVal(fieldTypePropNum);
- } else if (fieldTypePropName.equals(FieldType.INDEX_ANALYZER)) {
- indexAnalyzerProperties =
- (SimpleOrderedMap<Object>) fieldTypeProperties.getVal(fieldTypePropNum);
- } else if (fieldTypePropName.equals(FieldType.QUERY_ANALYZER)) {
- queryAnalyzerProperties =
- (SimpleOrderedMap<Object>) fieldTypeProperties.getVal(fieldTypePropNum);
- } else if (fieldTypePropName.equals(FieldType.MULTI_TERM_ANALYZER)) {
- multiTermAnalyzerProperties =
- (SimpleOrderedMap<Object>) fieldTypeProperties.getVal(fieldTypePropNum);
- } else if (fieldTypePropName.equals(FieldType.SIMILARITY)) {
- perFieldSimilarityProperties =
- (SimpleOrderedMap<Object>) fieldTypeProperties.getVal(fieldTypePropNum);
- } else {
- writeAttr(fieldTypePropName, fieldTypeProperties.getVal(fieldTypePropNum).toString());
+
+ for (Entry<String, Object> fieldTypeProperty : fieldTypeProperties) {
+ String fieldTypePropName = fieldTypeProperty.getKey();
+ Object fieldTypePropValue = fieldTypeProperty.getValue();
+
+ switch (fieldTypePropName) {
+ case FieldType.ANALYZER -> analyzerProperties =
+ (SimpleOrderedMap<Object>) fieldTypePropValue;
+ case FieldType.INDEX_ANALYZER -> indexAnalyzerProperties =
+ (SimpleOrderedMap<Object>) fieldTypePropValue;
+ case FieldType.QUERY_ANALYZER -> queryAnalyzerProperties =
+ (SimpleOrderedMap<Object>) fieldTypePropValue;
+ case FieldType.MULTI_TERM_ANALYZER -> multiTermAnalyzerProperties =
+ (SimpleOrderedMap<Object>) fieldTypePropValue;
+ case FieldType.SIMILARITY -> perFieldSimilarityProperties =
+ (SimpleOrderedMap<Object>) fieldTypePropValue;
+ default -> writeAttr(fieldTypePropName, fieldTypePropValue.toString());
}
}
+
boolean isEmptyTag =
null == analyzerProperties
&& null == indexAnalyzerProperties
@@ -236,20 +224,21 @@ public class SchemaXmlWriter extends TextResponseWriter {
List<SimpleOrderedMap<Object>> charFilterPropertiesList = null;
SimpleOrderedMap<Object> tokenizerProperties = null;
List<SimpleOrderedMap<Object>> filterPropertiesList = null;
- for (int i = 0; i < analyzerProperties.size(); ++i) {
- String name = analyzerProperties.getName(i);
- if (name.equals(FieldType.CHAR_FILTERS)) {
- charFilterPropertiesList = (List<SimpleOrderedMap<Object>>) analyzerProperties.getVal(i);
- } else if (name.equals(FieldType.TOKENIZER)) {
- tokenizerProperties = (SimpleOrderedMap<Object>) analyzerProperties.getVal(i);
- } else if (name.equals(FieldType.FILTERS)) {
- filterPropertiesList = (List<SimpleOrderedMap<Object>>) analyzerProperties.getVal(i);
- } else if (name.equals(FieldType.CLASS_NAME)) {
- if (!"solr.TokenizerChain".equals(analyzerProperties.getVal(i))) {
- writeAttr(name, analyzerProperties.getVal(i).toString());
+
+ for (Entry<String, Object> analyzerProperty : analyzerProperties) {
+ String name = analyzerProperty.getKey();
+ Object value = analyzerProperty.getValue();
+ switch (name) {
+ case FieldType.CHAR_FILTERS -> charFilterPropertiesList =
+ (List<SimpleOrderedMap<Object>>) value;
+ case FieldType.TOKENIZER -> tokenizerProperties = (SimpleOrderedMap<Object>) value;
+ case FieldType.FILTERS -> filterPropertiesList = (List<SimpleOrderedMap<Object>>) value;
+ case FieldType.CLASS_NAME -> {
+ if (!"solr.TokenizerChain".equals(value)) {
+ writeAttr(name, value.toString());
+ }
}
- } else if (name.equals(IndexSchema.LUCENE_MATCH_VERSION_PARAM)) {
- writeAttr(name, analyzerProperties.getVal(i).toString());
+ case IndexSchema.LUCENE_MATCH_VERSION_PARAM -> writeAttr(name, value.toString());
}
}
boolean isEmptyTag =
@@ -264,24 +253,24 @@ public class SchemaXmlWriter extends TextResponseWriter {
if (null != charFilterPropertiesList) {
for (SimpleOrderedMap<Object> charFilterProperties : charFilterPropertiesList) {
openStartTag(FieldType.CHAR_FILTER);
- for (int i = 0; i < charFilterProperties.size(); ++i) {
- writeAttr(charFilterProperties.getName(i), charFilterProperties.getVal(i).toString());
+ for (Entry<String, Object> entry : charFilterProperties) {
+ writeAttr(entry.getKey(), entry.getValue().toString());
}
closeStartTag(true);
}
}
if (null != tokenizerProperties) {
openStartTag(FieldType.TOKENIZER);
- for (int i = 0; i < tokenizerProperties.size(); ++i) {
- writeAttr(tokenizerProperties.getName(i), tokenizerProperties.getVal(i).toString());
+ for (Entry<String, Object> entry : tokenizerProperties) {
+ writeAttr(entry.getKey(), entry.getValue().toString());
}
closeStartTag(true);
}
if (null != filterPropertiesList) {
for (SimpleOrderedMap<Object> filterProperties : filterPropertiesList) {
openStartTag(FieldType.FILTER);
- for (int i = 0; i < filterProperties.size(); ++i) {
- writeAttr(filterProperties.getName(i), filterProperties.getVal(i).toString());
+ for (Entry<String, Object> entry : filterProperties) {
+ writeAttr(entry.getKey(), entry.getValue().toString());
}
closeStartTag(true);
}
@@ -337,11 +326,10 @@ public class SchemaXmlWriter extends TextResponseWriter {
@Override
public void writeNamedList(String name, NamedList<?> val) throws IOException {
// name is ignored - this method is only used for SimilarityFactory
- int sz = val.size();
- for (int i = 0; i < sz; i++) {
- String valName = val.getName(i);
+ for (Map.Entry<String, ?> entry : val) {
+ String valName = entry.getKey();
if (!valName.equals(SimilarityFactory.CLASS_NAME)) {
- writeVal(valName, val.getVal(i));
+ writeVal(valName, entry.getValue());
}
}
}
diff --git a/solr/core/src/java/org/apache/solr/response/SolrQueryResponse.java b/solr/core/src/java/org/apache/solr/response/SolrQueryResponse.java
index 5676a63fe10..5d102adc848 100644
--- a/solr/core/src/java/org/apache/solr/response/SolrQueryResponse.java
+++ b/solr/core/src/java/org/apache/solr/response/SolrQueryResponse.java
@@ -298,12 +298,12 @@ public class SolrQueryResponse {
/** Returns a string of the form "prefix name1=value1 name2=value2 ..." */
public String getToLogAsString(String prefix) {
StringBuilder sb = new StringBuilder(prefix);
- for (int i = 0; i < toLog.size(); i++) {
- if (sb.length() > 0) {
+ for (Map.Entry<String, Object> entry : toLog) {
+ if (!sb.isEmpty()) {
sb.append(' ');
}
- String name = toLog.getName(i);
- Object val = toLog.getVal(i);
+ String name = entry.getKey();
+ Object val = entry.getValue();
if (name != null) {
sb.append(name).append('=');
}
diff --git a/solr/core/src/java/org/apache/solr/search/facet/FacetBucket.java b/solr/core/src/java/org/apache/solr/search/facet/FacetBucket.java
index 7584cdba6bb..be6471e1e9e 100644
--- a/solr/core/src/java/org/apache/solr/search/facet/FacetBucket.java
+++ b/solr/core/src/java/org/apache/solr/search/facet/FacetBucket.java
@@ -82,24 +82,23 @@ public class FacetBucket {
mcontext.setShardFlag(bucketNumber);
// drive merging off the received bucket?
- for (int i = 0; i < bucket.size(); i++) {
- String key = bucket.getName(i);
- Object val = bucket.getVal(i);
- if ("count".equals(key)) {
- count += ((Number) val).longValue();
- continue;
- }
- if ("val".equals(key)) {
- // this is taken care of at a higher level...
- continue;
- }
+ bucket.forEach(
+ (key, val) -> {
+ if ("count".equals(key)) {
+ count += ((Number) val).longValue();
+ return;
+ }
+ if ("val".equals(key)) {
+ // this is taken care of at a higher level...
+ return;
+ }
- FacetMerger merger = getMerger(key, val);
+ FacetMerger merger = getMerger(key, val);
- if (merger != null) {
- merger.merge(val, mcontext);
- }
- }
+ if (merger != null) {
+ merger.merge(val, mcontext);
+ }
+ });
}
public SimpleOrderedMap<Object> getMergedBucket() {
diff --git a/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/TopGroupsResultTransformer.java b/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/TopGroupsResultTransformer.java
index 5a924151fe5..a066f7d44a7 100644
--- a/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/TopGroupsResultTransformer.java
+++ b/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/TopGroupsResultTransformer.java
@@ -26,6 +26,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import org.apache.lucene.document.Document;
import org.apache.lucene.search.FieldDoc;
import org.apache.lucene.search.ScoreDoc;
@@ -128,10 +129,17 @@ public class TopGroupsResultTransformer
Integer totalHitCount = (Integer) commandResult.get("totalHitCount");
List<GroupDocs<BytesRef>> groupDocs = new ArrayList<>();
- for (int i = 2; i < commandResult.size(); i++) {
- String groupValue = commandResult.getName(i);
+
+ // Skip first two entries (totalGroupedHitCount and totalHitCount) and process the rest
+ int skipCount = 0;
+ for (Entry<String, ?> groupEntry : commandResult) {
+ if (skipCount++ < 2) {
+ continue;
+ }
+
+ String groupValue = groupEntry.getKey();
@SuppressWarnings("unchecked")
- NamedList<Object> groupResult = (NamedList<Object>) commandResult.getVal(i);
+ NamedList<Object> groupResult = (NamedList<Object>) groupEntry.getValue();
// previously Integer now Long
Number totalGroupHits = (Number) groupResult.get("totalHits");
Float maxScore = (Float) groupResult.get("maxScore");
diff --git a/solr/core/src/java/org/apache/solr/spelling/suggest/DocumentExpressionDictionaryFactory.java b/solr/core/src/java/org/apache/solr/spelling/suggest/DocumentExpressionDictionaryFactory.java
index 2b943eb653c..ee8fdb3ce22 100644
--- a/solr/core/src/java/org/apache/solr/spelling/suggest/DocumentExpressionDictionaryFactory.java
+++ b/solr/core/src/java/org/apache/solr/spelling/suggest/DocumentExpressionDictionaryFactory.java
@@ -65,14 +65,13 @@ public class DocumentExpressionDictionaryFactory extends DictionaryFactory {
if (weightExpression == null) {
throw new IllegalArgumentException(WEIGHT_EXPRESSION + " is a mandatory parameter");
}
-
- for (int i = 0; i < params.size(); i++) {
- if (params.getName(i).equals(SORT_FIELD)) {
- String sortFieldName = (String) params.getVal(i);
-
- sortFields.add(getSortField(core, sortFieldName));
- }
- }
+ params.forEach(
+ (name, value) -> {
+ if (name.equals(SORT_FIELD)) {
+ String sortFieldName = (String) value;
+ sortFields.add(getSortField(core, sortFieldName));
+ }
+ });
return new DocumentValueSourceDictionary(
searcher.getIndexReader(),
diff --git a/solr/core/src/java/org/apache/solr/update/processor/AbstractDefaultValueUpdateProcessorFactory.java b/solr/core/src/java/org/apache/solr/update/processor/AbstractDefaultValueUpdateProcessorFactory.java
index daa5b589dd7..c62259e59e0 100644
--- a/solr/core/src/java/org/apache/solr/update/processor/AbstractDefaultValueUpdateProcessorFactory.java
+++ b/solr/core/src/java/org/apache/solr/update/processor/AbstractDefaultValueUpdateProcessorFactory.java
@@ -52,7 +52,7 @@ public abstract class AbstractDefaultValueUpdateProcessorFactory
}
if (0 < args.size()) {
- throw new SolrException(SERVER_ERROR, "Unexpected init param(s): '" + args.getName(0) + "'");
+ throw new SolrException(SERVER_ERROR, "Unexpected init param(s): " + args);
}
super.init(args);
diff --git a/solr/core/src/java/org/apache/solr/update/processor/CloneFieldUpdateProcessorFactory.java b/solr/core/src/java/org/apache/solr/update/processor/CloneFieldUpdateProcessorFactory.java
index 4240454b84d..f9978a3ed22 100644
--- a/solr/core/src/java/org/apache/solr/update/processor/CloneFieldUpdateProcessorFactory.java
+++ b/solr/core/src/java/org/apache/solr/update/processor/CloneFieldUpdateProcessorFactory.java
@@ -216,7 +216,7 @@ public class CloneFieldUpdateProcessorFactory extends UpdateRequestProcessorFact
}
if (0 < args.size()) {
- throw new SolrException(SERVER_ERROR, "Unexpected init param(s): '" + args.getName(0) + "'");
+ throw new SolrException(SERVER_ERROR, "Unexpected init param(s): " + args);
}
super.init(args);
@@ -236,7 +236,7 @@ public class CloneFieldUpdateProcessorFactory extends UpdateRequestProcessorFact
// if we got here we know we had pattern and replacement, now check for the other two so that
// we can give a better message than "unexpected"
- if (0 <= args.indexOf(SOURCE_PARAM, 0) || 0 <= args.indexOf(DEST_PARAM, 0)) {
+ if (0 <= args.indexOf(SOURCE_PARAM) || 0 <= args.indexOf(DEST_PARAM)) {
throw new SolrException(
SERVER_ERROR,
"Short hand syntax must not be mixed with full syntax. Found "
@@ -359,9 +359,8 @@ public class CloneFieldUpdateProcessorFactory extends UpdateRequestProcessorFact
SERVER_ERROR,
"Init param '"
+ SOURCE_PARAM
- + "' has unexpected 'exclude' sub-param(s): '"
- + selectorConfig.getName(0)
- + "'");
+ + "' has unexpected 'exclude' sub-param(s): "
+ + selectorConfig);
}
// call once per instance
selectorConfig.remove("exclude");
@@ -372,9 +371,8 @@ public class CloneFieldUpdateProcessorFactory extends UpdateRequestProcessorFact
SERVER_ERROR,
"Init param '"
+ SOURCE_PARAM
- + "' contains unexpected child param(s): '"
- + selectorConfig.getName(0)
- + "'");
+ + "' contains unexpected child param(s): "
+ + selectorConfig);
}
// consume from the named list so it doesn't interfere with subsequent processing
sources.remove(0);
@@ -428,12 +426,7 @@ public class CloneFieldUpdateProcessorFactory extends UpdateRequestProcessorFact
}
if (0 != destList.size()) {
throw new SolrException(
- SERVER_ERROR,
- "Init param '"
- + DEST_PARAM
- + "' has unexpected children: '"
- + destList.getName(0)
- + "'");
+ SERVER_ERROR, "Init param '" + DEST_PARAM + "' has unexpected children: " + destList);
}
try {
diff --git a/solr/core/src/java/org/apache/solr/update/processor/FieldMutatingUpdateProcessorFactory.java b/solr/core/src/java/org/apache/solr/update/processor/FieldMutatingUpdateProcessorFactory.java
index 7571d918a14..97a246278ba 100644
--- a/solr/core/src/java/org/apache/solr/update/processor/FieldMutatingUpdateProcessorFactory.java
+++ b/solr/core/src/java/org/apache/solr/update/processor/FieldMutatingUpdateProcessorFactory.java
@@ -173,7 +173,7 @@ public abstract class FieldMutatingUpdateProcessorFactory extends UpdateRequestP
if (0 < exc.size()) {
throw new SolrException(
SolrException.ErrorCode.SERVER_ERROR,
- "Unexpected 'exclude' init sub-param(s): '" + args.getName(0) + "'");
+ "Unexpected 'exclude' init sub-param(s): " + args);
}
// call once per instance
args.remove("exclude");
@@ -196,8 +196,7 @@ public abstract class FieldMutatingUpdateProcessorFactory extends UpdateRequestP
if (0 < args.size()) {
throw new SolrException(
- SolrException.ErrorCode.SERVER_ERROR,
- "Unexpected init param(s): '" + args.getName(0) + "'");
+ SolrException.ErrorCode.SERVER_ERROR, "Unexpected init param(s): " + args);
}
}
diff --git a/solr/core/src/java/org/apache/solr/update/processor/IgnoreLargeDocumentProcessorFactory.java b/solr/core/src/java/org/apache/solr/update/processor/IgnoreLargeDocumentProcessorFactory.java
index 7f9d1c250d9..e7a58d517bb 100644
--- a/solr/core/src/java/org/apache/solr/update/processor/IgnoreLargeDocumentProcessorFactory.java
+++ b/solr/core/src/java/org/apache/solr/update/processor/IgnoreLargeDocumentProcessorFactory.java
@@ -61,7 +61,7 @@ public class IgnoreLargeDocumentProcessorFactory extends UpdateRequestProcessorF
args.remove(PERMISSIVE_MODE_PARAM);
if (args.size() > 0) {
- throw new SolrException(SERVER_ERROR, "Unexpected init param(s): '" + args.getName(0) + "'");
+ throw new SolrException(SERVER_ERROR, "Unexpected init param(s): " + args);
}
}
diff --git a/solr/core/src/java/org/apache/solr/update/processor/TolerantUpdateProcessor.java b/solr/core/src/java/org/apache/solr/update/processor/TolerantUpdateProcessor.java
index 36bfa0fd47e..1ee9592bb5d 100644
--- a/solr/core/src/java/org/apache/solr/update/processor/TolerantUpdateProcessor.java
+++ b/solr/core/src/java/org/apache/solr/update/processor/TolerantUpdateProcessor.java
@@ -21,6 +21,7 @@ import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
+import java.util.Map.Entry;
import java.util.Set;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.CharsRefBuilder;
@@ -249,10 +250,10 @@ public class TolerantUpdateProcessor extends UpdateRequestProcessor {
continue;
}
- for (int i = 0; i < remoteErrMetadata.size(); i++) {
+ for (Entry<String, String> errEntry : remoteErrMetadata) {
ToleratedUpdateError err =
ToleratedUpdateError.parseMetadataIfToleratedUpdateError(
- remoteErrMetadata.getName(i), remoteErrMetadata.getVal(i));
+ errEntry.getKey(), errEntry.getValue());
if (null == err) {
// some metadata unrelated to this update processor
continue;
diff --git a/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java b/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java
index d820d699985..e6814b3fd0f 100644
--- a/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java
+++ b/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java
@@ -808,15 +808,15 @@ public class SolrPluginUtils {
Map<Object, ShardDoc> resultIds,
Map.Entry<String, Object>[] destArr) {
assert resultIds.size() == destArr.length;
- for (int i = 0; i < namedList.size(); i++) {
- String id = namedList.getName(i);
- // TODO: lookup won't work for non-string ids... String vs Float
- ShardDoc sdoc = resultIds.get(id);
- if (sdoc != null) { // maybe null when rb.onePassDistributedQuery
- int idx = sdoc.positionInResponse;
- destArr[idx] = new NamedList.NamedListEntry<>(id, namedList.getVal(i));
- }
- }
+ namedList.forEach(
+ (id, val) -> {
+ // TODO: lookup won't work for non-string ids... String vs Float
+ ShardDoc sdoc = resultIds.get(id);
+ if (sdoc != null) { // maybe null when rb.onePassDistributedQuery
+ int idx = sdoc.positionInResponse;
+ destArr[idx] = new NamedList.NamedListEntry<>(id, val);
+ }
+ });
}
/**
diff --git a/solr/core/src/test/org/apache/solr/TestTolerantSearch.java b/solr/core/src/test/org/apache/solr/TestTolerantSearch.java
index 5d5841ba9e0..a0af557e739 100644
--- a/solr/core/src/test/org/apache/solr/TestTolerantSearch.java
+++ b/solr/core/src/test/org/apache/solr/TestTolerantSearch.java
@@ -149,9 +149,9 @@ public class TestTolerantSearch extends SolrJettyTestBase {
NamedList<Object> shardsInfo =
((NamedList<Object>) response.getResponse().get(ShardParams.SHARDS_INFO));
boolean foundError = false;
- for (int i = 0; i < shardsInfo.size(); i++) {
- if (shardsInfo.getName(i).contains("collection2")) {
- assertNotNull(((NamedList<Object>) shardsInfo.getVal(i)).get("error"));
+ for (var infoEntry : shardsInfo) {
+ if (infoEntry.getKey().contains("collection2")) {
+ assertNotNull(((NamedList<Object>) infoEntry.getValue()).get("error"));
foundError = true;
break;
}
@@ -199,9 +199,9 @@ public class TestTolerantSearch extends SolrJettyTestBase {
NamedList<Object> shardsInfo =
((NamedList<Object>) response.getResponse().get(ShardParams.SHARDS_INFO));
boolean foundError = false;
- for (int i = 0; i < shardsInfo.size(); i++) {
- if (shardsInfo.getName(i).contains("collection2")) {
- assertNotNull(((NamedList<Object>) shardsInfo.getVal(i)).get("error"));
+ for (var infoEntry : shardsInfo) {
+ if (infoEntry.getKey().contains("collection2")) {
+ assertNotNull(((NamedList<Object>) infoEntry.getValue()).get("error"));
foundError = true;
break;
}
diff --git a/solr/core/src/test/org/apache/solr/cloud/TestTolerantUpdateProcessorCloud.java b/solr/core/src/test/org/apache/solr/cloud/TestTolerantUpdateProcessorCloud.java
index f045d7d4522..958621541bf 100644
--- a/solr/core/src/test/org/apache/solr/cloud/TestTolerantUpdateProcessorCloud.java
+++ b/solr/core/src/test/org/apache/solr/cloud/TestTolerantUpdateProcessorCloud.java
@@ -705,10 +705,10 @@ public class TestTolerantUpdateProcessorCloud extends SolrCloudTestCase {
Set<ToleratedUpdateError> actualKnownErrs =
new LinkedHashSet<ToleratedUpdateError>(remoteErrMetadata.size());
int actualKnownErrsCount = 0;
- for (int i = 0; i < remoteErrMetadata.size(); i++) {
+ for (var entry : remoteErrMetadata) {
ToleratedUpdateError err =
ToleratedUpdateError.parseMetadataIfToleratedUpdateError(
- remoteErrMetadata.getName(i), remoteErrMetadata.getVal(i));
+ entry.getKey(), entry.getValue());
if (null == err) {
// some metadata unrelated to this update processor
continue;
@@ -912,10 +912,10 @@ public class TestTolerantUpdateProcessorCloud extends SolrCloudTestCase {
NamedList<String> remoteErrMetadata = e.getMetadata();
assertNotNull("no metadata in: " + e, remoteErrMetadata);
int actualKnownErrsCount = 0;
- for (int i = 0; i < remoteErrMetadata.size(); i++) {
+ for (var entry : remoteErrMetadata) {
ToleratedUpdateError err =
ToleratedUpdateError.parseMetadataIfToleratedUpdateError(
- remoteErrMetadata.getName(i), remoteErrMetadata.getVal(i));
+ entry.getKey(), entry.getValue());
if (null == err) {
// some metadata unrelated to this update processor
continue;
@@ -1105,10 +1105,10 @@ public class TestTolerantUpdateProcessorCloud extends SolrCloudTestCase {
Set<ToleratedUpdateError> actualKnownErrs =
new LinkedHashSet<ToleratedUpdateError>(remoteErrMetadata.size());
int actualKnownErrsCount = 0;
- for (int i = 0; i < remoteErrMetadata.size(); i++) {
+ for (var entry : remoteErrMetadata) {
ToleratedUpdateError err =
ToleratedUpdateError.parseMetadataIfToleratedUpdateError(
- remoteErrMetadata.getName(i), remoteErrMetadata.getVal(i));
+ entry.getKey(), entry.getValue());
if (null == err) {
// some metadata unrelated to this update processor
continue;
diff --git a/solr/core/src/test/org/apache/solr/handler/component/CustomHighlightComponentTest.java b/solr/core/src/test/org/apache/solr/handler/component/CustomHighlightComponentTest.java
index aebb03d5a48..3c7c79ca904 100644
--- a/solr/core/src/test/org/apache/solr/handler/component/CustomHighlightComponentTest.java
+++ b/solr/core/src/test/org/apache/solr/handler/component/CustomHighlightComponentTest.java
@@ -51,12 +51,13 @@ public class CustomHighlightComponentTest extends SolrCloudTestCase {
@Override
protected Object convertHighlights(NamedList<Object> hl) {
final ArrayList<SimpleOrderedMap<Object>> hlMaps = new ArrayList<>();
- for (int i = 0; i < hl.size(); ++i) {
- SimpleOrderedMap<Object> hlMap = new SimpleOrderedMap<>();
- hlMap.add(id_key, hl.getName(i));
- hlMap.add(snippets_key, hl.getVal(i));
- hlMaps.add(hlMap);
- }
+ hl.forEach(
+ (name, val) -> {
+ SimpleOrderedMap<Object> hlMap = new SimpleOrderedMap<>();
+ hlMap.add(id_key, name);
+ hlMap.add(snippets_key, val);
+ hlMaps.add(hlMap);
+ });
return hlMaps;
}
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 dfe5118a9a4..0476aa583bf 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
@@ -2258,11 +2258,16 @@ public class StatsComponentTest extends SolrTestCaseJ4 {
"{!percentiles='" + percentiles + "'}stat_f")) {
SolrQueryResponse rsp = h.queryAndResponse(null, query);
NamedList<Double> pout = extractPercentiles(rsp, "stat_f");
- for (int i = 0; i < percentilesList.size(); i++) {
- // ensure exact order, but all values should be null (empty result set)
- assertEquals(percentilesList.get(i), pout.getName(i));
- assertNull(pout.getVal(i));
- }
+
+ assertEquals(percentilesList.size(), pout.size());
+ Iterator<String> percentileIter = percentilesList.iterator();
+ pout.forEach(
+ (pKey, pVal) -> {
+ String p = percentileIter.next();
+ // ensure exact order, but all values should be null (empty result set)
+ assertEquals(p, pKey);
+ assertNull(pVal);
+ });
}
int id = 0;
@@ -2286,11 +2291,15 @@ public class StatsComponentTest extends SolrTestCaseJ4 {
"{!percentiles='" + percentiles + "'}stat_f")) {
SolrQueryResponse rsp = h.queryAndResponse(null, query);
NamedList<Double> pout = extractPercentiles(rsp, "stat_f");
- for (int i = 0; i < percentilesList.size(); i++) {
- String p = percentilesList.get(i);
- assertEquals(p, pout.getName(i));
- assertEquals(Double.parseDouble(p), pout.getVal(i), 1.0D);
- }
+
+ assertEquals(percentilesList.size(), pout.size());
+ Iterator<String> percentileIter = percentilesList.iterator();
+ pout.forEach(
+ (pKey, pVal) -> {
+ String p = percentileIter.next();
+ assertEquals(p, pKey);
+ assertEquals(Double.parseDouble(p), pVal, 1.0D);
+ });
}
// test request for no percentiles
diff --git a/solr/core/src/test/org/apache/solr/request/TestIntervalFaceting.java b/solr/core/src/test/org/apache/solr/request/TestIntervalFaceting.java
index d66e6c6fa45..85c0ee433bb 100644
--- a/solr/core/src/test/org/apache/solr/request/TestIntervalFaceting.java
+++ b/solr/core/src/test/org/apache/solr/request/TestIntervalFaceting.java
@@ -21,9 +21,7 @@ import java.lang.invoke.MethodHandles;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
-import java.util.HashSet;
import java.util.Locale;
-import java.util.Set;
import org.apache.lucene.util.BytesRef;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrClient;
@@ -514,37 +512,28 @@ public class TestIntervalFaceting extends SolrTestCaseJ4 {
+ facetIntervals,
facetQueries.size(),
getCountDistinctIntervals(facetIntervals));
- for (int i = 0; i < facetIntervals.size(); i++) {
- assertEquals(
- "Interval did not match: "
- + field
- + ": "
- + facetIntervals.getName(i)
- + "\nResponse: "
- + rsp.getValues().get("facet_counts"),
- facetQueries
- .get(
- field
- + ":"
- + facetIntervals
- .getName(i)
- .replace(",", " TO ")
- .replace('(', '{')
- .replace(')', '}'))
- .toString(),
- facetIntervals.getVal(i).toString());
- }
+ facetIntervals.forEach(
+ (name, val) -> {
+ assertEquals(
+ "Interval did not match: "
+ + field
+ + ": "
+ + name
+ + "\nResponse: "
+ + rsp.getValues().get("facet_counts"),
+ facetQueries
+ .get(
+ field + ":" + name.replace(",", " TO ").replace('(', '{').replace(')', '}'))
+ .toString(),
+ val.toString());
+ });
} finally {
req.close();
}
}
private int getCountDistinctIntervals(NamedList<Object> facetIntervals) {
- Set<String> distinctIntervals = new HashSet<>(facetIntervals.size());
- for (int i = 0; i < facetIntervals.size(); i++) {
- distinctIntervals.add(facetIntervals.getName(i));
- }
- return distinctIntervals.size();
+ return facetIntervals.asMap(0).size();
}
/**
diff --git a/solr/core/src/test/org/apache/solr/search/RankQueryTestPlugin.java b/solr/core/src/test/org/apache/solr/search/RankQueryTestPlugin.java
index 674836772f7..86dfb310438 100644
--- a/solr/core/src/test/org/apache/solr/search/RankQueryTestPlugin.java
+++ b/solr/core/src/test/org/apache/solr/search/RankQueryTestPlugin.java
@@ -22,8 +22,10 @@ import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Objects;
import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.IndexReaderContext;
@@ -664,7 +666,7 @@ public class RankQueryTestPlugin extends QParserPlugin {
}
}
- @SuppressWarnings({"unchecked", "rawtypes"})
+ @SuppressWarnings({"rawtypes", "unchecked"})
private NamedList unmarshalSortValues(SortSpec sortSpec, NamedList sortFieldValues) {
NamedList unmarshalledSortValsPerField = new NamedList<>();
@@ -673,7 +675,7 @@ public class RankQueryTestPlugin extends QParserPlugin {
List<SchemaField> schemaFields = sortSpec.getSchemaFields();
SortField[] sortFields = sortSpec.getSort().getSort();
- int marshalledFieldNum = 0;
+ Iterator<Entry<String, Object>> sortFieldValuesIter = sortFieldValues.iterator();
for (int sortFieldNum = 0; sortFieldNum < sortFields.length; sortFieldNum++) {
final SortField sortField = sortFields[sortFieldNum];
final SortField.Type type = sortField.getType();
@@ -682,13 +684,14 @@ public class RankQueryTestPlugin extends QParserPlugin {
if (type == SortField.Type.SCORE || type == SortField.Type.DOC) continue;
final String sortFieldName = sortField.getField();
- final String valueFieldName = sortFieldValues.getName(marshalledFieldNum);
+ final Map.Entry<String, Object> sortFieldValuesEntry = sortFieldValuesIter.next();
+ final String valueFieldName = sortFieldValuesEntry.getKey();
SolrTestCase.assertEquals(
"sortFieldValues name key does not match expected SortField.getField",
sortFieldName,
valueFieldName);
- List sortVals = (List) sortFieldValues.getVal(marshalledFieldNum);
+ List sortVals = (List) sortFieldValuesEntry.getValue();
final SchemaField schemaField = schemaFields.get(sortFieldNum);
if (null == schemaField) {
@@ -701,7 +704,6 @@ public class RankQueryTestPlugin extends QParserPlugin {
}
unmarshalledSortValsPerField.add(sortField.getField(), unmarshalledSortVals);
}
- marshalledFieldNum++;
}
return unmarshalledSortValsPerField;
}
diff --git a/solr/modules/analysis-extras/src/java/org/apache/solr/update/processor/OpenNLPExtractNamedEntitiesUpdateProcessorFactory.java b/solr/modules/analysis-extras/src/java/org/apache/solr/update/processor/OpenNLPExtractNamedEntitiesUpdateProcessorFactory.java
index 338eeea0e5e..d8e81977523 100644
--- a/solr/modules/analysis-extras/src/java/org/apache/solr/update/processor/OpenNLPExtractNamedEntitiesUpdateProcessorFactory.java
+++ b/solr/modules/analysis-extras/src/java/org/apache/solr/update/processor/OpenNLPExtractNamedEntitiesUpdateProcessorFactory.java
@@ -258,7 +258,7 @@ public class OpenNLPExtractNamedEntitiesUpdateProcessorFactory extends UpdateReq
analyzerFieldType = analyzerFieldTypeParam.toString();
if (0 < args.size()) {
- throw new SolrException(SERVER_ERROR, "Unexpected init param(s): '" + args.getName(0) + "'");
+ throw new SolrException(SERVER_ERROR, "Unexpected init param(s): " + args);
}
super.init(args);
@@ -404,9 +404,8 @@ public class OpenNLPExtractNamedEntitiesUpdateProcessorFactory extends UpdateReq
SERVER_ERROR,
"Init param '"
+ SOURCE_PARAM
- + "' has unexpected 'exclude' sub-param(s): '"
- + selectorConfig.getName(0)
- + "'");
+ + "' has unexpected 'exclude' sub-param(s): "
+ + selectorConfig);
}
// call once per instance
selectorConfig.remove("exclude");
@@ -417,15 +416,14 @@ public class OpenNLPExtractNamedEntitiesUpdateProcessorFactory extends UpdateReq
SERVER_ERROR,
"Init param '"
+ SOURCE_PARAM
- + "' contains unexpected child param(s): '"
- + selectorConfig.getName(0)
- + "'");
+ + "' contains unexpected child param(s): "
+ + selectorConfig);
}
// consume from the named list so it doesn't interfere with subsequent processing
sources.remove(0);
}
}
- if (1 <= sources.size()) {
+ if (!sources.isEmpty()) {
// source better be one or more strings
srcInclusions.fieldName = new HashSet<>(args.removeConfigArgs("source"));
}
@@ -473,12 +471,7 @@ public class OpenNLPExtractNamedEntitiesUpdateProcessorFactory extends UpdateReq
}
if (0 != destList.size()) {
throw new SolrException(
- SERVER_ERROR,
- "Init param '"
- + DEST_PARAM
- + "' has unexpected children: '"
- + destList.getName(0)
- + "'");
+ SERVER_ERROR, "Init param '" + DEST_PARAM + "' has unexpected children: " + destList);
}
try {
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/ScoreNodesStream.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/ScoreNodesStream.java
index 9f0d083a308..2b3847dfa5c 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/ScoreNodesStream.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/ScoreNodesStream.java
@@ -24,6 +24,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.io.SolrClientCache;
import org.apache.solr.client.solrj.io.Tuple;
@@ -230,7 +231,6 @@ public class ScoreNodesStream extends TupleStream implements Expressible {
QueryRequest request = new QueryRequest(params);
try {
-
// Get the response from the terms component
NamedList<?> response = client.request(request, collection);
@SuppressWarnings({"unchecked"})
@@ -239,28 +239,23 @@ public class ScoreNodesStream extends TupleStream implements Expressible {
@SuppressWarnings({"unchecked"})
NamedList<NamedList<Number>> fields = (NamedList<NamedList<Number>>) response.get("terms");
- int size = fields.size();
- for (int i = 0; i < size; i++) {
- String fieldName = fields.getName(i);
- NamedList<Number> terms = fields.get(fieldName);
- int tsize = terms.size();
- for (int t = 0; t < tsize; t++) {
- String term = terms.getName(t);
- Number docFreq = terms.get(term);
- Tuple tuple = nodes.get(term);
- if (!tuple.getFields().containsKey(termFreq)) {
- throw new Exception("termFreq field not present in the Tuple");
- }
- Number termFreqValue = (Number) tuple.get(termFreq);
- float score =
- (float) (Math.log(termFreqValue.floatValue()) + 1.0)
- * (float) (Math.log((numDocs + 1) / (docFreq.doubleValue() + 1)) + 1.0);
- tuple.put("nodeScore", score);
- tuple.put("docFreq", docFreq);
- tuple.put("numDocs", numDocs);
- }
- }
- } catch (Exception e) {
+ fields.forEach(
+ (fieldName, terms) ->
+ terms.forEach(
+ (term, docFreq) -> {
+ Tuple tuple = nodes.get(term);
+ if (!tuple.getFields().containsKey(termFreq)) {
+ throw new RuntimeException("termFreq field not present in the Tuple");
+ }
+ Number termFreqValue = (Number) tuple.get(termFreq);
+ float score =
+ (float) (Math.log(termFreqValue.floatValue()) + 1.0)
+ * (float) (Math.log((numDocs + 1) / (docFreq.doubleValue() + 1)) + 1.0);
+ tuple.put("nodeScore", score);
+ tuple.put("docFreq", docFreq);
+ tuple.put("numDocs", numDocs);
+ }));
+ } catch (SolrServerException e) {
throw new IOException(e);
}
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/response/FieldStatsInfo.java b/solr/solrj/src/java/org/apache/solr/client/solrj/response/FieldStatsInfo.java
index cd1ade0b3e3..a024cf02748 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/response/FieldStatsInfo.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/response/FieldStatsInfo.java
@@ -82,11 +82,8 @@ public class FieldStatsInfo implements Serializable {
List<FieldStatsInfo> vals = new ArrayList<>();
facets.put(ev.getKey(), vals);
@SuppressWarnings("unchecked")
- NamedList<NamedList<Object>> vnl = (NamedList<NamedList<Object>>) ev.getValue();
- for (int i = 0; i < vnl.size(); i++) {
- String n = vnl.getName(i);
- vals.add(new FieldStatsInfo(vnl.getVal(i), n));
- }
+ var vnl = (NamedList<NamedList<Object>>) ev.getValue();
+ vnl.forEach((name, value) -> vals.add(new FieldStatsInfo(value, name)));
}
} else if ("percentiles".equals(entry.getKey())) {
@SuppressWarnings("unchecked")
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/response/QueryResponse.java b/solr/solrj/src/java/org/apache/solr/client/solrj/response/QueryResponse.java
index 11cea6f4587..c783563634b 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/response/QueryResponse.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/response/QueryResponse.java
@@ -113,58 +113,62 @@ public class QueryResponse extends SolrResponseBase {
super.setResponse(res);
// Look for known things
- for (int i = 0; i < res.size(); i++) {
- String n = res.getName(i);
- if ("responseHeader".equals(n)) {
- _header = (NamedList<Object>) res.getVal(i);
- } else if ("response".equals(n)) {
- _results = (SolrDocumentList) res.getVal(i);
- } else if ("sort_values".equals(n)) {
- _sortvalues = (NamedList<ArrayList>) res.getVal(i);
- } else if ("facet_counts".equals(n)) {
- _facetInfo = (NamedList<Object>) res.getVal(i);
- // extractFacetInfo inspects _results, so defer calling it
- // in case it hasn't been populated yet.
- } else if ("debug".equals(n)) {
- _debugInfo = (NamedList<Object>) res.getVal(i);
- extractDebugInfo(_debugInfo);
- } else if ("grouped".equals(n)) {
- _groupedInfo = (NamedList<Object>) res.getVal(i);
- extractGroupedInfo(_groupedInfo);
- } else if ("expanded".equals(n)) {
- NamedList map = (NamedList) res.getVal(i);
- _expandedResults = map.asMap(1);
- } else if ("highlighting".equals(n)) {
- _highlightingInfo = (NamedList<Object>) res.getVal(i);
- extractHighlightingInfo(_highlightingInfo);
- } else if ("spellcheck".equals(n)) {
- _spellInfo = (NamedList<Object>) res.getVal(i);
- extractSpellCheckInfo(_spellInfo);
- } else if ("clusters".equals(n)) {
- _clusterInfo = (ArrayList<NamedList<Object>>) res.getVal(i);
- extractClusteringInfo(_clusterInfo);
- } else if ("facets".equals(n)) {
- _jsonFacetingInfo = (NamedList<Object>) res.getVal(i);
- // Don't call extractJsonFacetingInfo(_jsonFacetingInfo) here in an effort to do it lazily
- } else if ("suggest".equals(n)) {
- _suggestInfo = (NamedList<NamedList<Object>>) res.getVal(i);
- extractSuggesterInfo(_suggestInfo);
- } else if ("stats".equals(n)) {
- _statsInfo = (NamedList<Object>) res.getVal(i);
- extractStatsInfo(_statsInfo);
- } else if ("terms".equals(n)) {
- _termsInfo = (NamedList<NamedList<Object>>) res.getVal(i);
- extractTermsInfo(_termsInfo);
- } else if ("moreLikeThis".equals(n)) {
- _moreLikeThisInfo = (NamedList<SolrDocumentList>) res.getVal(i);
- } else if ("taskList".equals(n)) {
- _tasksInfo = (NamedList<String>) res.getVal(i);
- } else if ("cancellationResult".equals(n)) {
- _cancellationInfo = (String) res.getVal(i);
- } else if ("taskResult".equals(n)) {
- _taskStatusCheckInfo = (String) res.getVal(i);
- } else if (CursorMarkParams.CURSOR_MARK_NEXT.equals(n)) {
- _cursorMarkNext = (String) res.getVal(i);
+ for (Map.Entry<String, Object> resEntry : res) {
+ String n = resEntry.getKey();
+ Object val = resEntry.getValue();
+
+ switch (n) {
+ case "responseHeader" -> _header = (NamedList<Object>) val;
+ case "response" -> _results = (SolrDocumentList) val;
+ case "sort_values" -> _sortvalues = (NamedList<ArrayList>) val;
+ case "facet_counts" -> _facetInfo = (NamedList<Object>) val;
+
+ // extractFacetInfo inspects _results, so defer calling it
+ // in case it hasn't been populated yet.
+ case "debug" -> {
+ _debugInfo = (NamedList<Object>) val;
+ extractDebugInfo(_debugInfo);
+ }
+ case "grouped" -> {
+ _groupedInfo = (NamedList<Object>) val;
+ extractGroupedInfo(_groupedInfo);
+ }
+ case "expanded" -> {
+ NamedList map = (NamedList) val;
+ _expandedResults = map.asMap(1);
+ }
+ case "highlighting" -> {
+ _highlightingInfo = (NamedList<Object>) val;
+ extractHighlightingInfo(_highlightingInfo);
+ }
+ case "spellcheck" -> {
+ _spellInfo = (NamedList<Object>) val;
+ extractSpellCheckInfo(_spellInfo);
+ }
+ case "clusters" -> {
+ _clusterInfo = (ArrayList<NamedList<Object>>) val;
+ extractClusteringInfo(_clusterInfo);
+ }
+ case "facets" -> _jsonFacetingInfo = (NamedList<Object>) val;
+
+ // Don't call extractJsonFacetingInfo(_jsonFacetingInfo) here in an effort to do it lazily
+ case "suggest" -> {
+ _suggestInfo = (NamedList<NamedList<Object>>) val;
+ extractSuggesterInfo(_suggestInfo);
+ }
+ case "stats" -> {
+ _statsInfo = (NamedList<Object>) val;
+ extractStatsInfo(_statsInfo);
+ }
+ case "terms" -> {
+ _termsInfo = (NamedList<NamedList<Object>>) val;
+ extractTermsInfo(_termsInfo);
+ }
+ case "moreLikeThis" -> _moreLikeThisInfo = (NamedList<SolrDocumentList>) val;
+ case "taskList" -> _tasksInfo = (NamedList<String>) val;
+ case "cancellationResult" -> _cancellationInfo = (String) val;
+ case "taskResult" -> _taskStatusCheckInfo = (String) val;
+ case CursorMarkParams.CURSOR_MARK_NEXT -> _cursorMarkNext = (String) val;
}
}
if (_facetInfo != null) extractFacetInfo(_facetInfo);
@@ -231,11 +235,9 @@ public class QueryResponse extends SolrResponseBase {
private void extractGroupedInfo(NamedList<Object> info) {
if (info != null) {
_groupResponse = new GroupResponse();
- int size = info.size();
- for (int i = 0; i < size; i++) {
- String fieldName = info.getName(i);
- Object fieldGroups = info.getVal(i);
- SimpleOrderedMap<Object> simpleOrderedMap = (SimpleOrderedMap<Object>) fieldGroups;
+ for (Map.Entry<String, Object> infoEntry : info) {
+ String fieldName = infoEntry.getKey();
+ SimpleOrderedMap<Object> simpleOrderedMap = (SimpleOrderedMap<Object>) infoEntry.getValue();
Object oMatches = simpleOrderedMap.get("matches");
Object oNGroups = simpleOrderedMap.get("ngroups");
@@ -336,12 +338,10 @@ public class QueryResponse extends SolrResponseBase {
}
// Parse pivot facets
- NamedList pf = (NamedList) info.get("facet_pivot");
+ var pf = (NamedList<List<NamedList>>) info.get("facet_pivot");
if (pf != null) {
_facetPivot = new NamedList<>();
- for (int i = 0; i < pf.size(); i++) {
- _facetPivot.add(pf.getName(i), readPivots((List<NamedList>) pf.getVal(i)));
- }
+ pf.forEach((name, pivot) -> _facetPivot.add(name, readPivots(pivot)));
}
// Parse interval facets
@@ -415,64 +415,53 @@ public class QueryResponse extends SolrResponseBase {
protected List<PivotField> readPivots(List<NamedList> list) {
ArrayList<PivotField> values = new ArrayList<>(list.size());
for (NamedList nl : list) {
- // NOTE, this is cheating, but we know the order they are written in, so no need to check
- assert "field".equals(nl.getName(0));
- String f = (String) nl.getVal(0);
- assert "value".equals(nl.getName(1));
- Object v = nl.getVal(1);
- assert "count".equals(nl.getName(2));
- int cnt = ((Integer) nl.getVal(2)).intValue();
-
+ // Required fields:
+ String field = null;
+ Object value = null;
+ int count = -1;
+ // Optional fields:
List<PivotField> subPivots = null;
Map<String, FieldStatsInfo> fieldStatsInfos = null;
Map<String, Integer> queryCounts = null;
List<RangeFacet> ranges = null;
- if (4 <= nl.size()) {
- for (int index = 3; index < nl.size(); index++) {
- final String key = nl.getName(index);
- final Object val = nl.getVal(index);
- switch (key) {
- case "pivot":
- {
- assert null != val : "Server sent back 'null' for sub pivots?";
- assert val instanceof List : "Server sent non-List for sub pivots?";
-
- subPivots = readPivots((List<NamedList>) val);
- break;
- }
- case "stats":
- {
- assert null != val : "Server sent back 'null' for stats?";
- assert val instanceof NamedList : "Server sent non-NamedList for stats?";
-
- fieldStatsInfos = extractFieldStatsInfo((NamedList<Object>) val);
- break;
- }
- case "queries":
- {
- // Parse the queries
- queryCounts = new LinkedHashMap<>();
- NamedList<Integer> fq = (NamedList<Integer>) val;
- if (fq != null) {
- for (Map.Entry<String, Integer> entry : fq) {
- queryCounts.put(entry.getKey(), entry.getValue());
- }
- }
- break;
- }
- case "ranges":
- {
- ranges = extractRangeFacets((NamedList<NamedList<Object>>) val);
- break;
+ // Process all entries with a single approach
+ for (Map.Entry<String, ?> entry : (Iterable<Map.Entry<String, ?>>) nl) {
+ final String key = entry.getKey();
+ final Object val = entry.getValue();
+
+ switch (key) {
+ case "field" -> field = (String) val;
+ case "value" -> value = val;
+ case "count" -> count = ((Integer) val).intValue();
+ case "pivot" -> {
+ assert null != val : "Server sent back 'null' for sub pivots?";
+ assert val instanceof List : "Server sent non-List for sub pivots?";
+ subPivots = readPivots((List<NamedList>) val);
+ }
+ case "stats" -> {
+ assert null != val : "Server sent back 'null' for stats?";
+ assert val instanceof NamedList : "Server sent non-NamedList for stats?";
+ fieldStatsInfos = extractFieldStatsInfo((NamedList<Object>) val);
+ }
+ case "queries" -> {
+ // Parse the queries
+ queryCounts = new LinkedHashMap<>();
+ NamedList<Integer> fq = (NamedList<Integer>) val;
+ if (fq != null) {
+ for (Map.Entry<String, Integer> e : fq) {
+ queryCounts.put(e.getKey(), e.getValue());
}
- default:
- throw new RuntimeException("unknown key in pivot: " + key + " [" + val + "]");
+ }
}
+ case "ranges" -> ranges = extractRangeFacets((NamedList<NamedList<Object>>) val);
+ default -> throw new RuntimeException("unknown key in pivot: " + key + " [" + val + "]");
}
}
- values.add(new PivotField(f, v, cnt, subPivots, fieldStatsInfos, queryCounts, ranges));
+ // Create and add the PivotField with all gathered information
+ values.add(
+ new PivotField(field, value, count, subPivots, fieldStatsInfos, queryCounts, ranges));
}
return values;
}
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/response/SpellCheckResponse.java b/solr/solrj/src/java/org/apache/solr/client/solrj/response/SpellCheckResponse.java
index 2269365ceaf..4d3a077da51 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/response/SpellCheckResponse.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/response/SpellCheckResponse.java
@@ -40,13 +40,13 @@ public class SpellCheckResponse {
correctlySpelled = true;
return;
}
- for (int i = 0; i < sugg.size(); i++) {
- String n = sugg.getName(i);
- @SuppressWarnings("unchecked")
- Suggestion s = new Suggestion(n, (NamedList<Object>) sugg.getVal(i));
- suggestionMap.put(n, s);
- suggestions.add(s);
- }
+ sugg.forEach(
+ (n, val) -> {
+ @SuppressWarnings("unchecked")
+ Suggestion s = new Suggestion(n, (NamedList<Object>) val);
+ suggestionMap.put(n, s);
+ suggestions.add(s);
+ });
Boolean correctlySpelled = (Boolean) spellInfo.get("correctlySpelled");
if (correctlySpelled != null) {
@@ -75,11 +75,9 @@ public class SpellCheckResponse {
collation.setCollationQueryString(collationQuery);
collation.setNumberOfHits(hits);
- for (int ii = 0; ii < misspellingsAndCorrections.size(); ii++) {
- String misspelling = misspellingsAndCorrections.getName(ii);
- String correction = misspellingsAndCorrections.getVal(ii);
- collation.addMisspellingsAndCorrection(new Correction(misspelling, correction));
- }
+ misspellingsAndCorrections.forEach(
+ (misspelling, correction) ->
+ collation.addMisspellingsAndCorrection(new Correction(misspelling, correction)));
collations.add(collation);
} else {
throw new AssertionError("Should get Lists of Strings or List of NamedLists here.");
@@ -143,35 +141,32 @@ public class SpellCheckResponse {
public Suggestion(String token, NamedList<Object> suggestion) {
this.token = token;
- for (int i = 0; i < suggestion.size(); i++) {
- String n = suggestion.getName(i);
-
- if ("numFound".equals(n)) {
- numFound = (Integer) suggestion.getVal(i);
- } else if ("startOffset".equals(n)) {
- startOffset = (Integer) suggestion.getVal(i);
- } else if ("endOffset".equals(n)) {
- endOffset = (Integer) suggestion.getVal(i);
- } else if ("origFreq".equals(n)) {
- originalFrequency = (Integer) suggestion.getVal(i);
- } else if ("suggestion".equals(n)) {
- List<?> list = (List<?>) suggestion.getVal(i);
- if (list.size() > 0 && list.get(0) instanceof NamedList) {
- // extended results detected
- @SuppressWarnings("unchecked")
- List<NamedList<?>> extended = (List<NamedList<?>>) list;
- alternativeFrequencies = new ArrayList<>();
- for (NamedList<?> nl : extended) {
- alternatives.add((String) nl.get("word"));
- alternativeFrequencies.add((Integer) nl.get("freq"));
+ suggestion.forEach(
+ (n, val) -> {
+ switch (n) {
+ case "numFound" -> numFound = (Integer) val;
+ case "startOffset" -> startOffset = (Integer) val;
+ case "endOffset" -> endOffset = (Integer) val;
+ case "origFreq" -> originalFrequency = (Integer) val;
+ case "suggestion" -> {
+ List<?> list = (List<?>) val;
+ if (!list.isEmpty() && list.get(0) instanceof NamedList) {
+ // extended results detected
+ @SuppressWarnings("unchecked")
+ List<NamedList<?>> extended = (List<NamedList<?>>) list;
+ alternativeFrequencies = new ArrayList<>();
+ for (NamedList<?> nl : extended) {
+ alternatives.add((String) nl.get("word"));
+ alternativeFrequencies.add((Integer) nl.get("freq"));
+ }
+ } else {
+ @SuppressWarnings("unchecked")
+ List<String> alts = (List<String>) list;
+ alternatives.addAll(alts);
+ }
+ }
}
- } else {
- @SuppressWarnings("unchecked")
- List<String> alts = (List<String>) list;
- alternatives.addAll(alts);
- }
- }
- }
+ });
}
public String getToken() {
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/response/SuggesterResponse.java b/solr/solrj/src/java/org/apache/solr/client/solrj/response/SuggesterResponse.java
index 66891128edc..29a68c1a0d7 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/response/SuggesterResponse.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/response/SuggesterResponse.java
@@ -34,27 +34,25 @@ public class SuggesterResponse {
private final Map<String, List<Suggestion>> suggestionsPerDictionary = new LinkedHashMap<>();
public SuggesterResponse(NamedList<NamedList<Object>> suggestInfo) {
- for (int i = 0; i < suggestInfo.size(); i++) {
- final String outerName = suggestInfo.getName(i);
- final NamedList<Object> outerValue = suggestInfo.getVal(i);
+ suggestInfo.forEach(
+ (outerName, outerValue) -> {
+ SimpleOrderedMap<?> suggestionsNode = (SimpleOrderedMap<?>) outerValue.getVal(0);
+ List<Suggestion> suggestionList = new ArrayList<>();
+ if (suggestionsNode != null) {
+ @SuppressWarnings("unchecked")
+ var suggestionListToParse =
+ (List<SimpleOrderedMap<?>>) suggestionsNode.get(SUGGESTIONS_NODE_NAME);
+ for (SimpleOrderedMap<?> suggestion : suggestionListToParse) {
+ String term = (String) suggestion.get(TERM_NODE_NAME);
+ long weight = (long) suggestion.get(WEIGHT_NODE_NAME);
+ String payload = (String) suggestion.get(PAYLOAD_NODE_NAME);
- SimpleOrderedMap<?> suggestionsNode = (SimpleOrderedMap<?>) outerValue.getVal(0);
- List<Suggestion> suggestionList = new ArrayList<>();
- if (suggestionsNode != null) {
- @SuppressWarnings("unchecked")
- List<SimpleOrderedMap<?>> suggestionListToParse =
- (List<SimpleOrderedMap<?>>) suggestionsNode.get(SUGGESTIONS_NODE_NAME);
- for (SimpleOrderedMap<?> suggestion : suggestionListToParse) {
- String term = (String) suggestion.get(TERM_NODE_NAME);
- long weight = (long) suggestion.get(WEIGHT_NODE_NAME);
- String payload = (String) suggestion.get(PAYLOAD_NODE_NAME);
-
- Suggestion parsedSuggestion = new Suggestion(term, weight, payload);
- suggestionList.add(parsedSuggestion);
- }
- suggestionsPerDictionary.put(outerName, suggestionList);
- }
- }
+ Suggestion parsedSuggestion = new Suggestion(term, weight, payload);
+ suggestionList.add(parsedSuggestion);
+ }
+ suggestionsPerDictionary.put(outerName, suggestionList);
+ }
+ });
}
/**
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/response/TermsResponse.java b/solr/solrj/src/java/org/apache/solr/client/solrj/response/TermsResponse.java
index 9d2c1e544d9..a9a283c896b 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/response/TermsResponse.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/response/TermsResponse.java
@@ -27,27 +27,27 @@ public class TermsResponse {
private Map<String, List<Term>> termMap = new HashMap<>();
public TermsResponse(NamedList<NamedList<Object>> termsInfo) {
- for (int i = 0; i < termsInfo.size(); i++) {
- String fieldName = termsInfo.getName(i);
- List<Term> itemList = new ArrayList<>();
- NamedList<Object> items = termsInfo.getVal(i);
-
- for (int j = 0; j < items.size(); j++) {
- String term = items.getName(j);
- Object val = items.getVal(j);
- Term t;
- if (val instanceof NamedList) {
- @SuppressWarnings("unchecked")
- NamedList<Number> termStats = (NamedList<Number>) val;
- t = new Term(term, termStats.get("df").longValue(), termStats.get("ttf").longValue());
- } else {
- t = new Term(term, ((Number) val).longValue());
- }
- itemList.add(t);
- }
-
- termMap.put(fieldName, itemList);
- }
+ termsInfo.forEach(
+ (fieldName, items) -> {
+ List<Term> itemList = new ArrayList<>();
+
+ items.forEach(
+ (term, val) -> {
+ Term t;
+ if (val instanceof NamedList) {
+ @SuppressWarnings("unchecked")
+ NamedList<Number> termStats = (NamedList<Number>) val;
+ t =
+ new Term(
+ term, termStats.get("df").longValue(), termStats.get("ttf").longValue());
+ } else {
+ t = new Term(term, ((Number) val).longValue());
+ }
+ itemList.add(t);
+ });
+
+ termMap.put(fieldName, itemList);
+ });
}
/**
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/response/schema/SchemaResponse.java b/solr/solrj/src/java/org/apache/solr/client/solrj/response/schema/SchemaResponse.java
index bdd754ef707..7f34859f0a3 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/response/schema/SchemaResponse.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/response/schema/SchemaResponse.java
@@ -38,13 +38,12 @@ public class SchemaResponse extends SolrResponseBase {
private static <T> Map<String, T> extractAttributeMap(NamedList<T> namedList) {
if (namedList == null) return null;
LinkedHashMap<String, T> result = new LinkedHashMap<>();
- for (int i = 0; i < namedList.size(); i++) {
- T val = namedList.getVal(i);
- String name = namedList.getName(i);
- if (!(val instanceof NamedList) && !(val instanceof List)) {
- result.put(name, val);
- }
- }
+ namedList.forEach(
+ (name, val) -> {
+ if (!(val instanceof NamedList) && !(val instanceof List)) {
+ result.put(name, val);
+ }
+ });
return result;
}