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:
Shai Erera 2013-01-17 12:09:11 +00:00
parent e40f5acf04
commit 076b6de0a3
2 changed files with 8 additions and 2 deletions

View File

@ -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'

View File

@ -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);
}
}