Details
-
Type: Bug
-
Status: Open (View Workflow)
-
Priority: Minor
-
Resolution: Unresolved
-
Affects Version/s: 1.6.1
-
Fix Version/s: None
-
Component/s: o.c.jsword.passage
-
Labels:None
Description
Lists of RocketPassages now appear to sort in inverse biblical order whereas they used to sort in Biblical order when using Collections.sort(rocketPassageList).
And Bible bookmarks seem to be deserialized to RocketPassages and when sorted using the latest JSword bookmarks in Rev appear at the top of the list and Genesis at the bottom, but with pre-av11n code bookmarks in Genesis would appear at the top.
I have dug in a little.
This is the old code in AbstractPassage.compareTo:
Verse thatfirst = thatref.getVerseAt(0);
Verse thisfirst = getVerseAt(0);
return thisfirst.compareTo(thatfirst);
Verse.compareTo:
int thatStart = that.getOrdinal();
int thisStart = this.getOrdinal();
if (thatStart > thisStart)
if (thatStart < thisStart)
{ return 1; }
And here is the new code:
Verse thatfirst = thatref.getVerseAt(0);
Verse thisfirst = getVerseAt(0);
return getVersification().distance(thisfirst, thatfirst);
Versification:
public int distance(Verse start, Verse end) {
return end.getOrdinal() - start.getOrdinal();
To see the problem imagine in the old code:
if (thatVerseinRev > thisVerseInGen) // obviously true
return -1 // so in old code the compareTo result is -ve
But in the new code:
distance(thisVerseInGen, thatVerseInRev)
thatVerseInRev.ordinal - thisVerseInGen.ordinal // result is +ve
Is it okay simply to reverse the order of that and this in AbstractPassage and make it:
return thatfirst.compareTo(thisfirst);
Will this problem be seen in any other places?
I created a couple of junits in VersificationParentTst and they seem to point to the problem only affecting lists of RocketPassage which initially surprised me until I noticed that Verse has it's own compareTo method.
// This test works correctly
public void testListSort() {
if (v11n.containsBook(BibleBook.GEN) && v11n.containsBook(BibleBook.REV))
}
// This test fails because Rev is first and Gen last
public void testListSort2() {
try {
if (v11n.containsBook(BibleBook.GEN) && v11n.containsBook(BibleBook.REV))
} catch (Exception e)
{ fail("Exception in testListSort2"); }}
Regards
Martin