Search in sources :

Example 11 with ListIterator

use of java.util.ListIterator in project robovm by robovm.

the class AbstractListTest method test_subListII.

/**
     * java.util.AbstractList#subList(int, int)
     */
public void test_subListII() {
    // Test each of the SubList operations to ensure a
    // ConcurrentModificationException does not occur on an AbstractList
    // which does not update modCount
    SimpleList mList = new SimpleList();
    mList.add(new Object());
    mList.add(new Object());
    List sList = mList.subList(0, 2);
    // calls add(int, Object)
    sList.add(new Object());
    sList.get(0);
    sList.add(0, new Object());
    sList.get(0);
    sList.addAll(Arrays.asList(new String[] { "1", "2" }));
    sList.get(0);
    sList.addAll(0, Arrays.asList(new String[] { "3", "4" }));
    sList.get(0);
    sList.remove(0);
    sList.get(0);
    ListIterator lit = sList.listIterator();
    lit.add(new Object());
    lit.next();
    lit.remove();
    lit.next();
    // calls removeRange()
    sList.clear();
    sList.add(new Object());
    // test the type of sublist that is returned
    List al = new ArrayList();
    for (int i = 0; i < 10; i++) {
        al.add(new Integer(i));
    }
    assertTrue("Sublist returned should have implemented Random Access interface", al.subList(3, 7) instanceof RandomAccess);
    List ll = new LinkedList();
    for (int i = 0; i < 10; i++) {
        ll.add(new Integer(i));
    }
    assertTrue("Sublist returned should not have implemented Random Access interface", !(ll.subList(3, 7) instanceof RandomAccess));
}
Also used : ArrayList(java.util.ArrayList) RandomAccess(java.util.RandomAccess) List(java.util.List) AbstractList(java.util.AbstractList) LinkedList(java.util.LinkedList) ArrayList(java.util.ArrayList) ListIterator(java.util.ListIterator) LinkedList(java.util.LinkedList)

Example 12 with ListIterator

use of java.util.ListIterator in project robovm by robovm.

the class AbstractSequentialListTest method test_addILjava_lang_Object.

public void test_addILjava_lang_Object() {
    AbstractSequentialList asl = new AbstractSequentialList() {

        @Override
        public int size() {
            return 0;
        }

        @Override
        public ListIterator listIterator(int index) {
            return new Mock_unsupportedListIterator();
        }
    };
    try {
        asl.add(0, 1);
        fail("UnsupportedOperationException expected");
    } catch (UnsupportedOperationException e) {
    //expected
    }
    asl = new AbstractSequentialList() {

        @Override
        public int size() {
            return 0;
        }

        @Override
        public ListIterator listIterator(int index) {
            return new Mock_ListIterator();
        }
    };
    try {
        asl.add(0, "String");
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException ee) {
    //expected
    }
    try {
        asl.add(0, null);
        fail("NullPointerException expected");
    } catch (NullPointerException ee) {
    //expected
    }
    //ClassCastException can not be checked for this method.
    asl.add(0, 1);
    asl = new LinkedList();
    try {
        asl.add(-1, 1);
        fail("IndexOutOfBoundsException expected");
    } catch (IndexOutOfBoundsException ee) {
    //expected
    }
    asl.add(0, 1);
    try {
        asl.add(2, 1);
        fail("IndexOutOfBoundsException expected");
    } catch (IndexOutOfBoundsException ee) {
    //expected
    }
}
Also used : ListIterator(java.util.ListIterator) LinkedList(java.util.LinkedList) AbstractSequentialList(java.util.AbstractSequentialList)

Example 13 with ListIterator

use of java.util.ListIterator in project robovm by robovm.

the class AbstractSequentialListTest method test_iterrator.

public void test_iterrator() {
    AbstractSequentialList asl = new AbstractSequentialList() {

        @Override
        public int size() {
            return 0;
        }

        @Override
        public ListIterator listIterator(int index) {
            return new Mock_unsupportedListIterator();
        }
    };
    assertTrue(asl.iterator().getClass().toString().contains("Mock_unsupportedListIterator"));
    asl = new AbstractSequentialList() {

        @Override
        public int size() {
            return 0;
        }

        @Override
        public ListIterator listIterator(int index) {
            return new Mock_ListIterator();
        }
    };
    assertTrue(asl.iterator().getClass().toString().contains("Mock_ListIterator"));
    asl = new AbstractSequentialList() {

        @Override
        public int size() {
            return 0;
        }

        @Override
        public ListIterator listIterator(int index) {
            return null;
        }
    };
    assertNull(asl.iterator());
}
Also used : ListIterator(java.util.ListIterator) AbstractSequentialList(java.util.AbstractSequentialList)

