mirror of https://github.com/apache/lucene.git
-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:
parent
78a6922c43
commit
939ed115c4
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue