An ArrayList that reuses a single iterator

This commit is contained in:
zab
2012-11-22 21:50:48 +00:00
parent e974d3bc55
commit 1e83028702
2 changed files with 151 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
package net.i2p.util;
import static org.junit.Assert.*;
import java.util.Iterator;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
public class CachedIteratorArrayListTest {
private List<Integer> l;
@Before
public void setUp() {
l = new CachedIteratorArrayList<Integer>();
l.add(1);
l.add(2);
l.add(3);
}
@Test
public void test() {
// test for-each worx
int total = 0;
for (int i : l)
total += i;
assertEquals(6, total);
for (int i : l)
total += i;
assertEquals(12, total);
}
@Test
public void testSameness() {
Iterator<Integer> two = l.iterator();
Iterator<Integer> one = l.iterator();
assertSame(one, two);
}
}