<div dir="ltr">Hello<div><br></div><div>Further to the pullrequest, which is now in test with STEP, I&#39;ve wanted to add a containsAny(key) method.</div><div><br></div><div>Here&#39;s what I&#39;ve got so far, harnessing the new Scope and BookList </div>
<div><br></div><div><br></div><div><div>   private boolean containsAny(Book master, Key k) {</div><div>        if(!(master instanceof AbstractPassageBook)) {</div><div>            return master.contains(k);</div><div>        }</div>
<div><br></div><div>        final Set&lt;BibleBook&gt; books = ((AbstractPassageBook) master).getBibleBooks();</div><div>        final Verse firstVerse = KeyUtil.getVerse(k);</div><div>        if(!books.contains(firstVerse.getBook())) {</div>
<div>            //the books of the module do not contain the book referred to by the verse</div><div>            return false;</div><div>        }</div><div><br></div><div>        //we&#39;re still here, so the books do exist</div>
<div>        //so let&#39;s now examine the keys one by one</div><div>        Iterator&lt;Key&gt; keys = k.iterator();</div><div>        while(keys.hasNext()) {</div><div>            if(master.contains(keys.next())) {</div>
<div>                return true;</div><div>            }</div><div>        }</div><div><br></div><div>        return false;</div><div>    }</div></div><div><br></div><div>This may be worth integrating at the AbstractPassageBook level.</div>
<div><br></div><div>For the ESV and KJV the hit is 1 disk seek as they contain verse 0. </div><div>For the ASV, it is 2 disk seeks as the first master.contains(keys.next()) returns false.</div><div>For WHNU, Genesis would not exist and so it would be purely down to getBibleBooks().contains(firstVerse.getBooK())</div>
<div><br></div><div>My only concern is that for a key that doesn&#39;t exist, then this would be quite expensive for larger keys. </div><div><br></div><div><div>The only odd thing in the API is that getKey (and getValidKey) would end up giving you a key that doesn&#39;t exist in the module.</div>
</div><div><br></div><div>In my use case, I&#39;m suggesting keys to the user based on their input. So this would happen very rarely (i.e. if they type in Ge, then I suggest Gen.). So I do a </div><div><br></div><div>k = book.getKey()</div>
<div>containsAny(book, k)</div><div>if(true) return the key.</div><div><br></div><div>Perhaps we should modify getKey()&#39;s behaviour...</div><div><br></div><div>Chris</div><div><br></div><div><br></div><div><br></div></div>