diff --git a/CHANGES.txt b/CHANGES.txt
index f6588256d6b..5005b831620 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -312,8 +312,10 @@ Other Changes
18. SOLR-1022: Better "ignored" field in example schema.xml (Peter Wolanin via hossman)
-Build
+19. SOLR-967: New type-safe constructor for NamedList (Kay Kay via hossman)
+
+Build
----------------------
1. SOLR-776: Added in ability to sign artifacts via Ant for releases (gsingers)
diff --git a/src/common/org/apache/solr/common/util/NamedList.java b/src/common/org/apache/solr/common/util/NamedList.java
index e1d10254636..cb0e7ea5944 100644
--- a/src/common/org/apache/solr/common/util/NamedList.java
+++ b/src/common/org/apache/solr/common/util/NamedList.java
@@ -57,15 +57,61 @@ public class NamedList implements Cloneable, Serializable, Iterable
+ * Modifying the contents of the Entry[] after calling this constructor may change
+ * the NamedList (in future versions of Solr), but this is not garunteed and should
+ * not be relied upon. To modify the NamedList, refer to {@link #add(String, Object)}
+ * or {@link #remove(String)}.
+ *
+ *
+ * @param nameValuePairs the name value pairs
+ */
+ public NamedList(Map.Entry[] nameValuePairs) {
+ nvPairs = nameValueMapToList(nameValuePairs);
+ }
+
/**
* Creates an instance backed by an explicitly specified list of
* pairwise names/values.
*
- * @param nameValuePairs underlying List which should be used to implement a NamedList; modifying this List will affect the NamedList.
+ *
+ * When using this constructor, runtime typesafety is only garunteed if the all
+ * even numbered elements of the input list are of type "T".
+ *
+ *
+ * @param nameValuePairs underlying List which should be used to implement a NamedList
+ * @deprecated Use {@link #NamedList(java.util.Map.Entry[])} for the NamedList instantiation
*/
+ @Deprecated
public NamedList(List nameValuePairs) {
nvPairs=nameValuePairs;
}
+
+ /**
+ * Method to serialize Map.Entry<String, ?> to a List in which the even
+ * indexed elements (0,2,4. ..etc) are Strings and odd elements (1,3,5,) are of
+ * the type "T".
+ *
+ * @param nameValuePairs
+ * @return Modified List as per the above description
+ * @deprecated This a temporary placeholder method until the guts of the class
+ * are actually replaced by List<String, ?>.
+ * @see https://issues.apache.org/jira/browse/SOLR-912
+ */
+ @Deprecated
+ private List nameValueMapToList(Map.Entry[] nameValuePairs) {
+ List result = new ArrayList();
+ for (Map.Entry ent : nameValuePairs) {
+ result.add(ent.getKey());
+ result.add(ent.getValue());
+ }
+ return result;
+ }
/** The total number of name/value pairs */
public int size() {
@@ -211,6 +257,43 @@ public class NamedList implements Cloneable, Serializable, Iterable to store the key-value
+ * relationship in NamedList (the keys of which are String-s)
+ *
+ * @param
+ */
+ public static final class NamedListEntry implements Map.Entry {
+
+ public NamedListEntry() {
+
+ }
+
+ public NamedListEntry(String _key, T _value) {
+ key = _key;
+ value = _value;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public T getValue() {
+ return value;
+ }
+
+ public T setValue(T _value) {
+ T oldValue = value;
+ value = _value;
+ return oldValue;
+ }
+
+ private String key;
+
+ private T value;
+ }
/**
* Iterates over the Map and sequentially adds it's key/value pairs
diff --git a/src/common/org/apache/solr/common/util/SimpleOrderedMap.java b/src/common/org/apache/solr/common/util/SimpleOrderedMap.java
index 0378753e8cc..e00938b8e86 100755
--- a/src/common/org/apache/solr/common/util/SimpleOrderedMap.java
+++ b/src/common/org/apache/solr/common/util/SimpleOrderedMap.java
@@ -49,9 +49,14 @@ public class SimpleOrderedMap extends NamedList {
*
* @param nameValuePairs underlying List which should be used to implement a SimpleOrderedMap; modifying this List will affect the SimpleOrderedMap.
*/
+ @Deprecated
public SimpleOrderedMap(List nameValuePairs) {
super(nameValuePairs);
}
+
+ public SimpleOrderedMap(Map.Entry[] nameValuePairs) {
+ super(nameValuePairs);
+ }
@Override
public SimpleOrderedMap clone() {
diff --git a/src/java/org/apache/solr/handler/component/DebugComponent.java b/src/java/org/apache/solr/handler/component/DebugComponent.java
index 99ef332e1c2..2d958f18692 100644
--- a/src/java/org/apache/solr/handler/component/DebugComponent.java
+++ b/src/java/org/apache/solr/handler/component/DebugComponent.java
@@ -108,7 +108,7 @@ public class DebugComponent extends SearchComponent
NamedList info = null;
NamedList explain = new SimpleOrderedMap();
- Object[] arr = new Object[rb.resultIds.size() * 2];
+ Map.Entry[] arr = new NamedList.NamedListEntry[rb.resultIds.size()];
for (ShardRequest sreq : rb.finished) {
if ((sreq.purpose & ShardRequest.PURPOSE_GET_DEBUG) == 0) continue;
@@ -123,13 +123,12 @@ public class DebugComponent extends SearchComponent
// TODO: lookup won't work for non-string ids... String vs Float
ShardDoc sdoc = rb.resultIds.get(id);
int idx = sdoc.positionInResponse;
- arr[idx<<1] = id;
- arr[(idx<<1)+1] = sexplain.getVal(i);
+ arr[idx] = new NamedList.NamedListEntry