[jsword-devel] Confused that GenBookBackend denies containing empty keys

DM Smith dmsmith at crosswire.org
Wed Mar 16 15:33:04 MST 2011


On Mar 16, 2011, at 5:47 PM, Martin Denham wrote:

> Hi,
> 
> I am a bit confused by GenBookBackend.contains(key).  Here is some test code, btw HodgeSysTheo is from Xiphos repo:
> 
> 		Book book = getBook("HodgeSysTheo");
> 		Key volume1Key = book.getKey("Volume I");  // that is a capital I (eye) not a number one on the end
> 		assertNotNull("Vol 1 not found", volume1Key);
> 		if (!book.contains(volume1Key)) {
> 			System.out.println("Book does not contain a valid key");
> 		}

The TreeNode contains no data. For that reason it returns false.

But, I don't think that is right. If we want that behavior then we should have a different method for that (or a second argument to this one, e.g. boolean withContent DEFAULT false.

I'll have to look to see if we have any code that depends upon that behavior. (e.g. building a key list of that with content).

> 
> So you can see that I am getting a key from a GenBook but when I check to see if the same GenBook contains the key then I get false if the key does not contain anything.  Maybe this is correct but I thought I would ask just in case it is a bug.
> 
> The bit of code that implements contains() is
> 
>             TreeNode node = find(key);   // this returns true
It should have just return here with:
return node != null;

>             // Is there an entry?
>             if (node == null) {
>                 return false;
>             }


> 
>             // Is it non-empty?
>             byte[] userData = node.getUserData();
> 
>             // Some entries may be empty.
>             return userData.length == 8;   // this is false for the test key being used i.e. 'Volume I'
> 
> Either way I can make And Bible work but I just want to check the above is correct because it surprised me a bit.
> 
> Thanks
> Martin
> _______________________________________________
> jsword-devel mailing list
> jsword-devel at crosswire.org
> http://www.crosswire.org/mailman/listinfo/jsword-devel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.crosswire.org/pipermail/jsword-devel/attachments/20110316/3802d57d/attachment.html>


More information about the jsword-devel mailing list