r110994 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110993‎ | r110994 | r110995 >
Date:00:32, 9 February 2012
Author:oren
Status:deferred
Tags:
Comment:
overriding equals() since hashCode() is overridden
Modified paths:
  • /trunk/lucene-search-3/src/main/java/org/wikimedia/lsearch/beans/ArticleLinks.java (modified) (history)

Diff [purge]

Index: trunk/lucene-search-3/src/main/java/org/wikimedia/lsearch/beans/ArticleLinks.java
@@ -17,25 +17,41 @@
1818 public ArticleLinks redirectsTo;
1919 /** all the pages that get redirected here */
2020 public ArrayList<String> redirected;
21 -
 21+ /**
 22+ * Constructor for a regular article
 23+ * @param links
 24+ */
2225 public ArticleLinks(int links) {
2326 this.links = links;
2427 redirectsTo = null;
2528 }
2629
 30+ /**
 31+ * Constructor for redirect to an article
 32+ * @param links
 33+ * @param redirect
 34+ */
2735 public ArticleLinks(int links, ArticleLinks redirect) {
2836 this.links = links;
2937 this.redirectsTo = redirect;
3038 }
3139
 40+ final static int PRIME = 31;
 41+
3242 @Override
33 - public int hashCode() {
34 - final int PRIME = 31;
35 - int result = 1;
36 - result = PRIME * result + links;
37 - result = PRIME * result + 0;
38 - return result;
 43+ public int hashCode() {
 44+ return PRIME * (PRIME + links);
3945 }
4046
4147
 48+ @Override
 49+ public boolean equals(Object other) {
 50+ if( other instanceof ArticleLinks ) {
 51+ ArticleLinks otherArticleLinks = (ArticleLinks)other;
 52+ return links == otherArticleLinks.links
 53+ && redirectsTo.equals(otherArticleLinks)
 54+ && redirected.equals(otherArticleLinks.redirected);
 55+ }
 56+ return false;
 57+ }
4258 }

Status & tagging log