<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">That is the correct solution.<div><br><div><div>On May 7, 2013, at 11:14 AM, Martin Denham <<a href="mailto:mjdenham@gmail.com">mjdenham@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">Hi DM,<div><br></div><div>There are specific contains() implementations in VerseRange. </div><div><div> public boolean contains(Verse that) {</div><div> return v11n.distance(start, that) >= 0 && v11n.distance(that, end) >= 0;</div>
<div> }</div></div><div><br></div><div><div> public boolean contains(Key key) {</div><div> if (key instanceof VerseRange) {</div><div> return contains((VerseRange) key);</div><div> }</div><div>
return false;</div><div> }</div></div><div><br></div><div style="">The second is being called but returns false because key is not a VerseRange. If the implementation of VerseRange.contains(Key) is the problem then another clause added at the end of the method might be one way to fix it, like:</div>
<div style=""><div> public boolean contains(Key key) {</div><div> if (key instanceof VerseRange) {</div><div> return contains((VerseRange) key);</div><div> }</div><div> if (key instanceof Verse) {</div>
<div> return contains((Verse) key);</div><div> }</div><div><div> return false;</div><div> }</div></div><div><br></div></div><div style="">Martin</div></div><div class="gmail_extra"><br>
<br><div class="gmail_quote">On 7 May 2013 14:12, DM Smith <span dir="ltr"><<a href="mailto:dmsmith@crosswire.org" target="_blank">dmsmith@crosswire.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Sorry for not replying earlier. Have been on holiday.<br>
<br>
This conundrum should bee seen as a bug. Both should return the same value.<br>
<br>
I have an idea of what is happening (I have a masters degree in computer science for compiler construction), but until I trace it I won't be sure. I think that it is compile time determination of what is being called.<br>
<br>
In the gen_all case, it is known that it is a VerseRange and that VerseRange has a more specific contains(Verse). So that is called.<br>
<br>
In the gen_allKey case, it is no longer a VerseRange but a Key (which should not know anything about a Verse, since it is supposed to work for all kinds of Keys). So it cannot call contains(Verse) but only contains(Key).<br>
<br>
I'll see what I can find out.<br>
<br>
-- DM<br>
<div><div class="h5"><br>
On May 4, 2013, at 5:34 AM, Martin Denham <<a href="mailto:mjdenham@gmail.com">mjdenham@gmail.com</a>> wrote:<br>
<br>
> Here is an interesting problem (based on VerseRangeTest.java):<br>
><br>
> private VerseRange gen_all = ...;<br>
><br>
> public void testKeyContainsVerse() {<br>
> // this passes<br>
> assertTrue(gen_all.contains(gen11));<br>
><br>
> // this fails<br>
> Key gen_allKey = gen_all;<br>
> assertTrue(gen_allKey.contains(gen11));<br>
> }<br>
><br>
> This caught me out for a while. I think the second assert should pass but Key is an interface with a single non-overloaded contains():<br>
> boolean contains(Key key);<br>
><br>
> Whereas VerseRange contains overloaded methods like contains(Verse) that are not called because the Key interface is being used. At least that is what I think is happening.<br>
><br>
> Is this a bug?<br>
><br>
> Martin<br>
><br>
><br>
><br>
><br>
</div></div>> _______________________________________________<br>
> jsword-devel mailing list<br>
> <a href="mailto:jsword-devel@crosswire.org">jsword-devel@crosswire.org</a><br>
> <a href="http://www.crosswire.org/mailman/listinfo/jsword-devel" target="_blank">http://www.crosswire.org/mailman/listinfo/jsword-devel</a><br>
<br>
<br>
_______________________________________________<br>
jsword-devel mailing list<br>
<a href="mailto:jsword-devel@crosswire.org">jsword-devel@crosswire.org</a><br>
<a href="http://www.crosswire.org/mailman/listinfo/jsword-devel" target="_blank">http://www.crosswire.org/mailman/listinfo/jsword-devel</a><br>
</blockquote></div><br></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></div></body></html>