You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nutch.apache.org by ma...@apache.org on 2015/10/30 22:55:49 UTC

svn commit: r1711561 - in /nutch/trunk: CHANGES.txt src/java/org/apache/nutch/parse/Outlink.java src/plugin/index-links/src/test/org/apache/nutch/parse/ src/plugin/index-links/src/test/org/apache/nutch/parse/TestOutlinks.java

Author: mattmann
Date: Fri Oct 30 21:55:49 2015
New Revision: 1711561

URL: http://svn.apache.org/viewvc?rev=1711561&view=rev
Log:
Fix for NUTCH-2146 hashCode on the Outlink class contributed by Jorge Luis Betancourt <be...@gmail.com> this closes #79.

Added:
    nutch/trunk/src/plugin/index-links/src/test/org/apache/nutch/parse/
    nutch/trunk/src/plugin/index-links/src/test/org/apache/nutch/parse/TestOutlinks.java
Modified:
    nutch/trunk/CHANGES.txt
    nutch/trunk/src/java/org/apache/nutch/parse/Outlink.java

Modified: nutch/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/nutch/trunk/CHANGES.txt?rev=1711561&r1=1711560&r2=1711561&view=diff
==============================================================================
--- nutch/trunk/CHANGES.txt (original)
+++ nutch/trunk/CHANGES.txt Fri Oct 30 21:55:49 2015
@@ -3,6 +3,8 @@ Nutch Change Log
 Nutch 1.11 Release 25/10/2015 (dd/mm/yyyy)
 Release Report: http://s.apache.org/nutch11
 
+* NUTCH-2146 hashCode on the Outlink class (jorgelbg via mattmann)
+
 * NUTCH-2155 Create a "crawl completeness" utility (Michael Joyce via mattmann)
 
 * NUTCH-1988 Make nested output directory dump optional... again (Michael Joyce via lewismc)

Modified: nutch/trunk/src/java/org/apache/nutch/parse/Outlink.java
URL: http://svn.apache.org/viewvc/nutch/trunk/src/java/org/apache/nutch/parse/Outlink.java?rev=1711561&r1=1711560&r2=1711561&view=diff
==============================================================================
--- nutch/trunk/src/java/org/apache/nutch/parse/Outlink.java (original)
+++ nutch/trunk/src/java/org/apache/nutch/parse/Outlink.java Fri Oct 30 21:55:49 2015
@@ -128,4 +128,8 @@ public class Outlink implements Writable
     return repr.toString();
   }
 
+  @Override
+  public int hashCode() {
+    return toUrl.hashCode() ^ anchor.hashCode();
+  }
 }

Added: nutch/trunk/src/plugin/index-links/src/test/org/apache/nutch/parse/TestOutlinks.java
URL: http://svn.apache.org/viewvc/nutch/trunk/src/plugin/index-links/src/test/org/apache/nutch/parse/TestOutlinks.java?rev=1711561&view=auto
==============================================================================
--- nutch/trunk/src/plugin/index-links/src/test/org/apache/nutch/parse/TestOutlinks.java (added)
+++ nutch/trunk/src/plugin/index-links/src/test/org/apache/nutch/parse/TestOutlinks.java Fri Oct 30 21:55:49 2015
@@ -0,0 +1,54 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nutch.parse;
+
+import org.junit.Test;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.junit.Assert.*;
+
+public class TestOutlinks {
+
+  @Test
+  public void testAddSameObject() throws Exception {
+    Set<Outlink> set = new HashSet<>();
+
+    Outlink o = new Outlink("http://www.example.com", "Example");
+    set.add(o);
+    set.add(o);
+
+    assertEquals("Adding the same Outlink twice", 1, set.size());
+  }
+
+  @Test
+  public void testAddOtherObjectWithSameData() throws Exception {
+    Set<Outlink> set = new HashSet<>();
+
+    Outlink o = new Outlink("http://www.example.com", "Example");
+    Outlink o1 = new Outlink("http://www.example.com", "Example");
+
+    assertTrue("The two Outlink objects are the same", o.equals(o1));
+
+    set.add(o);
+    set.add(o1);
+
+    assertEquals("The set should contain only 1 Outlink", 1, set.size());
+  }
+}
\ No newline at end of file