Example 14 with ListIterator

use of java.util.ListIterator in project robovm by robovm.

the class AbstractSequentialListTest method test_addAllILjava_util_Collection.

public void test_addAllILjava_util_Collection() {
    AbstractSequentialList asl = new AbstractSequentialList() {

        @Override
        public int size() {
            return 0;
        }

        @Override
        public ListIterator listIterator(int index) {
            return new Mock_unsupportedListIterator();
        }
    };
    Collection strV = new Vector<String>();
    strV.add("String");
    strV.add("1");
    strV.add("3.14");
    try {
        asl.addAll(0, strV);
        fail("UnsupportedOperationException expected.");
    } catch (UnsupportedOperationException ee) {
    //expected
    }
    try {
        asl.addAll(0, null);
        fail("NullPointerException expected");
    } catch (NullPointerException ee) {
    //expected
    }
    //ClassCastException can not be checked for this method.
    asl = new AbstractSequentialList() {

        @Override
        public int size() {
            return 0;
        }

        @Override
        public ListIterator listIterator(int index) {
            return new Mock_ListIterator();
        }
    };
    try {
        asl.addAll(0, strV);
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
    //expected
    }
    strV.remove("String");
    strV.add(null);
    try {
        asl.addAll(0, strV);
        fail("NullPointerException expected");
    } catch (NullPointerException e) {
    //expected
    }
    strV.remove(null);
    asl.addAll(0, strV);
    asl = new LinkedList();
    try {
        asl.addAll(-10, strV);
        fail("IndexOutOfBoundsException expected");
    } catch (IndexOutOfBoundsException e) {
    //expected
    }
    try {
        asl.addAll(1, strV);
        fail("IndexOutOfBoundsException expected");
    } catch (IndexOutOfBoundsException e) {
    //expected
    }
}
Also used : ListIterator(java.util.ListIterator) LinkedList(java.util.LinkedList) AbstractSequentialList(java.util.AbstractSequentialList) Collection(java.util.Collection) Vector(java.util.Vector)

Example 15 with ListIterator

use of java.util.ListIterator in project robovm by robovm.

the class AbstractSequentialListTest method test_removeI.

public void test_removeI() {
    AbstractSequentialList asl = new AbstractSequentialList() {

        String[] buff = { "0", "1", "2", "3", "4", "5" };

        int currPos = 0;

        @Override
        public int size() {
            return buff.length;
        }

        @Override
        public ListIterator listIterator(int index) {
            currPos = index;
            return new ListIterator() {

                public void add(Object o) {
                }

                public boolean hasNext() {
                    return true;
                }

                public boolean hasPrevious() {
                    return false;
                }

                public Object next() {
                    return buff[currPos];
                }

                public int nextIndex() {
                    return 0;
                }

                public Object previous() {
                    return null;
                }

                public int previousIndex() {
                    return 0;
                }

                public void remove() {
                    buff[currPos] = "removed element";
                }

                public void set(Object o) {
                }
            };
        }
    };
    try {
        asl.remove(asl.size() + 1);
        fail("IndexOutOfBoundsException expected");
    } catch (IndexOutOfBoundsException e) {
    //expected
    }
    try {
        asl.remove(-1);
        fail("IndexOutOfBoundsException expected");
    } catch (IndexOutOfBoundsException e) {
    //expected
    }
    for (int i = 0; i < asl.size(); i++) {
        assertFalse(asl.get(i).toString().contains("removed element"));
        asl.remove(i);
        assertTrue(asl.get(i).toString().contains("removed element"));
    }
}
Also used : ListIterator(java.util.ListIterator) AbstractSequentialList(java.util.AbstractSequentialList)

Aggregations

ListIterator (java.util.ListIterator)81 List (java.util.List)30 ArrayList (java.util.ArrayList)29 LinkedList (java.util.LinkedList)26 Iterator (java.util.Iterator)15 AbstractList (java.util.AbstractList)7 AbstractSequentialList (java.util.AbstractSequentialList)6 RandomAccess (java.util.RandomAccess)5 SelectResults (org.apache.geode.cache.query.SelectResults)5 Test (org.junit.Test)5 Map (java.util.Map)4 NoSuchElementException (java.util.NoSuchElementException)4 SipURI (javax.sip.address.SipURI)4 StructTypeImpl (org.apache.geode.cache.query.internal.types.StructTypeImpl)4 File (java.io.File)3 IOException (java.io.IOException)3 SipException (javax.sip.SipException)3 ObjectType (org.apache.geode.cache.query.types.ObjectType)3 StructType (org.apache.geode.cache.query.types.StructType)3 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)2