예제 #1
1
  public void testSITwo() {
    HashSet s1 = new HashSet();
    s1.add("a");
    Iterators.Sequence it = new Iterators.Sequence(new Iterator[] {s1.iterator()});
    assertIteration(it, new Object[] {"a"});
    it.remove();
    assertEquals(Collections.EMPTY_SET, s1);
    assertIllegalState(it);

    List xs = Arrays.asList(new String[] {"a", "b"});
    List ixs = Collections.unmodifiableList(xs);
    Iterators.Sequence it2 = new Iterators.Sequence(new Iterator[] {ixs.iterator()});
    assertIteration(it2, new Object[] {"a", "b"});
    assertUnsupportedOperation(it2); // explicitly not modifiable

    ArrayList xs2 = new ArrayList();
    xs2.add("a");
    xs2.add("b");
    Iterators.Sequence it3 = new Iterators.Sequence(new Iterator[] {xs2.iterator()});
    assertIteration(it3, new Object[] {"a", "b"});
    it3.remove();
    ArrayList xs2expected = new ArrayList();
    xs2expected.add("a");
    assertEquals(xs2expected, xs2);

    ArrayList xs3 = new ArrayList();
    xs3.add("a");
    xs3.add("b");
    Iterators.Sequence it4 = new Iterators.Sequence(new Iterator[] {xs3.iterator()});
    it4.next();
    it4.remove();
    ArrayList xs3expected = new ArrayList();
    xs3expected.add("b");
    assertEquals(xs3expected, xs3);
  }
예제 #2
0
 public void testSISix() {
   ArrayList empty = new ArrayList();
   ArrayList ab = new ArrayList();
   ab.add("a");
   ab.add("b");
   ArrayList cd = new ArrayList();
   cd.add("c");
   cd.add("d");
   Iterators.Sequence it =
       new Iterators.Sequence(
           new Iterator[] {
             ab.iterator(), empty.iterator(),
             empty.iterator(), cd.iterator()
           });
   it.next();
   it.next();
   it.remove();
   ArrayList a = new ArrayList();
   a.add("a");
   assertEquals(a, ab);
   it.next();
   it.remove();
   ArrayList d = new ArrayList();
   d.add("d");
   assertEquals(d, cd);
 }