private void populateVerseNotesList() { mVerseNotesList.clear(); int startVerseNo = currentVerseRange.getStart().getVerse(); int endVerseNo = currentVerseRange.getEnd().getVerse(); if (mChapterNotesList!=null) { for (Note note : mChapterNotesList) { final int noteVerseNo = note.getVerseNo(); if (noteVerseNo >= startVerseNo && noteVerseNo <=endVerseNo) { mVerseNotesList.add(note); } } } }
public ConvertibleVerseRange(VerseRange verseRange) { this.originalVerseRange = verseRange; this.startVerse = new ConvertibleVerse(verseRange.getStart()); this.endVerse = new ConvertibleVerse(verseRange.getEnd()); }
/** * Is the given range within our range. For example if this = "Gen 1:1-31" * then: <tt>this.contains(Verse("Gen 1:3-10")) == true</tt> * <tt>this.contains(Verse("Gen 2:1-1")) == false</tt> * * @param that * The Verse to compare to * @return true if we contain it. */ public boolean contains(VerseRange that) { return v11n.distance(start, that.getStart()) >= 0 && v11n.distance(that.getEnd(), end) >= 0; }
public VerseRange next() { if (next == null) { next = real.next(); } if (next == null) { throw new NoSuchElementException(); } // So we know what is broadly next, however the range might need // splitting according to restrict if (restrict.isSameScope(next.getVersification(), next.getStart(), next.getEnd())) { return replyNext(); } return splitNext(); }
@Override public Verse createStartVerse(Versification v11n, VerseRange verseRangeBasis, String[] parts) throws NoSuchVerseException { if (verseRangeBasis == null) { // TRANSLATOR: The user supplied a verse reference but did not give the book or chapter of the Bible. throw new NoSuchVerseException(JSMsg.gettext("Book and chapter are missing")); } BibleBook book = verseRangeBasis.getEnd().getBook(); int chapter = verseRangeBasis.getEnd().getChapter(); int verse = getVerse(v11n, book, chapter, parts[0]); return new Verse(v11n, book, chapter, verse, getSubIdentifier(parts)); }
/** * Merge 2 VerseRanges together. The resulting range will encompass * Everything in-between the extremities of the 2 ranges. * * @param a * The first verse range to be merged * @param b * The second verse range to be merged */ public VerseRange(VerseRange a, VerseRange b) { v11n = a.v11n; shaper = new NumberShaper(); start = v11n.min(a.getStart(), b.getStart()); end = v11n.max(a.getEnd(), b.getEnd()); verseCount = calcVerseCount(); }
public VerseRange convert(VerseRange verseRange, Versification toVersification) { Verse startVerse = verseRange.getStart(); Verse endVerse = verseRange.getEnd(); Verse convertedStartVerse = convert(startVerse, toVersification); Verse convertedEndVerse = convert(endVerse, toVersification); return new VerseRange(toVersification, convertedStartVerse, convertedEndVerse); }
@Override public VerseRange blur(Versification v11n, VerseRange range, int blurDown, int blurUp) { Verse start = v11n.subtract(range.getStart(), blurDown); Verse end = v11n.add(range.getEnd(), blurUp); return new VerseRange(v11n, start, end); }
public void add(Key obj) { optimizeWrites(); VerseRange thatRange = toVerseRange(getVersification(), obj); store.add(thatRange); normalize(); // we do an extra check here because the cost of calculating the // params is non-zero an may be wasted if (suppressEvents == 0) { fireIntervalAdded(this, thatRange.getStart(), thatRange.getEnd()); } }
/** * Do the 2 VerseRanges in question actually overlap. This is slightly more * restrictive than the adjacentTo() test which could be satisfied by ranges * like Gen 1:1-2 and Gen 1:3-4. overlaps() however would return false given * these ranges. For example Gen 1:1-2 is adjacent to Gen 1:1-5 but not to * Gen 1:3-4 not to Gen 1:4-10. Also Gen 1:29-30 does not overlap Gen 2:1-10 * * @param that * The VerseRange to compare to * @return true if the ranges are adjacent */ public boolean overlaps(VerseRange that) { int thatStart = that.getStart().getOrdinal(); int thatEnd = that.getEnd().getOrdinal(); int thisStart = getStart().getOrdinal(); int thisEnd = getEnd().getOrdinal(); // if that starts inside this we are adjacent. if (thatStart >= thisStart && thatStart <= thisEnd) { return true; } // if this starts inside that we are adjacent. if (thisStart >= thatStart && thisStart <= thatEnd) { return true; } // otherwise we're not adjacent return false; }
/** * Are the 2 VerseRanges in question contiguous. that is - could they be * represented by a single VerseRange. Note that one range could be entirely * contained within the other and they would be considered adjacentTo() For * example Gen 1:1-2 is adjacent to Gen 1:1-5 and Gen 1:3-4 but not to Gen * 1:4-10. Also Gen 1:29-30 is adjacent to Gen 2:1-10 * * @param that * The VerseRange to compare to * @return true if the ranges are adjacent */ public boolean adjacentTo(VerseRange that) { int thatStart = that.getStart().getOrdinal(); int thatEnd = that.getEnd().getOrdinal(); int thisStart = getStart().getOrdinal(); int thisEnd = getEnd().getOrdinal(); // if that starts inside or is next to this we are adjacent. if (thatStart >= thisStart - 1 && thatStart <= thisEnd + 1) { return true; } // if this starts inside or is next to that we are adjacent. if (thisStart >= thatStart - 1 && thisStart <= thatEnd + 1) { return true; } // otherwise we're not adjacent return false; }
@Override public Verse createStartVerse(Versification v11n, VerseRange verseRangeBasis, String[] parts) throws NoSuchVerseException { if (verseRangeBasis == null) { // TRANSLATOR: The user supplied a verse reference but did not give the book of the Bible. throw new NoSuchVerseException(JSMsg.gettext("Book is missing")); } BibleBook book = verseRangeBasis.getEnd().getBook(); int chapter = getChapter(v11n, book, parts[0]); int verse = 0; // chapter > 0 ? 1 : 0; // 0 ? return new Verse(v11n, book, chapter, verse); }
/** * Create a VerseRange that is the stuff in VerseRange a that is also * in VerseRange b. * * @param a * The verses that you might want * @param b * The verses that you definitely don't * @return A list of the Verses outstanding */ public static VerseRange intersection(VerseRange a, VerseRange b) { Versification v11n = a.getVersification(); Verse newStart = v11n.max(a.getStart(), b.getStart()); Verse newEnd = v11n.min(a.getEnd(), b.getEnd()); if (v11n.distance(newStart, newEnd) >= 0) { return new VerseRange(a.getVersification(), newStart, newEnd); } return null; }
@Test public void testGetNextVerseRangeWrapsToNextChapter() throws Exception { assertThat(bibleTraverser.getNextVerseRange(testBook, TestData.KJV_PS_14).getStart(), equalTo(new Verse(TestData.KJV, BibleBook.PS, 15, 1))); assertThat(bibleTraverser.getNextVerseRange(testBook, TestData.KJV_PS_14).getEnd(), equalTo(new Verse(TestData.KJV, BibleBook.PS, 16, 2))); }
@Test public void testGetPreviousVerseRangeWrapsToPreviousChapter() throws Exception { assertThat(bibleTraverser.getPreviousVerseRange(testBook, TestData.KJV_PS_14).getStart(), equalTo(new Verse(TestData.KJV, BibleBook.PS, 12, 8))); assertThat(bibleTraverser.getPreviousVerseRange(testBook, TestData.KJV_PS_14).getEnd(), equalTo(new Verse(TestData.KJV, BibleBook.PS, 13, 6))); }
@Override public Verse createStartVerse(Versification v11n, VerseRange verseRangeBasis, String[] parts) throws NoSuchVerseException { if (verseRangeBasis == null) { // TRANSLATOR: The user supplied a verse reference but did not give the book of the Bible. throw new NoSuchVerseException(JSMsg.gettext("Book is missing")); } BibleBook book = verseRangeBasis.getEnd().getBook(); int chapter = getChapter(v11n, book, parts[0]); int verse = getVerse(v11n, book, chapter, parts[1]); return new Verse(v11n, book, chapter, verse, getSubIdentifier(parts)); }
@Override public VerseRange blur(Versification v11n, VerseRange range, int blurDown, int blurUp) { Verse start = range.getStart(); BibleBook startBook = start.getBook(); int startChapter = start.getChapter(); int startVerse = start.getVerse() - blurDown; Verse end = range.getEnd(); BibleBook endBook = end.getBook(); int endChapter = end.getChapter(); int endVerse = end.getVerse() + blurUp; startVerse = Math.max(startVerse, 0); endVerse = Math.min(endVerse, v11n.getLastVerse(endBook, endChapter)); Verse newStart = new Verse(v11n, startBook, startChapter, startVerse); Verse newEnd = new Verse(v11n, endBook, endChapter, endVerse); return new VerseRange(v11n, newStart, newEnd); }
public VerseRange getPreviousVerseRange(AbstractPassageBook document, VerseRange verseRange, boolean continueToPreviousChapter) { Versification v11n = verseRange.getVersification(); int verseCount = verseRange.getCardinality(); // shuffle backward Verse start = verseRange.getStart(); Verse end = verseRange.getEnd(); int i=0; while (i++<verseCount && (continueToPreviousChapter || !v11n.isStartOfChapter(start))) { start = getPrevVerse(document, start); end = getPrevVerse(document, end); } return new VerseRange(v11n, start, end); }
public VerseRange getNextVerseRange(AbstractPassageBook document, VerseRange verseRange, boolean continueToNextChapter) { Versification v11n = verseRange.getVersification(); int verseCount = verseRange.getCardinality(); // shuffle forward Verse start = verseRange.getStart(); Verse end = verseRange.getEnd(); int i=0; while (i++<verseCount && (continueToNextChapter || !v11n.isEndOfChapter(end))) { start = getNextVerse(document, start); end = getNextVerse(document, end); } return new VerseRange(v11n, start, end); }
@Override public void removeAll(Key key) { optimizeWrites(); if (key instanceof BitwisePassage) { BitwisePassage thatRef = (BitwisePassage) key; store.andNot(thatRef.store); } else { super.removeAll(key); } // we do an extra check here because the cost of calculating the // params is non-zero and may be wasted if (suppressEvents == 0 && !key.isEmpty()) { if (key instanceof Passage) { Passage that = (Passage) key; fireIntervalRemoved(this, that.getVerseAt(0), that.getVerseAt(that.countVerses() - 1)); } else if (key instanceof VerseRange) { VerseRange that = (VerseRange) key; fireIntervalRemoved(this, that.getStart(), that.getEnd()); } else if (key instanceof Verse) { Verse that = (Verse) key; fireIntervalRemoved(this, that, that); } } }