Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

Fix NUTCH-263.

Andrzej Bialecki4e3fa6fa3380
diff --git a/src/java/org/apache/nutch/crawl/MapWritable.java b/src/java/org/apache/nutch/crawl/MapWritable.java
index 5593a6819..cc2b7bcab 100644
--- a/src/java/org/apache/nutch/crawl/MapWritable.java
+++ b/src/java/org/apache/nutch/crawl/MapWritable.java
@@ -224,16 +224,20 @@ public class MapWritable implements Writable {
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;
}
@@ -452,6 +456,10 @@ public class MapWritable implements Writable {
}
return false;
}
+
+ public int hashCode() {
+ return toString().hashCode();
+ }
}
/** container for Id class tuples */
diff --git a/src/test/org/apache/nutch/crawl/TestMapWritable.java b/src/test/org/apache/nutch/crawl/TestMapWritable.java
index 879766ba9..402b4b4f8 100644
--- a/src/test/org/apache/nutch/crawl/TestMapWritable.java
+++ b/src/test/org/apache/nutch/crawl/TestMapWritable.java
@@ -91,6 +91,16 @@ public class TestMapWritable extends TestCase {
}
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");