Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could use a <a href="http://guava-libraries.googlecode.com/svn/tags/release03/javadoc/com/google/common/collect/Multimap.html" rel="nofollow">MultiMap</a>, with the key being the status code and the values being the broken links. That pretty much automatically gets you both:</p> <ul> <li>Each individual non-200 status code (as keys)</li> <li>The count of the 'broken' links associated with each code (<code>map.get(code).size()</code>)</li> </ul> <p>Pseudo-ish code:</p> <pre><code>// declare a multimap, somewhere before you need to first access it Multimap&lt;Integer, String&gt; brokenLinkMap = ArrayListMultiMap.create(); // use the map, in your current if block if(statusCode != 200){ System.out.println((String) x.get(i) + statusCode + statusMessage); brokenLinkMap.put(statusCode, url.toExternalForm()); // &lt;-- adding to the map! } // after all links have been processed, you can dump the map contents for(final Integer key : brokenLinkMap.keys()) { System.out.printf("Broken link count for status %s: %s\n", key, brokenLinkMap.get(key).size()); } </code></pre> <p>Alternatively, you could use all standard JDK classes:</p> <pre><code>// declare a map of lists, somewhere before you first need to access it Map&lt;Integer, List&lt;String&gt;&gt; brokenLinkMap = new HashMap&lt;Integer, List&lt;String&gt;&gt;(4); // use the map, in your current if block if(statusCode != 200){ System.out.println((String) x.get(i) + statusCode + statusMessage); if(! brokenLinkMap.containsKey(statusCode)) { List&lt;String&gt; brokenLinkList = new ArrayList&lt;String&gt;(8); brokenLinkMap.put(statusCode, brokenLinkList); } brokenLinkMap.get(statusCode).add(url.toExternalForm()); // &lt;-- adding to the map! } // after all links have been processed, you can dump the map contents for(final Integer key : brokenLinkMap.keys()) { System.out.printf("Broken link count for status %s: %s\n", key, brokenLinkMap.get(key).size()); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload