[jsword-devel] [JIRA] Commented: (JS-175) indexOf a valid Key in Josephus returns -1

Martin Denham (JIRA) jira at crosswire.org
Fri Mar 11 01:35:02 MST 2011


    [ http://www.crosswire.org/bugs/browse/JS-175?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14094#comment-14094 ] 

Martin Denham commented on JS-175:
----------------------------------

I just realised how stupid this request is because you can't find the index of tree elements.

What I really would like to do is find the next/prev key e.g. if on section1/chapter1 then pressing Next takes you to section1/chapter2.  Is there anything in JSword that will help me do that for a TreeKey or do I need to manually navigate the tree?

> 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