/** * Create a Verse from a human readable string. The opposite of getName(), * Given any RangedPassage v1, and the following * <code>RangedPassage v2 = new RangedPassage(v1.getName());</code> Then * <code>v1.equals(v2);</code> Theoretically, since there are many ways of * representing a RangedPassage as text string comparison along the lines * of: <code>v1.getName().equals(v2.getName())</code> could be false. * However since getName() is standardized this will be true. 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 RangedPassage * @param basis * The basis by which to interpret refs * @throws NoSuchVerseException * if refs is invalid */ protected RangedPassage(Versification v11n, String refs, Key basis) throws NoSuchVerseException { super(v11n, refs); store = new TreeSet<VerseRange>(); addVerses(refs, basis); normalize(); }
public void add(Key obj) { optimizeWrites(); VerseRange thatRange = toVerseRange(getVersification(), obj); store.add(thatRange); normalize(); // 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, thatRange.getStart(), thatRange.getEnd()); } }
public void remove(Key obj) { optimizeWrites(); VerseRange thatRange = toVerseRange(getVersification(), obj); boolean removed = false; // This allows us to modify store which iterating through a copy Set<Key> newStore = new TreeSet<Key>(); newStore.addAll(store); // go through all the VerseRanges for (Key aKey : newStore) { // if this range touches the range to be removed ... VerseRange thisRange = (VerseRange) aKey; if (thisRange.overlaps(thatRange)) { // ... remove it and add the remainder store.remove(thisRange); VerseRange[] vra = VerseRange.remainder(thisRange, thatRange); for (int i = 0; i < vra.length; i++) { store.add(vra[i]); } removed = true; } } if (removed) { normalize(); } // we do an extra check here because the cost of calculating the // params is non-zero an may be wasted if (suppressEvents == 0) { fireIntervalRemoved(this, thatRange.getStart(), thatRange.getEnd()); } }