@Override public boolean contains(Key obj) { // Even for the contains(VerseRange) case, the simple // 'return store.contains(that);' will not work because // VerseRanges can contain others but not be equal to them. VerseRange thatRange = toVerseRange(getVersification(), obj); Iterator<VerseRange> it = rangeIterator(RestrictionType.NONE); while (it.hasNext()) { VerseRange thisRange = it.next(); if (thisRange.contains(thatRange)) { return true; } } // If it is not a Verse or a VerseRange then it's not here, // this also copes with the searches failing. return false; }
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()); } }
Iterator<Key> thatIter = key.iterator(); while (thatIter.hasNext()) { VerseRange thatRange = toVerseRange(getVersification(), thatIter.next());
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()); } }