Search in sources :

Example 61 with Iterator

use of java.util.Iterator in project j2objc by google.

the class LinkedListTest method test_toArray$Ljava_lang_Object.

/**
	 * @tests java.util.LinkedList#toArray(java.lang.Object[])
	 */
public void test_toArray$Ljava_lang_Object() {
    // Test for method java.lang.Object []
    // java.util.LinkedList.toArray(java.lang.Object [])
    Integer[] argArray = new Integer[100];
    Object[] retArray;
    retArray = ll.toArray(argArray);
    assertTrue("Returned different array than passed", retArray == argArray);
    List retList = new LinkedList(Arrays.asList(retArray));
    Iterator li = ll.iterator();
    Iterator ri = retList.iterator();
    while (li.hasNext()) assertTrue("Lists are not equal", li.next() == ri.next());
    argArray = new Integer[1000];
    retArray = ll.toArray(argArray);
    assertNull("Failed to set first extra element to null", argArray[ll.size()]);
    for (int i = 0; i < ll.size(); i++) assertTrue("Returned incorrect array: " + i, retArray[i] == objArray[i]);
    ll.add(50, null);
    argArray = new Integer[101];
    retArray = ll.toArray(argArray);
    assertTrue("Returned different array than passed", retArray == argArray);
    retArray = ll.toArray(argArray);
    assertTrue("Returned different array than passed", retArray == argArray);
    retList = new LinkedList(Arrays.asList(retArray));
    li = ll.iterator();
    ri = retList.iterator();
    while (li.hasNext()) assertTrue("Lists are not equal", li.next() == ri.next());
}
Also used : Iterator(java.util.Iterator) ListIterator(java.util.ListIterator) List(java.util.List) LinkedList(java.util.LinkedList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Example 62 with Iterator

use of java.util.Iterator in project j2objc by google.

the class HashSetTest method test_clear.

/**
	 * @tests java.util.HashSet#clear()
	 */
public void test_clear() {
    // Test for method void java.util.HashSet.clear()
    Set orgSet = (Set) hs.clone();
    hs.clear();
    Iterator i = orgSet.iterator();
    assertEquals("Returned non-zero size after clear", 0, hs.size());
    while (i.hasNext()) assertTrue("Failed to clear set", !hs.contains(i.next()));
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Iterator(java.util.Iterator)

Example 63 with Iterator

use of java.util.Iterator in project j2objc by google.

the class CollectionsTest method test_reverseLjava_util_List.

/**
	 * @tests java.util.Collections#reverse(java.util.List)
	 */
public void test_reverseLjava_util_List() {
    // Test for method void java.util.Collections.reverse(java.util.List)
    try {
        Collections.reverse(null);
        fail("Expected NullPointerException for null list parameter");
    } catch (NullPointerException e) {
    //Expected
    }
    Collections.reverse(ll);
    Iterator i = ll.iterator();
    int count = objArray.length - 1;
    while (i.hasNext()) {
        assertEquals("Failed to reverse collection", objArray[count], i.next());
        --count;
    }
    ArrayList myList = new ArrayList();
    myList.add(null);
    myList.add(new Integer(20));
    Collections.reverse(myList);
    assertEquals("Did not reverse correctly--first element is: " + myList.get(0), new Integer(20), myList.get(0));
    assertNull("Did not reverse correctly--second element is: " + myList.get(1), myList.get(1));
}
Also used : ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList)

Example 64 with Iterator

use of java.util.Iterator in project j2objc by google.

the class CollectionsTest method test_unmodifiableSortedMapLjava_util_SortedMap.

/**
	 * @tests java.util.Collections#unmodifiableSortedMap(java.util.SortedMap)
	 */
public void test_unmodifiableSortedMapLjava_util_SortedMap() {
    // Test for method java.util.SortedMap
    // java.util.Collections.unmodifiableSortedMap(java.util.SortedMap)
    boolean exception = false;
    TreeMap tm = new TreeMap();
    tm.putAll(hm);
    Map c = Collections.unmodifiableSortedMap(tm);
    assertTrue("Returned map is of incorrect size", c.size() == tm.size());
    Iterator i = hm.keySet().iterator();
    while (i.hasNext()) {
        Object x = i.next();
        assertTrue("Returned map missing elements", c.get(x).equals(tm.get(x)));
    }
    try {
        c.put(new Object(), "");
    } catch (UnsupportedOperationException e) {
        exception = true;
    // Correct
    }
    if (!exception) {
        fail("Allowed modification of map");
    }
    try {
        c.remove(new Object());
    } catch (UnsupportedOperationException e) {
        // Correct
        return;
    }
    fail("Allowed modification of map");
}
Also used : ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 65 with Iterator

use of java.util.Iterator in project j2objc by google.

the class LinkedHashSetTest method test_iterator.

/**
	 * @tests java.util.LinkedHashSet#iterator()
	 */
public void test_iterator() {
    // Test for method java.util.Iterator java.util.LinkedHashSet.iterator()
    Iterator i = hs.iterator();
    int x = 0;
    int j;
    for (j = 0; i.hasNext(); j++) {
        Object oo = i.next();
        if (oo != null) {
            Integer ii = (Integer) oo;
            assertTrue("Incorrect element found", ii.intValue() == j);
        } else {
            assertTrue("Cannot find null", hs.contains(oo));
        }
        ++x;
    }
    assertTrue("Returned iteration of incorrect size", hs.size() == x);
    LinkedHashSet s = new LinkedHashSet();
    s.add(null);
    assertNull("Cannot handle null", s.iterator().next());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Iterator(java.util.Iterator)

Aggregations

Iterator (java.util.Iterator)8930 ArrayList (java.util.ArrayList)2267 Set (java.util.Set)1895 HashMap (java.util.HashMap)1828 Map (java.util.Map)1714 List (java.util.List)1622 HashSet (java.util.HashSet)1602 Test (org.junit.Test)624 IOException (java.io.IOException)524 Collection (java.util.Collection)377 Region (org.apache.geode.cache.Region)240 SSOException (com.iplanet.sso.SSOException)227 File (java.io.File)216 LinkedList (java.util.LinkedList)213 TreeSet (java.util.TreeSet)191 LinkedHashMap (java.util.LinkedHashMap)181 Entry (java.util.Map.Entry)174 SMSException (com.sun.identity.sm.SMSException)169 ListIterator (java.util.ListIterator)146 TreeMap (java.util.TreeMap)145