[EMAIL PROTECTED] wrote:

upayavira 2003/08/10 12:58:09

Modified: src/java/org/apache/cocoon/environment/commandline
LinkSamplingEnvironment.java
Log:
Make the CLI only report unique link count in a page (previously it reported every link, including repeated links, when using link view)
Should mean that link view and linkGathering both report the same number of links in a page

Why not using a Set then? See patch as attachment.


Joerg
Index: LinkSamplingEnvironment.java
===================================================================
RCS file: 
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/environment/commandline/LinkSamplingEnvironment.java,v
retrieving revision 1.3
diff -u -r1.3 LinkSamplingEnvironment.java
--- LinkSamplingEnvironment.java        10 Aug 2003 19:58:09 -0000      1.3
+++ LinkSamplingEnvironment.java        11 Aug 2003 23:12:29 -0000
@@ -50,16 +50,21 @@
  */
 package org.apache.cocoon.environment.commandline;
 
-import org.apache.avalon.framework.logger.Logger;
-
-import org.apache.cocoon.Constants;
-import org.apache.cocoon.environment.ObjectModelHelper;
-
-import java.io.*;
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
 import java.net.MalformedURLException;
-import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashSet;
 import java.util.Map;
+import java.util.Set;
+
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.cocoon.Constants;
+import org.apache.cocoon.environment.ObjectModelHelper;
 
 /**
  * This environment is sample the links of the resource.
@@ -101,7 +106,7 @@
      * Indicates if other links are present.
      */
     public Collection getLinks() throws IOException {
-        ArrayList list = new ArrayList();
+        Set set = new HashSet();
         if (!skip) {
             BufferedReader buffer = null;
             try {
@@ -109,14 +114,9 @@
                         new InputStreamReader(
                                 new ByteArrayInputStream(
                                         ((ByteArrayOutputStream) 
super.outputStream).toByteArray())));
-
-                while (true) {
-                    String line = buffer.readLine();
-                    if (line == null)
-                        break;
-                    if (!list.contains(line)) {
-                        list.add(line);
-                    }
+                String line;
+                while ((line = buffer.readLine()) != null) {
+                    set.add(line);
                 }
             } finally {
                 // explictly close the input
@@ -129,6 +129,6 @@
                 }
             }
         }
-        return list;
+        return set;
     }
 }

Reply via email to