Package java.util

Examples of java.util.ListIterator


        for (int i = 0; i < data.length; i++) {
            data[i] = new Data(i);
            list.add(data[i]);
        }

        ListIterator i;

        i = list.listIterator(5);
        i.next();
        Data d = new Data(999);
        i.set(d);
        assertEquals(d, list.get(5));
    }
View Full Code Here


    @Test
    public void testRemoveOnlyElementInList() throws Exception {
        Data d = new Data(0);
        list.add(d);
        ListIterator i = list.listIterator();
        assertTrue(i.hasNext());
        assertEquals(d, i.next());
        i.remove();
        assertTrue(!i.hasNext());
        assertTrue(!i.hasPrevious());
        assertEquals(0, list.size());
    }
View Full Code Here

    @Test
    public void testRemovePrevious() throws Exception {
        Data[] d = {new Data(0), new Data(1), new Data(2)};
        list.addAll(Arrays.asList(d));

        ListIterator i = list.listIterator(list.size());
        i.previous();
        i.previous();
        i.remove();
        assertEquals(2, list.size());
        assertTrue(i.hasPrevious());
        assertEquals(d[0], i.previous());
        assertTrue(!i.hasPrevious());
        assertTrue(i.hasNext());
        assertEquals(d[0], i.next());
        assertTrue(i.hasNext());
        assertEquals(d[2], i.next());
        assertTrue(!i.hasNext());
        assertTrue(i.hasPrevious());
        assertEquals(2, list.size());
    }
View Full Code Here

    @Test
    public void testRemoveLast() throws Exception {
        Data[] d = {new Data(0), new Data(1), new Data(2)};
        list.addAll(Arrays.asList(d));

        ListIterator i = list.listIterator(list.size());
        i.previous();
        i.remove();
        assertEquals(2, list.size());
        assertTrue(i.hasPrevious());
        assertTrue(!i.hasNext());
    }
View Full Code Here

    @Test
    public void testRemoveFirst() throws Exception {
        Data[] d = {new Data(0), new Data(1), new Data(2)};
        list.addAll(Arrays.asList(d));

        ListIterator i = list.listIterator(0);
        i.next();
        i.remove();
        assertEquals(2, list.size());
        assertTrue(!i.hasPrevious());
        assertTrue(i.hasNext());
    }
View Full Code Here

    @Test
    public void testRemoveNext() throws Exception {
        Data[] d = {new Data(0), new Data(1), new Data(2)};
        list.addAll(Arrays.asList(d));

        ListIterator i = list.listIterator();
        assertTrue(i.hasNext());
        i.next();
        assertTrue(i.hasNext());
        assertTrue(i.hasPrevious());
        i.remove();
        assertEquals(2, list.size());
        assertTrue(!i.hasPrevious());
        assertTrue(i.hasNext());
        assertEquals(d[1], i.next());
        assertTrue(i.hasNext());
        assertEquals(d[2], i.next());
        assertTrue(i.hasPrevious());
        assertTrue(!i.hasNext());
    }
View Full Code Here

    @Test
    public void testRemoveThrowsAfterAdd() throws Exception {
        Data d = new Data(0);
        list.add(d);
        ListIterator i = list.listIterator();
        boolean didThrow = false;

        try {
            i.remove();
        } catch (IllegalStateException e) {
            didThrow = true;
        } // end of try-catch
        assertTrue(didThrow);
    }
View Full Code Here

    @Test
    public void testRemoveThrowsWithoutPrevious() throws Exception {
        Data d = new Data(0);
        list.add(d);
        ListIterator i = list.listIterator(list.size());
        boolean didThrow = false;

        assertTrue(i.hasPrevious());
        try {
            i.remove();
        } catch (IllegalStateException e) {
            didThrow = true;
        } // end of try-catch
        assertTrue(didThrow);
    }
View Full Code Here

    @Test
    public void testIteratorAddFront() throws Exception {
        Data[] d = {new Data(0), new Data(1), new Data(2)};
        list.addAll(Arrays.asList(d));

        ListIterator i = list.listIterator();
        Data d1 = new Data(5);
        assertTrue(!i.hasPrevious());
        i.add(d1);
        assertTrue(i.hasPrevious());
        assertEquals(d1, i.previous());
        assertEquals(d1, i.next());
        assertEquals(d[0], i.next());
        assertEquals(d1, list.get(0));
    }
View Full Code Here

    @Test
    public void testIteratorAddBack() throws Exception {
        Data[] d = {new Data(0), new Data(1), new Data(2)};
        list.addAll(Arrays.asList(d));

        ListIterator i = list.listIterator(list.size());
        Data d1 = new Data(5);
        assertEquals(3, list.size());
        assertTrue(i.hasPrevious());
        assertTrue(!i.hasNext());
        i.add(d1);
        assertTrue(i.hasPrevious());
        assertTrue(!i.hasNext());
        assertEquals(4, list.size());

        assertEquals(d1, i.previous());
        assertEquals(d1, i.next());
        assertEquals(d1, list.get(3));
    }
View Full Code Here

TOP

Related Classes of java.util.ListIterator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.