<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Mar 16, 2011, at 5:47 PM, Martin Denham wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Hi,<div><br></div><div>I am a bit confused by GenBookBackend.contains(key). Here is some test code, btw HodgeSysTheo is from Xiphos repo:</div><div><br></div><div><div><span class="Apple-tab-span" style="white-space:pre"> </span>Book book = getBook("HodgeSysTheo");</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>Key volume1Key = book.getKey("Volume I"); // that is a capital I (<i>eye</i>) not a number one on the end</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>assertNotNull("Vol 1 not found", volume1Key);</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>if (!book.contains(volume1Key)) {</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>System.out.println("Book does not contain a valid key");</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div></div></blockquote><div><br></div>The TreeNode contains no data. For that reason it returns false.</div><div><br></div><div>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.</div><div><br></div><div>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).</div><div><br><blockquote type="cite"><div><br></div><div>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.</div>
<div><br></div><div>The bit of code that implements contains() is</div><div><br></div><div><div> TreeNode node = find(key); // this returns true</div></div></blockquote>It should have just return here with:</div><div>return node != null;</div><div><br><blockquote type="cite"><div><div> // Is there an entry?</div><div> if (node == null) {</div>
<div> return false;</div><div> }</div></div></blockquote><div><br></div><br><blockquote type="cite"><div><div><br></div><div> // Is it non-empty?</div><div> byte[] userData = node.getUserData();</div><div><br></div><div> // Some entries may be empty.</div>
<div> return userData.length == 8; // this is false for the test key being used i.e. 'Volume I'</div></div><div><br></div><div>Either way I can make And Bible work but I just want to check the above is correct because it surprised me a bit.</div>
<div><br></div><div>Thanks</div><div>Martin</div>
_______________________________________________<br>jsword-devel mailing list<br><a href="mailto:jsword-devel@crosswire.org">jsword-devel@crosswire.org</a><br>http://www.crosswire.org/mailman/listinfo/jsword-devel<br></blockquote></div><br></body></html>