Author: ab Date: Mon May 8 14:48:21 2006 New Revision: 405179 URL: http://svn.apache.org/viewcvs?rev=405179&view=rev Log: Fix NUTCH-263.
Modified: lucene/nutch/trunk/src/java/org/apache/nutch/crawl/MapWritable.java lucene/nutch/trunk/src/test/org/apache/nutch/crawl/TestMapWritable.java Modified: lucene/nutch/trunk/src/java/org/apache/nutch/crawl/MapWritable.java URL: http://svn.apache.org/viewcvs/lucene/nutch/trunk/src/java/org/apache/nutch/crawl/MapWritable.java?rev=405179&r1=405178&r2=405179&view=diff ============================================================================== --- lucene/nutch/trunk/src/java/org/apache/nutch/crawl/MapWritable.java (original) +++ lucene/nutch/trunk/src/java/org/apache/nutch/crawl/MapWritable.java Mon May 8 14:48:21 2006 @@ -224,16 +224,20 @@ public boolean equals(Object obj) { if (obj instanceof MapWritable) { MapWritable map = (MapWritable) obj; + if (fSize != map.fSize) return false; + HashSet set1 = new HashSet(); KeyValueEntry e1 = fFirst; - KeyValueEntry e2 = map.fFirst; - while (e1 != null && e2 != null) { - if (!e1.equals(e2)) { - return false; - } + while (e1 != null) { + set1.add(e1); e1 = e1.fNextEntry; + } + HashSet set2 = new HashSet(); + KeyValueEntry e2 = map.fFirst; + while (e2 != null) { + set2.add(e2); e2 = e2.fNextEntry; } - return true; + return set1.equals(set2); } return false; } @@ -451,6 +455,10 @@ return entry.fKey.equals(fKey) && entry.fValue.equals(fValue); } return false; + } + + public int hashCode() { + return toString().hashCode(); } } Modified: lucene/nutch/trunk/src/test/org/apache/nutch/crawl/TestMapWritable.java URL: http://svn.apache.org/viewcvs/lucene/nutch/trunk/src/test/org/apache/nutch/crawl/TestMapWritable.java?rev=405179&r1=405178&r2=405179&view=diff ============================================================================== --- lucene/nutch/trunk/src/test/org/apache/nutch/crawl/TestMapWritable.java (original) +++ lucene/nutch/trunk/src/test/org/apache/nutch/crawl/TestMapWritable.java Mon May 8 14:48:21 2006 @@ -91,6 +91,16 @@ } testWritable(c); } + + public void testEquals() { + MapWritable map1 = new MapWritable(); + MapWritable map2 = new MapWritable(); + map1.put(new UTF8("key1"), new UTF8("val1")); + map1.put(new UTF8("key2"), new UTF8("val2")); + map2.put(new UTF8("key2"), new UTF8("val2")); + map2.put(new UTF8("key1"), new UTF8("val1")); + assertTrue(map1.equals(map2)); + } public void testPerformance() throws Exception { File file = new File(System.getProperty("java.io.tmpdir"), "mapTestFile");