[jsword-devel] [JIRA] Commented: (JS-175) indexOf a valid Key in Josephus returns -1
Martin Denham (JIRA)
jira at crosswire.org
Sat Mar 12 08:54:24 MST 2011
[ http://www.crosswire.org/bugs/browse/JS-175?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14114#comment-14114 ]
Martin Denham commented on JS-175:
----------------------------------
I like your idea of flattening out the tree and using that for indexes. My current code tries to traverse the tree at each call to prev/next and it is a bit messy. However, I was experimenting a little with your method and suddenly realised that getGlobalKeyList is doing almost that except that it includes non-leaf nodes. I was confused because when I call getGlobalKeyList.getChildCount I was getting a very small number:
genBook.getGlobalKeyList returns all the keys, flattened and in the correct order. getCardinality reflects all keys
genBook.getGlobalKeyList.getChildCount/get(child)/indexOf/contains only use one level of keys
You can see that in:
Book book = getBook("Pilgrim");
Key globalKeyList = book.getGlobalKeyList();
assertEquals("Incorrect number of keys in master list", 29, globalKeyList.getCardinality());
assertEquals("Incorrect number of top level keys", 6, globalKeyList.getChildCount());
I thought I had to navigate a Gen Book as a tree (like BD or Xiphos) but I think I will try showing all keys returned by getGlobalKeyList in one long list. If a Key has no content then it seems to use the Key Name as content but almost all keys I have tested have content.
> indexOf a valid Key in Josephus returns -1
> ------------------------------------------
>
> Key: JS-175
> URL: http://www.crosswire.org/bugs/browse/JS-175
> Project: JSword
> Issue Type: Bug
> Components: o.c.jsword.passage
> Affects Versions: 1.6.1
> Environment: All
> Reporter: Martin Denham
> Assignee: DM Smith
>
> Here is my test:
> Book book = getBook("Josephus");
> assertNotNull("Josephus not available", book);
>
> // find a key and print out it's name - this works
> final String SECTION_2 = "Section 2";
> Key key = book.getKey(SECTION_2);
> assertEquals(SECTION_2, key.getName());
>
> // but we can't get it's index - this returns -1
> int keyPos = book.getGlobalKeyList().indexOf(key);
> assertFalse("Could not get index of a valid key", -1==keyPos);
> When dealing with a book having TreeKeys the top level Key returned by book.getGlobalKeyList is not a TreeKey but a KeyList which therefore does not automatically search it's children. So I wonder if SwordGenBook.global could be a TreeKey rather than a ReadOnlyKeyList.
> Maybe the way it works is the way it should work but I am not sure. Now I realise what is happening I could just call indexOf on each child of the globalKeyList but I think it would be more elegant if globalKeyList.indexOf returned a key from lower down in the tree.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the jsword-devel
mailing list