Why not?

I'm attaching a patch which does that. Nutch's API looks very messy, very un-Java. Why not making Hits work as a list so that it can be iterated with the new Java "for" and processed using the normal Collections APIs (for getting subsets, for instance, or for dumping the hits into another collection).
Index: src/java/org/apache/nutch/searcher/Hits.java
===================================================================
--- src/java/org/apache/nutch/searcher/Hits.java	(revisión: 543252)
+++ src/java/org/apache/nutch/searcher/Hits.java	(copia de trabajo)
@@ -20,13 +20,14 @@
 import java.io.DataInput;
 import java.io.DataOutput;
 import java.io.IOException;
+import java.util.AbstractList;
 
 import org.apache.hadoop.io.Writable;
 import org.apache.hadoop.io.WritableComparable;
 import org.apache.hadoop.io.Text;
 
 /** A set of hits matching a query. */
-public final class Hits implements Writable {
+public final class Hits extends AbstractList<Hit> implements Writable  {
 
   private long total;
   private boolean totalIsExact = true;
@@ -83,7 +84,7 @@
   public void readFields(DataInput in) throws IOException {
     total = in.readLong();                        // read total hits
     top = new Hit[in.readInt()];                  // read hits returned
-    Class sortClass = null;
+    Class<?> sortClass = null;
     if (top.length > 0) {                         // read sort value class
       try {
         sortClass = Class.forName(Text.readString(in));
@@ -109,4 +110,23 @@
     }
   }
 
+  @Override
+  public Hit get(int index) {
+    return getHit(index);
+  }
+
+  @Override
+  public int size() {
+    return getLength();
+  }
+  
+  @Override
+  public boolean equals(Object o) {
+    if(!super.equals(o))
+      return false;
+    if(!(o instanceof Hits))
+      return false;
+    Hits h = (Hits)o;
+    return h.totalIsExact == totalIsExact && h.total == total;
+  }
 }
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Nutch-developers mailing list
Nutch-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nutch-developers

Reply via email to