@Test public void testForget() { LiveList<Integer> source = new LiveArrayList<>(0, 1, 2, 3, 4, 5, 6); MemoizationList<Integer> memoizing = source.memoize(); LiveList<Integer> memoized = memoizing.memoizedItems(); memoizing.pin(); memoizing.force(0, 7); assertEquals(7, memoized.size()); memoizing.forget(2, 4); assertEquals(5, memoized.size()); memoizing.forget(3, 5); assertEquals(4, memoized.size()); Counter counter = new Counter(); memoized.observeQuasiChanges(ch -> { counter.inc(); assertEquals(1, ch.getModificationCount()); QuasiListModification<?> mod = ch.getModifications().get(0); assertEquals(1, mod.getFrom()); assertEquals(Arrays.asList(1, 5), mod.getRemoved()); assertEquals(0, mod.getAddedSize()); }); memoizing.forget(1, 6); assertEquals(1, counter.get()); }
@Override public void forget(int from, int to) { if(!isObservingInputs()) { throw new IllegalStateException( "There is nothing to forget, because memoization is off." + " To turn memoization on, you have to be observing this" + " list or its memoizedItems."); } Lists.checkRange(from, to, size()); int memoChangeFrom = sparseList.getPresentCountBefore(from); List<E> memoRemoved = sparseList.collect(from, to); sparseList.spliceByVoid(from, to, to - from); memoizedItems.fireRemoveRange(memoChangeFrom, memoRemoved); }
MemoizationListImpl extends LiveListBase<E> implements MemoizationList<E>, UnmodifiableByDefaultLiveList<E> { @Override public void forget(int from, int to) { if(!isObservingInputs()) { throw new IllegalStateException( "There is nothing to forget, because memoization is off." + " To turn memoization on, you have to be observing this" + " list or its memoizedItems."); } Lists.checkRange(from, to, size()); int memoChangeFrom = sparseList.getPresentCountBefore(from); List<E> memoRemoved = sparseList.collect(from, to); sparseList.spliceByVoid(from, to, to - from); memoizedItems.fireRemoveRange(memoChangeFrom, memoRemoved); } }
MemoizationListImpl extends LiveListBase<E> implements MemoizationList<E>, UnmodifiableByDefaultLiveList<E> { @Override public void forget(int from, int to) { if(!isObservingInputs()) { throw new IllegalStateException( "There is nothing to forget, because memoization is off." + " To turn memoization on, you have to be observing this" + " list or its memoizedItems."); } Lists.checkRange(from, to, size()); int memoChangeFrom = sparseList.getPresentCountBefore(from); List<E> memoRemoved = sparseList.collect(from, to); sparseList.spliceByVoid(from, to, to - from); memoizedItems.fireRemoveRange(memoChangeFrom, memoRemoved); } MemoizationListImpl(ObservableList<E> source); }
MemoizationListImpl extends LiveListBase<E> implements MemoizationList<E>, UnmodifiableByDefaultLiveList<E> { @Override public void forget(int from, int to) { if(!isObservingInputs()) { throw new IllegalStateException( "There is nothing to forget, because memoization is off." + " To turn memoization on, you have to be observing this" + " list or its memoizedItems."); } Lists.checkRange(from, to, size()); int memoChangeFrom = sparseList.getPresentCountBefore(from); List<E> memoRemoved = sparseList.collect(from, to); sparseList.spliceByVoid(from, to, to - from); memoizedItems.fireRemoveRange(memoChangeFrom, memoRemoved); } MemoizationListImpl(ObservableList<E> source); @Override E get(int index); @Override void force(int from, int to); @Override int size(); @Override LiveList<E> memoizedItems(); @Override boolean isMemoized(int index); @Override Optional<E> getIfMemoized(int index); @Override int getMemoizedCountBefore(int position); @Override int getMemoizedCountAfter(int position); @Override int getMemoizedCount(); @Override void forget(int from, int to); @Override int indexOfMemoizedItem(int index); @Override IndexRange getMemoizedItemsRange(); }
MemoizationListImpl extends LiveListBase<E> implements MemoizationList<E>, UnmodifiableByDefaultLiveList<E> { @Override public void forget(int from, int to) { if(!isObservingInputs()) { throw new IllegalStateException( "There is nothing to forget, because memoization is off." + " To turn memoization on, you have to be observing this" + " list or its memoizedItems."); } Lists.checkRange(from, to, size()); int memoChangeFrom = sparseList.getPresentCountBefore(from); List<E> memoRemoved = sparseList.collect(from, to); sparseList.spliceByVoid(from, to, to - from); memoizedItems.fireRemoveRange(memoChangeFrom, memoRemoved); } MemoizationListImpl(ObservableList<E> source); @Override E get(int index); @Override void force(int from, int to); @Override int size(); @Override LiveList<E> memoizedItems(); @Override boolean isMemoized(int index); @Override Optional<E> getIfMemoized(int index); @Override int getMemoizedCountBefore(int position); @Override int getMemoizedCountAfter(int position); @Override int getMemoizedCount(); @Override void forget(int from, int to); @Override int indexOfMemoizedItem(int index); @Override IndexRange getMemoizedItemsRange();  }