[jsword-devel] Java conundrum

DM Smith dmsmith at crosswire.org
Thu May 9 06:59:59 MST 2013


That'd be fine.

I've been mulling over whether it is a sufficient solution. There are other "Key"s that hold verses (i.e. Passage and it ilk). A VerseRange can certainly contain all the Verses in a Passage. For example, a VerseRange of Genesis 1 contains a Passage of Gen 1:1-2 and Gen 1:10. I don't think this is at all common in real code, but it is possible.

But don't let that slow progress.

In Him,
	DM

On May 9, 2013, at 9:47 AM, Martin Denham <mjdenham at gmail.com> wrote:

> I can check in a fix if you like.
> 
> Martin
> 
> 
> On 8 May 2013 15:58, DM Smith <dmsmith at crosswire.org> wrote:
> That is the correct solution.
> 
> On May 7, 2013, at 11:14 AM, Martin Denham <mjdenham at gmail.com> wrote:
> 
>> Hi DM,
>> 
>> There are specific contains() implementations in VerseRange.  
>>     public boolean contains(Verse that) {
>>         return v11n.distance(start, that) >= 0 && v11n.distance(that, end) >= 0;
>>     }
>> 
>>     public boolean contains(Key key) {
>>         if (key instanceof VerseRange) {
>>             return contains((VerseRange) key);
>>         }
>>         return false;
>>     }
>> 
>> 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:
>>     public boolean contains(Key key) {
>>         if (key instanceof VerseRange) {
>>             return contains((VerseRange) key);
>>         }
>>         if (key instanceof Verse) {
>>             return contains((Verse) key);
>>         }
>>         return false;
>>     }
>> 
>> Martin
>> 
>> 
>> On 7 May 2013 14:12, DM Smith <dmsmith at crosswire.org> wrote:
>> Sorry for not replying earlier. Have been on holiday.
>> 
>> This conundrum should bee seen as a bug. Both should return the same value.
>> 
>> 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.
>> 
>> 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.
>> 
>> 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).
>> 
>> I'll see what I can find out.
>> 
>> -- DM
>> 
>> On May 4, 2013, at 5:34 AM, Martin Denham <mjdenham at gmail.com> wrote:
>> 
>> > Here is an interesting problem (based on VerseRangeTest.java):
>> >
>> >     private VerseRange gen_all = ...;
>> >
>> >     public void testKeyContainsVerse() {
>> >         // this passes
>> >         assertTrue(gen_all.contains(gen11));
>> >
>> >         // this fails
>> >         Key gen_allKey = gen_all;
>> >         assertTrue(gen_allKey.contains(gen11));
>> >     }
>> >
>> > 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():
>> >     boolean contains(Key key);
>> >
>> > 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.
>> >
>> > Is this a bug?
>> >
>> > Martin
>> >
>> >
>> >
>> >
>> > _______________________________________________
>> > jsword-devel mailing list
>> > jsword-devel at crosswire.org
>> > http://www.crosswire.org/mailman/listinfo/jsword-devel
>> 
>> 
>> _______________________________________________
>> jsword-devel mailing list
>> jsword-devel at crosswire.org
>> http://www.crosswire.org/mailman/listinfo/jsword-devel
>> 
>> _______________________________________________
>> jsword-devel mailing list
>> jsword-devel at crosswire.org
>> http://www.crosswire.org/mailman/listinfo/jsword-devel
> 
> 
> _______________________________________________
> jsword-devel mailing list
> jsword-devel at crosswire.org
> http://www.crosswire.org/mailman/listinfo/jsword-devel
> 
> 
> _______________________________________________
> 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/20130509/9f8245c0/attachment-0001.html>


More information about the jsword-devel mailing list