[jsword-devel] Limiting the number of verses in a passage

Stephen Denne spdlist at ihug.co.nz
Mon Jul 6 02:15:05 MST 2009


> > From: Brian Fernandes [mailto:infernalproteus at gmail.com] 
> 
> > Given a passage object, say a RocketPassage - what is the 
> best way to 
> > limit the number of verses in it?
> > 
> > The verses in the passage may not be continuous. So something like 
> > "gen.1.1-3,lev.2.1-5,exo.3.1-ff" as a single passage object. 
> > If I want 
> > to restrict the lookup/retrieval to only the first 15 
> verses, what is 
> > the best way to achieve this with JSword?
> > 
> > Thanks!
> > Brian.
> 
> 
> There's an example or two of Passage.trimVerses() in 
> org.crosswire.jsword.examples.APIExamples that may do what you want.

Although if you wish to preserve the original order, you might be better using

StringUtil.split(refs, AbstractPassage.REF_ALLOWED_DELIMS);
VerseRange basis = VerseRangeFactory.fromString(parts[0].trim());

Using basis, and looping through:

VerseRange next = VerseRangeFactory.fromString(parts[i].trim(), basis);
basis = next;

Making use of the VerseRange.getCardinality() call to keep track of how many verses you've got so far, calling iterator() on each
range, stopping when you've looked up/retrieved the desired number of verses.

Regards,
Stephen Denne.




More information about the jsword-devel mailing list