This is an automated email from the ASF dual-hosted git repository.

dsmiley pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git

commit 446a9e581cb0cf6220957bbf72df0d71a4d48311
Author: David Smiley <[email protected]>
AuthorDate: Mon Aug 25 13:28:48 2025 -0400

    SolrParams.of() (partial cherry-pick) (#3140)
---
 .../apache/solr/common/params/EmptySolrParams.java | 63 ++++++++++++++++++++++
 .../org/apache/solr/common/params/SolrParams.java  | 10 ++++
 2 files changed, 73 insertions(+)

diff --git 
a/solr/solrj/src/java/org/apache/solr/common/params/EmptySolrParams.java 
b/solr/solrj/src/java/org/apache/solr/common/params/EmptySolrParams.java
new file mode 100644
index 00000000000..4259948bd49
--- /dev/null
+++ b/solr/solrj/src/java/org/apache/solr/common/params/EmptySolrParams.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.common.params;
+
+import java.util.Iterator;
+import java.util.Map.Entry;
+
+/** Empty, immutable, SolrParams. */
+class EmptySolrParams extends SolrParams {
+
+  static final SolrParams INSTANCE = new EmptySolrParams();
+
+  @SuppressWarnings("rawtypes")
+  private static final Iterator EMPTY_ITERATOR =
+      new Iterator() {
+        @Override
+        public boolean hasNext() {
+          return false;
+        }
+
+        @Override
+        public Object next() {
+          throw new IllegalStateException("No elements available in iterator");
+        }
+      };
+
+  @Override
+  public String get(String param) {
+    return null;
+  }
+
+  @Override
+  public String[] getParams(String param) {
+    return null;
+  }
+
+  @SuppressWarnings("unchecked")
+  @Override
+  public Iterator<String> getParameterNamesIterator() {
+    return EMPTY_ITERATOR;
+  }
+
+  @SuppressWarnings("unchecked")
+  @Override
+  public Iterator<Entry<String, String[]>> iterator() {
+    return EMPTY_ITERATOR;
+  }
+}
diff --git a/solr/solrj/src/java/org/apache/solr/common/params/SolrParams.java 
b/solr/solrj/src/java/org/apache/solr/common/params/SolrParams.java
index 81433e35fca..7eaa63373bc 100644
--- a/solr/solrj/src/java/org/apache/solr/common/params/SolrParams.java
+++ b/solr/solrj/src/java/org/apache/solr/common/params/SolrParams.java
@@ -528,4 +528,14 @@ public abstract class SolrParams
     }
     return sb.toString();
   }
+
+  /** An empty, immutable SolrParams. */
+  public static SolrParams of() {
+    return EmptySolrParams.INSTANCE;
+  }
+
+  /** An immutable SolrParams holding one pair (not null). */
+  public static SolrParams of(String k, String v) {
+    return new MapSolrParams(Map.of(k, v));
+  }
 }

Reply via email to