mirror of https://github.com/apache/lucene.git
fix bug in CategoryPath.compareTo
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1434634 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e40f5acf04
commit
076b6de0a3
|
@ -92,8 +92,8 @@ public class CategoryPath implements Comparable<CategoryPath> {
|
|||
*/
|
||||
@Override
|
||||
public int compareTo(CategoryPath other) {
|
||||
int length = this.length < other.length ? this.length : other.length;
|
||||
for (int i = 0, j = 0; i < length; i++, j++) {
|
||||
final int len = length < other.length ? length : other.length;
|
||||
for (int i = 0, j = 0; i < len; i++, j++) {
|
||||
int cmp = components[i].compareTo(other.components[j]);
|
||||
if (cmp < 0) return -1; // this is 'before'
|
||||
if (cmp > 0) return 1; // this is 'after'
|
||||
|
|
|
@ -163,16 +163,22 @@ public class TestCategoryPath extends LuceneTestCase {
|
|||
CategoryPath p = new CategoryPath("a/b/c/d", '/');
|
||||
CategoryPath pother = new CategoryPath("a/b/c/d", '/');
|
||||
assertEquals(0, pother.compareTo(p));
|
||||
assertEquals(0, p.compareTo(pother));
|
||||
pother = new CategoryPath("", '/');
|
||||
assertTrue(pother.compareTo(p) < 0);
|
||||
assertTrue(p.compareTo(pother) > 0);
|
||||
pother = new CategoryPath("a/b_/c/d", '/');
|
||||
assertTrue(pother.compareTo(p) > 0);
|
||||
assertTrue(p.compareTo(pother) < 0);
|
||||
pother = new CategoryPath("a/b/c", '/');
|
||||
assertTrue(pother.compareTo(p) < 0);
|
||||
assertTrue(p.compareTo(pother) > 0);
|
||||
pother = new CategoryPath("a/b/c/e", '/');
|
||||
assertTrue(pother.compareTo(p) > 0);
|
||||
assertTrue(p.compareTo(pother) < 0);
|
||||
pother = new CategoryPath("a/b/c//e", '/');
|
||||
assertTrue(pother.compareTo(p) < 0);
|
||||
assertTrue(p.compareTo(pother) > 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue