@Override public void clear() { optimizeWrites(); store.clear(); fireIntervalRemoved(this, null, null); }
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); } }
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 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); }
/** * Call the support mechanism in AbstractPassage * * @param in * The stream to read our state from * @throws IOException * if the read fails * @throws ClassNotFoundException * If the read data is incorrect * @serialData Write the ordinal number of this verse * @see AbstractPassage#readObjectSupport(ObjectInputStream) */ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { optimizeWrites(); in.defaultReadObject(); // Read the versification by name String v11nName = in.readUTF(); Versification v11n = Versifications.instance().getVersification(v11nName); store = new BitSet(v11n.maximumOrdinal() + 1); readObjectSupport(in); }
/** * 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); } }
@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); } } }
@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); } } }