@Override public Passage createEmptyPassage(Versification v11n) { return new DistinctPassage(v11n); }
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.add(lastVerse); } // 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, firstVerse, lastVerse); } }
@Override public void clear() { optimizeWrites(); store.clear(); fireIntervalRemoved(this, null, null); }
@Override public void optimizeReads() { raiseEventSuppresion(); // We have to create the cached versions of these separately // so that the calculations made by addAll(this) can // safely call methods like countVerses() without any // danger of them being optimized before the optimizations // are ready for use. DistinctPassage dtemp = new DistinctPassage(getVersification()); dtemp.raiseEventSuppresion(); dtemp.addAll(this); dtemp.lowerEventSuppressionAndTest(); RangedPassage rtemp = new RangedPassage(getVersification()); rtemp.raiseEventSuppresion(); rtemp.addAll(this); rtemp.lowerEventSuppressionAndTest(); distinct = dtemp; ranged = rtemp; // This is just an optimization so we dont need to fire any events lowerEventSuppressionAndTest(); }
@Override public int booksInPassage() { if (distinct != null) { return distinct.booksInPassage(); } return super.booksInPassage(); }
@Override public int countVerses() { if (distinct != null) { return distinct.countVerses(); } return super.countVerses(); }
@Override public Iterator<Key> iterator() { if (distinct != null) { return distinct.iterator(); } return super.iterator(); }
@Override public boolean isEmpty() { if (distinct != null) { return distinct.isEmpty(); } return super.isEmpty(); }
@Override public Verse getVerseAt(int offset) throws ArrayIndexOutOfBoundsException { if (distinct != null) { return distinct.getVerseAt(offset); } return super.getVerseAt(offset); }
/** * Create a Verse from a human readable string. The opposite of toString(), * Given any DistinctPassage v1, and the following * <code>DistinctPassage v2 = new DistinctPassage(v1.toString());</code> * Then <code>v1.equals(v2);</code> Theoretically, since there are many ways * of representing a DistinctPassage 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 DistinctPassage * @param basis * The basis by which to interpret refs * @throws NoSuchVerseException * If the string is not valid */ protected DistinctPassage(Versification v11n, String refs, Key basis) throws NoSuchVerseException { super(v11n, refs); store = Collections.synchronizedSortedSet(new TreeSet<Key>()); addVerses(refs, basis); }
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.remove(lastVerse); } // 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, firstVerse, lastVerse); } }
@Override public Passage createPassage(Versification v11n, String passage, Key basis) throws NoSuchVerseException { if (passage == null || passage.length() == 0) { return createEmptyPassage(v11n); } return new DistinctPassage(v11n, passage, basis); }