private void testListIterator(List <DSInteger> the_list) { ListIterator <DSInteger> it = the_list.listIterator(); int count = 0; while (it.hasNext()) { count++; it.next(); } //you are at the last item, not one before the first item when the //initial loop begins count--; while (it.hasPrevious()) { count--; it.previous(); } Assert.AreEqual(0, count); //test values returned it = the_list.listIterator(); Assert.AreEqual(30, it.next().value); Assert.AreEqual(60, it.next().value); //test removal DSInteger removed = it.remove(); Assert.AreEqual(60, removed.value); Assert.AreEqual(90, it.next().value); it.next(); //120 it.next(); //150 //test removing the last item Assert.AreEqual(false, it.hasNext()); Assert.AreEqual(150, it.remove().value); Assert.AreEqual(false, it.hasNext()); Assert.AreEqual(90, it.previous().value); Assert.AreEqual(true, it.hasNext()); Assert.AreEqual(120, it.next().value); //test removing the first item the_list.clear(); addInitialItems(the_list); it = the_list.listIterator(); Assert.AreEqual(false, it.hasPrevious()); Assert.AreEqual(30, it.next().value); it.remove(); Assert.AreEqual(false, it.hasPrevious()); Assert.AreEqual(60, it.next().value); Assert.AreEqual(90, it.next().value); Assert.AreEqual(60, it.previous().value); Assert.AreEqual(false, it.hasPrevious()); }
//public abstract ListIterator<E> listIterator(int location); public override E remove(int location) { try { ListIterator <E> it = listIterator(location); E result = it.next(); it.remove(); return(result); } catch (NoSuchElementException) { throw new java.lang.IndexOutOfBoundsException(); } }
internal virtual void optimize() { for (int i = 0; i < this.arcList.size(); i++) { GrammarArc grammarArc = (GrammarArc)this.arcList.get(i); this.arcList.set(i, this.optimizeArc(grammarArc)); } if (this.isEmpty()) { ListIterator listIterator = this.arcList.listIterator(); while (listIterator.hasNext()) { GrammarArc grammarArc = (GrammarArc)listIterator.next(); if (this == grammarArc.getGrammarNode()) { listIterator.remove(); } } } }
public void remove() { iterator.remove(); subList.sizeChanged(false); end--; }