Index: trunk/lucene-search-3/src/main/java/org/wikimedia/lsearch/beans/ArticleLinks.java |
— | — | @@ -17,25 +17,41 @@ |
18 | 18 | public ArticleLinks redirectsTo; |
19 | 19 | /** all the pages that get redirected here */ |
20 | 20 | public ArrayList<String> redirected; |
21 | | - |
| 21 | + /** |
| 22 | + * Constructor for a regular article |
| 23 | + * @param links |
| 24 | + */ |
22 | 25 | public ArticleLinks(int links) { |
23 | 26 | this.links = links; |
24 | 27 | redirectsTo = null; |
25 | 28 | } |
26 | 29 | |
| 30 | + /** |
| 31 | + * Constructor for redirect to an article |
| 32 | + * @param links |
| 33 | + * @param redirect |
| 34 | + */ |
27 | 35 | public ArticleLinks(int links, ArticleLinks redirect) { |
28 | 36 | this.links = links; |
29 | 37 | this.redirectsTo = redirect; |
30 | 38 | } |
31 | 39 | |
| 40 | + final static int PRIME = 31; |
| 41 | + |
32 | 42 | @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); |
39 | 45 | } |
40 | 46 | |
41 | 47 | |
| 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 | + } |
42 | 58 | } |