public void blur(int verses, RestrictionType restrict) { optimizeWrites(); raiseEventSuppresion(); raiseNormalizeProtection(); Passage temp = this.clone(); Iterator<VerseRange> it = temp.rangeIterator(RestrictionType.NONE); while (it.hasNext()) { VerseRange range = restrict.blur(getVersification(), it.next(), verses, verses); add(range); } lowerNormalizeProtection(); if (lowerEventSuppressionAndTest()) { fireIntervalAdded(this, null, null); } }
public void readDescription(Reader in) throws IOException, NoSuchVerseException { raiseEventSuppresion(); raiseNormalizeProtection(); int count = 0; // number of lines read // Quiet Android from complaining about using the default BufferReader buffer size. // The actual buffer size is undocumented. So this is a good idea any way. BufferedReader bin = new BufferedReader(in, 8192); String v11nName = bin.readLine(); v11n = Versifications.instance().getVersification(v11nName); while (true) { String line = bin.readLine(); if (line == null) { break; } count++; addVerses(line, null); } // If the file was empty then there is nothing to do if (count == 0) { return; } lowerNormalizeProtection(); if (lowerEventSuppressionAndTest()) { fireIntervalAdded(this, getVerseAt(0), getVerseAt(countVerses() - 1)); } }
public void retainAll(Key key) { optimizeWrites(); raiseEventSuppresion(); raiseNormalizeProtection(); Passage temp = this.clone(); for (Key verse : temp) { if (!key.contains(verse)) { remove(verse); } } lowerNormalizeProtection(); if (lowerEventSuppressionAndTest()) { fireIntervalRemoved(this, null, null); } }
public Passage trimVerses(int count) { optimizeWrites(); raiseNormalizeProtection(); int i = 0; boolean overflow = false; Passage remainder = this.clone(); for (Key verse : this) { i++; if (i > count) { remove(verse); overflow = true; } else { remainder.remove(verse); } } lowerNormalizeProtection(); // The event notification is done by the remove above if (overflow) { return remainder; } return null; }
optimizeWrites(); raiseEventSuppresion(); raiseNormalizeProtection(); while (it.hasNext()) { add(it.next()); add(subkey); lowerNormalizeProtection(); if (lowerEventSuppressionAndTest()) { if (key instanceof Passage) { Passage that = (Passage) key; fireIntervalAdded(this, that.getVerseAt(0), that.getVerseAt(that.countVerses() - 1)); } else if (key instanceof VerseRange) { VerseRange that = (VerseRange) key; fireIntervalAdded(this, that.getStart(), that.getEnd()); } else if (key instanceof Verse) { Verse that = (Verse) key; fireIntervalAdded(this, that, that);
raiseEventSuppresion(); raiseNormalizeProtection(); for (int i = 0; i < v11n.maximumOrdinal(); i++) { if (store.get(i)) { add(v11n.decodeOrdinal(i)); for (int i = 0; i < verses; i++) { int ord = is.readInt(); add(v11n.decodeOrdinal(ord)); int ord = is.readInt(); int count = is.readInt(); add(RestrictionType.NONE.toRange(getVersification(), v11n.decodeOrdinal(ord), count)); lowerEventSuppressionAndTest(); lowerNormalizeProtection();
int rangedSize = 8 * countRanges(RestrictionType.NONE); int distinctSize = 4 * countVerses(); Iterator<Key> iter = iterator(); while (iter.hasNext()) { Verse verse = (Verse) iter.next(); out.writeInt(countVerses()); out.writeInt(countRanges(RestrictionType.NONE)); Iterator<VerseRange> it = rangeIterator(RestrictionType.NONE); while (it.hasNext()) { VerseRange range = it.next();
public int compareTo(Key obj) { Passage thatref = (Passage) obj; if (thatref.countVerses() == 0) { if (countVerses() == 0) { return 0; } // that is empty so he should come before me return -1; } if (countVerses() == 0) { // we are empty be he isn't so we are first return 1; } Verse thatfirst = thatref.getVerseAt(0); Verse thisfirst = getVerseAt(0); return getVersification().distance(thatfirst, thisfirst); }
public VerseRange getRangeAt(int offset, RestrictionType restrict) throws ArrayIndexOutOfBoundsException { Iterator<VerseRange> it = rangeIterator(restrict); Object retcode = null; for (int i = 0; i <= offset; i++) { if (!it.hasNext()) { throw new ArrayIndexOutOfBoundsException(JSOtherMsg.lookupText("Index out of range (Given {0,number,integer}, Max {1,number,integer}).", Integer.valueOf(offset), Integer.valueOf(countVerses()))); } retcode = it.next(); } return (VerseRange) retcode; }
public Verse getVerseAt(int offset) throws ArrayIndexOutOfBoundsException { Iterator<Key> it = iterator(); Object retcode = null; for (int i = 0; i <= offset; i++) { if (!it.hasNext()) { throw new ArrayIndexOutOfBoundsException(JSOtherMsg.lookupText("Index out of range (Given {0,number,integer}, Max {1,number,integer}).", Integer.valueOf(offset), Integer.valueOf(countVerses()))); } retcode = it.next(); } return (Verse) retcode; }
public String getOverview() { // TRANSLATOR: This provides an overview of the verses in one or more books. The placeholders here deserve extra comment. // {0,number,integer} is a placeholder for the count of verses. It will be displayed as an integer using the number system of the user's locale. // {0,choice,0#verses|1#verse|1<verses} uses the value of the number of verses to display the correct singular or plural form for the word "verse" // Choices are separated by |. And each choice consists of a number, a comparison and the value to use when the comparison is met. // Choices are ordered from smallest to largest. The numbers represent boundaries that determine when a choice is used. // The comparison # means to match exactly. // The comparison < means that the number on the left is less than the number being evaluated. // Here, 0 is the first boundary specified by a #. So every number less than or equal to 0 get the first choice. // In this situation, we are dealing with counting numbers, so we'll never have negative numbers. // Next choice is 1 with a boundary specified by #. So all numbers greater than 0 (the first choice) but less than or equal to 1 get the second choice. // In this situation, the only number that will match is 1. // The final choice is 1<. This means that every number greater than 1 will get this choice. // Putting the first two placeholders together we get "0 verses", "1 verse" or "n verses" (where n is 2 or more) // The reason to go into this is that this pattern works for English. Other languages might have different ways of representing singular and plurals. // {1,number,integer} is a placeholder for the count of Bible books. It works the same way as the count of verses. // {1,choice,0#books|1#book|1<books} is the placeholder for the singular or plural of "book" return JSMsg.gettext("{0,number,integer} {0,choice,0#verses|1#verse|1<verses} in {1,number,integer} {1,choice,0#books|1#book|1<books}", Integer.valueOf(countVerses()), Integer.valueOf(booksInPassage() )); }
optimizeWrites(); add(vrBasis); start = 1; add(next); vrBasis = next;
@Override public BitwisePassage clone() { // This gets us a shallow copy BitwisePassage copy = (BitwisePassage) super.clone(); copy.store = (BitSet) store.clone(); return copy; }
public int getCardinality() { return countVerses(); }
@Override public int countRanges(RestrictionType restrict) { if (restrict.equals(RestrictionType.NONE)) { return store.size(); } return super.countRanges(restrict); }
public boolean contains(Key key) { Passage ref = KeyUtil.getPassage(key); return containsAll(ref); }
public boolean containsAll(Passage that) { if (that instanceof RangedPassage) { Iterator<VerseRange> iter = null; iter = ((RangedPassage) that).rangeIterator(RestrictionType.NONE); while (iter.hasNext()) { if (!contains(iter.next())) { return false; } } } else { Iterator<Key> iter = that.iterator(); while (iter.hasNext()) { if (!contains(iter.next())) { return false; } } } return true; }
@Override public void blur(int verses, RestrictionType restrict) { assert verses >= 0; optimizeWrites(); raiseNormalizeProtection(); if (!restrict.equals(RestrictionType.NONE)) { super.blur(verses, restrict); } else { optimizeWrites(); raiseEventSuppresion(); raiseNormalizeProtection(); int maximumOrdinal = getVersification().maximumOrdinal(); BitSet newStore = new BitSet(maximumOrdinal + 1); for (int i = store.nextSetBit(0); i >= 0; i = store.nextSetBit(i + 1)) { int start = Math.max(1, i - verses); int end = Math.min(maximumOrdinal, i + verses); for (int j = start; j <= end; j++) { newStore.set(j); } } store = newStore; lowerNormalizeProtection(); if (lowerEventSuppressionAndTest()) { fireIntervalAdded(this, null, null); } } }
@Override public void addAll(Key key) { //check for key empty. This avoids the AIOBounds with that.getVerseAt, during event firing if (key.isEmpty()) { //nothing to add return; } optimizeWrites(); if (key instanceof BitwisePassage) { BitwisePassage thatRef = (BitwisePassage) key; store.or(thatRef.store); } else { super.addAll(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; fireIntervalAdded(this, that.getVerseAt(0), that.getVerseAt(that.countVerses() - 1)); } else if (key instanceof VerseRange) { VerseRange that = (VerseRange) key; fireIntervalAdded(this, that.getStart(), that.getEnd()); } else if (key instanceof Verse) { Verse that = (Verse) key; fireIntervalAdded(this, that, that); } } }
public Passage trimRanges(int count, RestrictionType restrict) { optimizeWrites(); raiseNormalizeProtection(); int i = 0; boolean overflow = false; Passage remainder = this.clone(); Iterator<VerseRange> it = rangeIterator(restrict); while (it.hasNext()) { i++; Key range = it.next(); if (i > count) { remove(range); overflow = true; } else { remainder.remove(range); } } lowerNormalizeProtection(); // The event notification is done by the remove above if (overflow) { return remainder; } return null; }