Author: shalin
Date: Thu May 28 08:48:29 2009
New Revision: 779486

URL: http://svn.apache.org/viewvc?rev=779486&view=rev
Log:
SOLR-458 -- Add equals and hashCode methods to NamedList

Modified:
    lucene/solr/trunk/CHANGES.txt
    lucene/solr/trunk/src/common/org/apache/solr/common/util/NamedList.java

Modified: lucene/solr/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/CHANGES.txt?rev=779486&r1=779485&r2=779486&view=diff
==============================================================================
--- lucene/solr/trunk/CHANGES.txt (original)
+++ lucene/solr/trunk/CHANGES.txt Thu May 28 08:48:29 2009
@@ -487,6 +487,8 @@
 35. SOLR-786: Refactor DisMaxQParser to allow overriding certain features of 
DisMaxQParser
     (Wojciech Biela via shalin)
 
+36. SOLR-458: Add equals and hashCode methods to NamedList (Stefan Rinner, 
shalin) 
+
 Build
 ----------------------
  1. SOLR-776: Added in ability to sign artifacts via Ant for releases 
(gsingers)

Modified: 
lucene/solr/trunk/src/common/org/apache/solr/common/util/NamedList.java
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/src/common/org/apache/solr/common/util/NamedList.java?rev=779486&r1=779485&r2=779486&view=diff
==============================================================================
--- lucene/solr/trunk/src/common/org/apache/solr/common/util/NamedList.java 
(original)
+++ lucene/solr/trunk/src/common/org/apache/solr/common/util/NamedList.java Thu 
May 28 08:48:29 2009
@@ -61,7 +61,7 @@
   /**
    * Creates a NamedList instance containing the "name,value" pairs contained 
in the
    * Entry[].
-   * 
+   *
    * <p>
    * 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
@@ -91,12 +91,12 @@
   public NamedList(List nameValuePairs) {
     nvPairs=nameValuePairs;
   }
-  
+
   /**
    * Method to serialize Map.Entry&lt;String, ?&gt; 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
@@ -106,12 +106,12 @@
   @Deprecated
   private List  nameValueMapToList(Map.Entry<String, ? extends T>[] 
nameValuePairs) {
     List result = new ArrayList();
-    for (Map.Entry<String, ?> ent : nameValuePairs) { 
+    for (Map.Entry<String, ?> ent : nameValuePairs) {
       result.add(ent.getKey());
       result.add(ent.getValue());
     }
     return result;
-  }  
+  }
 
   /** The total number of name/value pairs */
   public int size() {
@@ -136,7 +136,7 @@
   public T getVal(int idx) {
     return (T)nvPairs.get((idx << 1) + 1);
   }
-  
+
   /**
    * Adds a name/value pair to the end of the list.
    */
@@ -197,7 +197,7 @@
   /**
    * Gets the value for the first instance of the specified name
    * found.
-   * 
+   *
    * @return null if not found or if the value stored was null.
    * @see #indexOf
    * @see #get(String,int)
@@ -209,7 +209,7 @@
   /**
    * Gets the value for the first instance of the specified name
    * found starting at the specified index.
-   * 
+   *
    * @return null if not found or if the value stored was null.
    * @see #indexOf
    */
@@ -257,25 +257,25 @@
 
     return sb.toString();
   }
-  
+
   /**
-   * 
+   *
    * Helper class implementing Map.Entry<String, T> to store the key-value
    * relationship in NamedList (the keys of which are String-s) 
-   * 
+   *
    * @param <T>
    */
   public static final class NamedListEntry<T> implements Map.Entry<String, T> {
 
-    public NamedListEntry() { 
-      
+    public NamedListEntry() {
+
     }
-    
+
     public NamedListEntry(String _key, T _value) {
       key = _key;
       value = _value;
     }
-    
+
     public String getKey() {
       return key;
     }
@@ -288,10 +288,10 @@
       T oldValue = value;
       value = _value;
       return oldValue;
-    } 
-    
+    }
+
     private String key;
-    
+
     private T value;
   }
 
@@ -324,18 +324,18 @@
   
//----------------------------------------------------------------------------
   // Iterable interface
   
//----------------------------------------------------------------------------
-  
+
   /**
    * Support the Iterable interface
    */
   public Iterator<Map.Entry<String,T>> iterator() {
-    
+
     final NamedList list = this;
-    
+
     Iterator<Map.Entry<String,T>> iter = new Iterator<Map.Entry<String,T>>() {
-      
+
       int idx = 0;
-      
+
       public boolean hasNext() {
         return idx < list.size();
       }
@@ -351,7 +351,7 @@
           public T getValue() {
             return (T)list.getVal( index );
           }
-          
+
           public String toString()
           {
                  return getKey()+"="+getValue();
@@ -376,4 +376,16 @@
     if(idx != -1) return remove(idx);
     return null;
   }
+
+  @Override
+  public int hashCode() {
+    return nvPairs.hashCode();
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (!(obj instanceof NamedList)) return false;
+    NamedList nl = (NamedList) obj;
+    return this.nvPairs.equals(nl.nvPairs);
+  }
 }


Reply via email to