Search in sources :

Example 6 with AbstractList

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

the class ConcurrentModTest method testAdd.

/*
     * Test method for 'java.util.AbstractList.subList(int, int)'
     */
public void testAdd() {
    AbstractList al = new ArrayList();
    Double one = new Double(1.0);
    Double two = new Double(2.0);
    Double three = new Double(3.0);
    Double four = new Double(4.0);
    al.add(one);
    al.add(two);
    al.add(three);
    al.add(four);
    List sub = al.subList(1, 3);
    assertEquals(2, sub.size());
    // the sub.get(1) is 3.0
    assertTrue(((Double) sub.get(1)).doubleValue() <= 3.0);
    assertTrue(((Double) sub.get(1)).doubleValue() > 2.0);
    // remove the 2.0
    al.remove(1);
    try {
        // illegal call the subList's method Add(int,Object).
        sub.add(1, two);
        fail("It should throws ConcurrentModificationException.");
    } catch (ConcurrentModificationException e) {
        return;
    }
}
Also used : AbstractList(java.util.AbstractList) ConcurrentModificationException(java.util.ConcurrentModificationException) ArrayList(java.util.ArrayList) List(java.util.List) AbstractList(java.util.AbstractList) ArrayList(java.util.ArrayList)

Example 7 with AbstractList

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

the class AbstractListTest method test_listIteratorI.

public void test_listIteratorI() {
    AbstractList al1 = new ArrayList();
    AbstractList al2 = new ArrayList();
    al1.add(0);
    al1.add(1);
    al1.add(2);
    al1.add(3);
    al1.add(4);
    al2.add(2);
    al2.add(3);
    al2.add(4);
    Iterator li1 = al1.listIterator(2);
    Iterator li2 = al2.listIterator();
    while (li1.hasNext() && li2.hasNext()) {
        assertEquals(li1.next(), li2.next());
    }
    assertSame(li1.hasNext(), li2.hasNext());
    try {
        al1.listIterator(-1);
        fail("IndexOutOfBoundsException expected");
    } catch (IndexOutOfBoundsException ee) {
    //expected
    }
    try {
        al1.listIterator(al1.size() + 1);
        fail("IndexOutOfBoundsException expected");
    } catch (IndexOutOfBoundsException ee) {
    //expected
    }
}
Also used : AbstractList(java.util.AbstractList) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ListIterator(java.util.ListIterator)

Example 8 with AbstractList

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

the class AbstractListTest method test_indexOfLjava_lang_Object.

public void test_indexOfLjava_lang_Object() {
    AbstractList al = new ArrayList();
    al.add(0);
    al.add(1);
    al.add(2);
    al.add(3);
    al.add(4);
    assertEquals(-1, al.indexOf(5));
    assertEquals(2, al.indexOf(2));
}
Also used : AbstractList(java.util.AbstractList) ArrayList(java.util.ArrayList)

Example 9 with AbstractList

use of java.util.AbstractList 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 10 with AbstractList

use of java.util.AbstractList in project xtext-xtend by eclipse.

the class GetSuperTypeBenchmark method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    typeReference = getTypeReference(type);
    TypeReferences typeReferences = typeReference.getOwner().getServices().getTypeReferences();
    abstractCollection = typeReferences.findDeclaredType(AbstractCollection.class, typeReference.getType());
    abstractList = typeReferences.findDeclaredType(AbstractList.class, typeReference.getType());
    collection = typeReferences.findDeclaredType(Collection.class, typeReference.getType());
    iterable = typeReferences.findDeclaredType(Iterable.class, typeReference.getType());
    list = typeReferences.findDeclaredType(List.class, typeReference.getType());
    object = typeReferences.findDeclaredType(Object.class, typeReference.getType());
    set = typeReferences.findDeclaredType(Set.class, typeReference.getType());
    stringBuilder = typeReferences.findDeclaredType(StringBuilder.class, typeReference.getType());
    EcoreUtil.resolveAll(typeReference.getOwner().getContextResourceSet());
}
Also used : AbstractList(java.util.AbstractList) Set(java.util.Set) TypeReferences(org.eclipse.xtext.common.types.util.TypeReferences) AbstractCollection(java.util.AbstractCollection) AbstractCollection(java.util.AbstractCollection) Collection(java.util.Collection) List(java.util.List) AbstractList(java.util.AbstractList)

Aggregations

AbstractList (java.util.AbstractList)26 ArrayList (java.util.ArrayList)19 List (java.util.List)10 Collection (java.util.Collection)6 ConcurrentModificationException (java.util.ConcurrentModificationException)5 Vector (java.util.Vector)4 ListIterator (java.util.ListIterator)3 Set (java.util.Set)3 IOException (java.io.IOException)2 Collections (java.util.Collections)2 LinkedList (java.util.LinkedList)2 RandomAccess (java.util.RandomAccess)2 Collectors (java.util.stream.Collectors)2 Query (org.apache.lucene.search.Query)2 Test (org.junit.Test)2 JsArrayString (com.google.gwt.core.client.JsArrayString)1 TestingLoader (dagger.internal.TestingLoader)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 Array (java.lang.reflect.Array)1