-LUCENE-828: Term equals(Object) fix

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@519006 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Otis Gospodnetic 2007-03-16 15:21:05 +00:00
parent 78a6922c43
commit 939ed115c4
3 changed files with 26 additions and 0 deletions

View File

@ -77,6 +77,9 @@ Bug fixes
10. LUCENE-829: close readers in contrib/benchmark. (Karl Wettin, Doron Cohen)
11. LUCENE-828: Minor fix for Term's equal().
(Paul Cowan via Otis Gospodnetic)
New features
1. LUCENE-759: Added two n-gram-producing TokenFilters.

View File

@ -63,8 +63,12 @@ public final class Term implements Comparable, java.io.Serializable {
/** Compares two terms, returning true iff they have the same
field and text. */
public final boolean equals(Object o) {
if (o == this)
return true;
if (o == null)
return false;
if (!(o instanceof Term))
return false;
Term other = (Term)o;
return field == other.field && text.equals(other.text);
}

View File

@ -0,0 +1,19 @@
package org.apache.lucene.index;
import junit.framework.TestCase;
public class TestTerm extends TestCase {
public void testEquals() {
final Term base = new Term("same", "same");
final Term same = new Term("same", "same");
final Term differentField = new Term("different", "same");
final Term differentText = new Term("same", "different");
final String differentType = "AString";
assertEquals(base, base);
assertEquals(base, same);
assertFalse(base.equals(differentField));
assertFalse(base.equals(differentText));
assertFalse(base.equals(differentType));
}
}