@Override public Passage createEmptyPassage(Versification v11n) { return new BitwisePassage(v11n); } },
@Override public int booksInPassage() { if (distinct != null) { return distinct.booksInPassage(); } return super.booksInPassage(); }
@Override public boolean containsAll(Passage that) { if (ranged != null) { return ranged.containsAll(that); } return super.containsAll(that); }
@Override public void clear() { optimizeWrites(); store.clear(); fireIntervalRemoved(this, null, null); }
/** * A shortcut to adding a key, by ordinal. The ordinal needs to be taken * from the same versification as the passage being created. * * @param ordinal * the ordinal */ public void addVersifiedOrdinal(int ordinal) { optimizeWrites(); store.set(ordinal); // we do an extra check here because the cost of calculating the // params is non-zero and may be wasted if (suppressEvents == 0) { Verse verse = getVersification().decodeOrdinal(ordinal); fireIntervalAdded(this, verse, verse); } }
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); } }
@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); } } }
passage.raiseEventSuppresion(); passage.raiseNormalizeProtection(); passage.addVersifiedOrdinal(v11n.getOrdinal(currentTestament, ordinal)); passage.addVersifiedOrdinal(v11n.getOrdinal(currentTestament, ordinal)); passage.lowerNormalizeProtection(); passage.lowerEventSuppressionAndTest();
@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); }
@Override public int countVerses() { if (distinct != null) { return distinct.countVerses(); } return super.countVerses(); }
@Override public VerseRange getRangeAt(int offset, RestrictionType restrict) throws ArrayIndexOutOfBoundsException { if (ranged != null) { return ranged.getRangeAt(offset, restrict); } return super.getRangeAt(offset, restrict); }
@Override public int countRanges(RestrictionType restrict) { if (ranged != null) { return ranged.countRanges(restrict); } return super.countRanges(restrict); }
/** * Create a Verse from a human readable string. The opposite of toString(), * Given any BitwisePassage v1, and the following * <code>DistinctPassage v2 = new BitwisePassage(v1.toString());</code> Then * <code>v1.equals(v2);</code> Theoretically, since there are many ways of * representing a BitwisePassage as text string comparison along the lines * of: <code>v1.toString().equals(v2.toString())</code> could be false. * Practically since toString() is standardized this will be true however. * We don't need to worry about thread safety in a ctor since we don't exist * yet. * * @param v11n * The Versification to which this Passage belongs. * @param refs * A String containing the text of the BitwisePassage * @param basis * The basis by which to interpret refs * @throws NoSuchVerseException * If the string is not parsable */ protected BitwisePassage(Versification v11n, String refs, Key basis) throws NoSuchVerseException { super(v11n, refs); store = new BitSet(v11n.maximumOrdinal() + 1); addVerses(refs, basis); }
passage.raiseEventSuppresion(); passage.raiseNormalizeProtection(); passage.addVersifiedOrdinal(v11n.getOrdinal(currentTestament, ordinal)); passage.addVersifiedOrdinal(v11n.getOrdinal(currentTestament, ordinal)); passage.lowerNormalizeProtection(); passage.lowerEventSuppressionAndTest();
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); } }
@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); } } }
@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); } } }
@Override public Passage createPassage(Versification v11n, String passage, Key basis) throws NoSuchVerseException { if (passage == null || passage.length() == 0) { return createEmptyPassage(v11n); } return new BitwisePassage(v11n, passage, basis); }