/** * Determine the later of the two verses. * If first == second then return first. * * @param first the first verse to compare * @param second the second verse to compare * @return The later of the two verses */ public Verse max(Verse first, Verse second) { return first.getOrdinal() > second.getOrdinal() ? first : second; }
/** * Determine the earlier of the two verses. * If first == second then return first. * * @param first the first verse to compare * @param second the second verse to compare * @return The earlier of the two verses */ public Verse min(Verse first, Verse second) { return first.getOrdinal() <= second.getOrdinal() ? first : second; }
/** * The ranking given to a specific verse * * @param verse * The verse to get the ranking of * @return The rank of the verse in question */ public int getTallyOf(Verse verse) { return board[verse.getOrdinal()]; }
/** * What is the index of the give verse in the current ordering scheme * * @param verse * The verse to get the index of * @return The index of the verse or -1 if the verse was not found */ public int getIndexOf(Verse verse) { int pos = verse.getOrdinal(); int tally = board[pos]; return tally > 0 ? pos : -1; }
/** * How many verses are there in between the 2 Verses. The answer is -ve if * start is bigger than end. The answer is inclusive of start and exclusive * of end, so that <code>distance(gen11, gen12) == 1</code> * * @param start * The first Verse in the range * @param end The last Verse in the range * @return The count of verses between this and that. */ public int distance(Verse start, Verse end) { return end.getOrdinal() - start.getOrdinal(); }
/** * Does this tally contain all the specified verses? * * @param that * The verses to test for * @return true if all the verses exist in this tally */ @Override public boolean contains(Key that) { for (Key aKey : that) { Verse verse = (Verse) aKey; if (board[verse.getOrdinal()] == 0) { return false; } } return true; }
@Override public boolean contains(Key obj) { for (Key aKey : obj) { Verse verse = (Verse) aKey; if (!store.get(verse.getOrdinal())) { return false; } } return true; }
/** * Create an array of Verses * * @return The array of verses that this makes up */ public Verse[] toVerseArray() { Verse[] retcode = new Verse[verseCount]; int ord = start.getOrdinal(); for (int i = 0; i < verseCount; i++) { retcode[i] = v11n.decodeOrdinal(ord + i); } return retcode; }
/** * Get percentage value of reading progress of the verse within its biblebook. */ public int getPercentOfBook(@NotNull Verse verse) { Versification v11n = verse.getVersification(); BibleBook bibleBook = verse.getBook(); int lastChapterNumber = v11n.getLastChapter(bibleBook); int lastVerseNumber = v11n.getLastVerse(bibleBook, lastChapterNumber); Verse lastVerse = new Verse(v11n, bibleBook, lastChapterNumber, lastVerseNumber); Verse firstVerse = new Verse(v11n, bibleBook, 1, 1); return (int)((((double)(verse.getOrdinal() - firstVerse.getOrdinal())) / (lastVerse.getOrdinal() - firstVerse.getOrdinal())) * 100.0); } }
public void add(Key obj) { optimizeWrites(); Verse firstVerse = null; Verse lastVerse = null; for (Key aKey : obj) { lastVerse = (Verse) aKey; if (firstVerse == null) { firstVerse = lastVerse; } store.set(lastVerse.getOrdinal()); } // we do an extra check here because the cost of calculating the // params is non-zero and may be wasted if (suppressEvents == 0) { fireIntervalAdded(this, firstVerse, lastVerse); } }
public void remove(Key obj) { optimizeWrites(); Verse firstVerse = null; Verse lastVerse = null; for (Key aKey : obj) { lastVerse = (Verse) aKey; if (firstVerse == null) { firstVerse = lastVerse; } store.clear(lastVerse.getOrdinal()); } // we do an extra check here because the cost of calculating the // params is non-zero and may be wasted if (suppressEvents == 0) { fireIntervalAdded(this, firstVerse, lastVerse); } }
/** * Increment/Decrement this verses in the rankings * * @param that * The verses to add/increment * @param tally * The amount to increment/decrement by */ private void alterVerseBase(Key that, int tally) { for (Key aKey : that) { Verse verse = (Verse) aKey; increment(verse.getOrdinal(), tally); } if (tally > 0) { incrementMax(tally); } }
@Override public void retainAll(Key key) { optimizeWrites(); BitSet thatStore = null; if (key instanceof BitwisePassage) { thatStore = ((BitwisePassage) key).store; } else { Versification v11n = getVersification(); thatStore = new BitSet(v11n.maximumOrdinal() + 1); for (Key aKey : key) { int ord = ((Verse) aKey).getOrdinal(); if (store.get(ord)) { thatStore.set(ord); } } } store.and(thatStore); fireIntervalRemoved(this, null, null); }
/** * Remove these verses from the rankings, ie, set their rank to zero. * * @param that * The verses to remove/decrement */ public void remove(Key that) { optimizeWrites(); for (Key aKey : that) { Verse verse = (Verse) aKey; kill(verse.getOrdinal()); } fireIntervalRemoved(this, null, null); }
/** * Convert the verse correctly to the v11n or return null */ @Nullable private Verse convertVerseStrictly(Verse verse, Versification toVersification) { try { Key key = versificationsMapper.mapVerse(verse, toVersification); Verse mappedVerse = KeyUtil.getVerse(key); // If target v11n does not contain mapped verse then an exception normally occurs and the ordinal is set to 0 if (mappedVerse.getOrdinal()>0) { return mappedVerse; } } catch (Exception e) { // unexpected problem during mapping Log.e(TAG, "JSword Versification mapper failed to map "+verse.getOsisID()+" from "+verse.getVersification().getName()+" to "+toVersification.getName(), e); } return null; } }
/** * Get the verse n down from here this Verse. * * @param verse * The verse to use as a start * @param n * The number to count down by * @return The new Verse */ public Verse subtract(Verse verse, int n) { int newVerse = verse.getVerse() - n; // Try the simple case of the verse being in the same chapter if (newVerse >= 0) { return new Verse(verse.getVersification(), verse.getBook(), verse.getChapter(), newVerse); } return decodeOrdinal(verse.getOrdinal() - n); }
public void setAliasKey(RawFileBackendState state, Key alias, Key source) throws IOException { String v11nName = getBookMetaData().getProperty(BookMetaData.KEY_VERSIFICATION); Versification v11n = Versifications.instance().getVersification(v11nName); Verse aliasVerse = KeyUtil.getVerse(alias); Verse sourceVerse = KeyUtil.getVerse(source); int aliasIndex = aliasVerse.getOrdinal(); Testament testament = v11n.getTestament(aliasIndex); aliasIndex = v11n.getTestamentOrdinal(aliasIndex); RandomAccessFile idxRaf = state.getIdxRaf(testament); int sourceOIndex = sourceVerse.getOrdinal(); sourceOIndex = v11n.getTestamentOrdinal(sourceOIndex); DataIndex dataIndex = getIndex(idxRaf, sourceOIndex); // Only the index is updated to point to the same place as what is // linked. updateIndexFile(idxRaf, aliasIndex, dataIndex.getOffset()); }
@Override public void addAll(Key that) { optimizeWrites(); if (that instanceof PassageTally) { PassageTally tally = (PassageTally) that; int vib = getVersification().maximumOrdinal(); for (int i = 0; i <= vib; i++) { increment(i, tally.board[i]); } incrementMax(tally.max); } else { for (Key aKey : that) { Verse verse = (Verse) aKey; increment(verse.getOrdinal(), 1); } incrementMax(1); } fireIntervalAdded(this, null, null); }
/** * Get the verse that is a few verses on from the one we've got. * * @param verse * The verse to use as a start * @param n * the number of verses later than the one we're one * @return The new verse */ public Verse add(Verse verse, int n) { int newVerse = verse.getVerse() + n; // Try the simple case of the verse being in the same chapter if (newVerse <= getLastVerse(verse.getBook(), verse.getChapter())) { return new Verse(verse.getVersification(), verse.getBook(), verse.getChapter(), newVerse); } return decodeOrdinal(verse.getOrdinal() + n); }
public String readRawContent(RawBackendState state, Key key) throws IOException { String v11nName = getBookMetaData().getProperty(BookMetaData.KEY_VERSIFICATION); Versification v11n = Versifications.instance().getVersification(v11nName); Verse verse = KeyUtil.getVerse(key); int index = verse.getOrdinal(); Testament testament = v11n.getTestament(index); index = v11n.getTestamentOrdinal(index); RawBackendState initState = null; try { initState = initState(); return getEntry(state, verse.getName(), testament, index); } catch (BookException e) { return ""; } finally { OpenFileStateManager.instance().release(initState); } }