Search in sources :

Example 56 with Iterator

use of java.util.Iterator in project groovy-core by groovy.

the class Java2GroovyProcessor method processFiles.

public static void processFiles(List<String> fileNames) throws Exception {
    Iterator i = fileNames.iterator();
    while (i.hasNext()) {
        String filename = (String) i.next();
        File f = new File(filename);
        String text = ResourceGroovyMethods.getText(f);
        System.out.println(convert(filename, text, true, true));
    }
}
Also used : Iterator(java.util.Iterator) File(java.io.File)

Example 57 with Iterator

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

the class CollectionsTest method test_fillLjava_util_ListLjava_lang_Object.

/**
	 * @tests java.util.Collections#fill(java.util.List, java.lang.Object)
	 */
public void test_fillLjava_util_ListLjava_lang_Object() {
    // java.lang.Object)
    try {
        Collections.fill(null, new Object());
        fail("Expected NullPointerException for null list parameter");
    } catch (NullPointerException e) {
    //Expected
    }
    final int size = ll.size();
    Collections.fill(ll, "k");
    assertEquals("Fill modified list size", size, ll.size());
    Iterator i = ll.iterator();
    while (i.hasNext()) assertEquals("Failed to fill elements", "k", i.next());
    Collections.fill(ll, null);
    assertEquals("Fill with nulls modified list size", size, ll.size());
    i = ll.iterator();
    while (i.hasNext()) assertNull("Failed to fill with nulls", i.next());
}
Also used : ListIterator(java.util.ListIterator) Iterator(java.util.Iterator)

Example 58 with Iterator

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

the class CollectionsTest method test_unmodifiableSetLjava_util_Set.

/**
	 * @tests java.util.Collections#unmodifiableSet(java.util.Set)
	 */
public void test_unmodifiableSetLjava_util_Set() {
    // Test for method java.util.Set
    // java.util.Collections.unmodifiableSet(java.util.Set)
    boolean exception = false;
    Set c = Collections.unmodifiableSet(s);
    assertTrue("Returned set is of incorrect size", c.size() == s.size());
    Iterator i = ll.iterator();
    while (i.hasNext()) assertTrue("Returned set missing elements", c.contains(i.next()));
    try {
        c.add(new Object());
    } catch (UnsupportedOperationException e) {
        exception = true;
    // Correct
    }
    if (!exception) {
        fail("Allowed modification of set");
    }
    try {
        c.remove(new Object());
        fail("Allowed modification of set");
    } catch (UnsupportedOperationException e) {
    // Correct
    }
    Set mySet = Collections.unmodifiableSet(new HashSet());
    assertTrue("Should not contain null", !mySet.contains(null));
    mySet = Collections.unmodifiableSet(Collections.singleton(null));
    assertTrue("Should contain null", mySet.contains(null));
    mySet = new TreeSet();
    for (int counter = 0; counter < 100; counter++) {
        mySet.add(objArray[counter]);
    }
    new Support_UnmodifiableCollectionTest("", Collections.unmodifiableSet(mySet)).runTest();
}
Also used : SortedSet(java.util.SortedSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) TreeSet(java.util.TreeSet) Support_UnmodifiableCollectionTest(tests.support.Support_UnmodifiableCollectionTest) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) HashSet(java.util.HashSet)

Example 59 with Iterator

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

the class EnumMapTest method test_entrySet.

/**
     * @tests java.util.EnumMap#entrySet()
     */
@SuppressWarnings({ "unchecked", "boxing" })
public void test_entrySet() {
    EnumMap enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Middle, 1);
    enumSizeMap.put(Size.Big, null);
    MockEntry mockEntry = new MockEntry(Size.Middle, 1);
    Set set = enumSizeMap.entrySet();
    Set set1 = enumSizeMap.entrySet();
    //$NON-NLS-1$
    assertSame("Should be same", set1, set);
    try {
        set.add(mockEntry);
        //$NON-NLS-1$
        fail("Should throw UnsupportedOperationException");
    } catch (UnsupportedOperationException e) {
    // Expected
    }
    assertTrue("Returned false for contained object", //$NON-NLS-1$
    set.contains(mockEntry));
    mockEntry = new MockEntry(Size.Middle, null);
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(mockEntry));
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(Size.Small));
    mockEntry = new MockEntry(new Integer(1), 1);
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(mockEntry));
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(new Integer(1)));
    mockEntry = new MockEntry(Size.Big, null);
    assertTrue("Returned false for contained object", //$NON-NLS-1$
    set.contains(mockEntry));
    assertTrue("Returned false when the object can be removed", //$NON-NLS-1$
    set.remove(mockEntry));
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(mockEntry));
    assertFalse("Returned true when the object can not be removed", //$NON-NLS-1$
    set.remove(mockEntry));
    mockEntry = new MockEntry(new Integer(1), 1);
    assertFalse("Returned true when the object can not be removed", //$NON-NLS-1$
    set.remove(mockEntry));
    assertFalse("Returned true when the object can not be removed", //$NON-NLS-1$
    set.remove(new Integer(1)));
    // The set is backed by the map so changes to one are reflected by the
    // other.
    enumSizeMap.put(Size.Big, 3);
    mockEntry = new MockEntry(Size.Big, 3);
    assertTrue("Returned false for contained object", //$NON-NLS-1$
    set.contains(mockEntry));
    enumSizeMap.remove(Size.Big);
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(mockEntry));
    //$NON-NLS-1$
    assertEquals("Wrong size", 1, set.size());
    set.clear();
    //$NON-NLS-1$
    assertEquals("Wrong size", 0, set.size());
    enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Middle, 1);
    enumSizeMap.put(Size.Big, null);
    set = enumSizeMap.entrySet();
    Collection c = new ArrayList();
    c.add(new MockEntry(Size.Middle, 1));
    //$NON-NLS-1$
    assertTrue("Return wrong value", set.containsAll(c));
    //$NON-NLS-1$
    assertTrue("Remove does not success", set.removeAll(c));
    enumSizeMap.put(Size.Middle, 1);
    c.add(new MockEntry(Size.Big, 3));
    //$NON-NLS-1$
    assertTrue("Remove does not success", set.removeAll(c));
    //$NON-NLS-1$
    assertFalse("Should return false", set.removeAll(c));
    //$NON-NLS-1$
    assertEquals("Wrong size", 1, set.size());
    enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Middle, 1);
    enumSizeMap.put(Size.Big, null);
    set = enumSizeMap.entrySet();
    c = new ArrayList();
    c.add(new MockEntry(Size.Middle, 1));
    c.add(new MockEntry(Size.Big, 3));
    //$NON-NLS-1$
    assertTrue("Retain does not success", set.retainAll(c));
    //$NON-NLS-1$
    assertEquals("Wrong size", 1, set.size());
    //$NON-NLS-1$
    assertFalse("Should return false", set.retainAll(c));
    enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Middle, 1);
    enumSizeMap.put(Size.Big, null);
    set = enumSizeMap.entrySet();
    Object[] array = set.toArray();
    //$NON-NLS-1$
    assertEquals("Wrong length", 2, array.length);
    Map.Entry entry = (Map.Entry) array[0];
    //$NON-NLS-1$
    assertEquals("Wrong key", Size.Middle, entry.getKey());
    //$NON-NLS-1$
    assertEquals("Wrong value", 1, entry.getValue());
    Object[] array1 = new Object[10];
    array1 = set.toArray();
    //$NON-NLS-1$
    assertEquals("Wrong length", 2, array1.length);
    entry = (Map.Entry) array[0];
    //$NON-NLS-1$
    assertEquals("Wrong key", Size.Middle, entry.getKey());
    //$NON-NLS-1$
    assertEquals("Wrong value", 1, entry.getValue());
    array1 = new Object[10];
    array1 = set.toArray(array1);
    //$NON-NLS-1$
    assertEquals("Wrong length", 10, array1.length);
    entry = (Map.Entry) array[1];
    //$NON-NLS-1$
    assertEquals("Wrong key", Size.Big, entry.getKey());
    //$NON-NLS-1$
    assertNull("Should be null", array1[2]);
    set = enumSizeMap.entrySet();
    //$NON-NLS-1$
    Integer integer = new Integer("1");
    assertFalse("Returned true when the object can not be removed", //$NON-NLS-1$
    set.remove(integer));
    assertTrue("Returned false when the object can be removed", //$NON-NLS-1$
    set.remove(entry));
    enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Middle, 1);
    enumSizeMap.put(Size.Big, null);
    set = enumSizeMap.entrySet();
    Iterator iter = set.iterator();
    entry = (Map.Entry) iter.next();
    //$NON-NLS-1$
    assertTrue("Returned false for contained object", set.contains(entry));
    mockEntry = new MockEntry(Size.Middle, 2);
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(mockEntry));
    mockEntry = new MockEntry(new Integer(2), 2);
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(mockEntry));
    entry = (Map.Entry) iter.next();
    //$NON-NLS-1$
    assertTrue("Returned false for contained object", set.contains(entry));
    enumSizeMap.put(Size.Middle, 1);
    enumSizeMap.remove(Size.Big);
    mockEntry = new MockEntry(Size.Big, null);
    //$NON-NLS-1$
    assertEquals("Wrong size", 1, set.size());
    //$NON-NLS-1$
    assertFalse("Returned true for uncontained object", set.contains(mockEntry));
    enumSizeMap.put(Size.Big, 2);
    mockEntry = new MockEntry(Size.Big, 2);
    assertTrue("Returned false for contained object", //$NON-NLS-1$
    set.contains(mockEntry));
    iter.remove();
    try {
        iter.remove();
        //$NON-NLS-1$
        fail("Should throw IllegalStateException");
    } catch (IllegalStateException e) {
    // Expected
    }
    try {
        entry.setValue(2);
        //$NON-NLS-1$
        fail("Should throw IllegalStateException");
    } catch (IllegalStateException e) {
    // Expected
    }
    try {
        set.contains(entry);
        //$NON-NLS-1$
        fail("Should throw IllegalStateException");
    } catch (IllegalStateException e) {
    // Expected
    }
    enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Middle, 1);
    enumSizeMap.put(Size.Big, null);
    set = enumSizeMap.entrySet();
    iter = set.iterator();
    entry = (Map.Entry) iter.next();
    //$NON-NLS-1$
    assertEquals("Wrong key", Size.Middle, entry.getKey());
    //$NON-NLS-1$
    assertTrue("Returned false for contained object", set.contains(entry));
    enumSizeMap.put(Size.Middle, 3);
    //$NON-NLS-1$
    assertTrue("Returned false for contained object", set.contains(entry));
    entry.setValue(2);
    //$NON-NLS-1$
    assertTrue("Returned false for contained object", set.contains(entry));
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.remove(new Integer(1)));
    iter.next();
    //The following test case fails on RI.
    //$NON-NLS-1$
    assertEquals("Wrong key", Size.Middle, entry.getKey());
    set.clear();
    //$NON-NLS-1$
    assertEquals("Wrong size", 0, set.size());
    enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Middle, 1);
    enumSizeMap.put(Size.Big, null);
    set = enumSizeMap.entrySet();
    iter = set.iterator();
    mockEntry = new MockEntry(Size.Middle, 1);
    //$NON-NLS-1$
    assertFalse("Wrong result", entry.equals(mockEntry));
    try {
        iter.remove();
        //$NON-NLS-1$
        fail("Should throw IllegalStateException");
    } catch (IllegalStateException e) {
    // Expected
    }
    entry = (Map.Entry) iter.next();
    //$NON-NLS-1$
    assertEquals("Wrong key", Size.Middle, entry.getKey());
    //$NON-NLS-1$
    assertTrue("Should return true", entry.equals(mockEntry));
    //$NON-NLS-1$
    assertEquals("Should be equal", mockEntry.hashCode(), entry.hashCode());
    mockEntry = new MockEntry(Size.Big, 1);
    //$NON-NLS-1$
    assertFalse("Wrong result", entry.equals(mockEntry));
    entry = (Map.Entry) iter.next();
    //$NON-NLS-1$
    assertFalse("Wrong result", entry.equals(mockEntry));
    //$NON-NLS-1$
    assertEquals("Wrong key", Size.Big, entry.getKey());
    iter.remove();
    //$NON-NLS-1$
    assertFalse("Wrong result", entry.equals(mockEntry));
    //$NON-NLS-1$
    assertEquals("Wrong size", 1, set.size());
    try {
        iter.remove();
        //$NON-NLS-1$
        fail("Should throw IllegalStateException");
    } catch (IllegalStateException e) {
    // Expected
    }
    try {
        iter.next();
        //$NON-NLS-1$
        fail("Should throw NoSuchElementException");
    } catch (NoSuchElementException e) {
    // Expected
    }
}
Also used : Set(java.util.Set) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Collection(java.util.Collection) EnumMap(java.util.EnumMap) EnumMap(java.util.EnumMap) Map(java.util.Map) HashMap(java.util.HashMap) NoSuchElementException(java.util.NoSuchElementException)

Example 60 with Iterator

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

the class EnumMapTest method test_keySet.

/**
     * @tests java.util.EnumMap#keySet()
     */
@SuppressWarnings({ "unchecked", "boxing" })
public void test_keySet() {
    EnumMap enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Middle, 2);
    enumSizeMap.put(Size.Big, null);
    Set set = enumSizeMap.keySet();
    Set set1 = enumSizeMap.keySet();
    //$NON-NLS-1$
    assertSame("Should be same", set1, set);
    try {
        set.add(Size.Big);
        //$NON-NLS-1$
        fail("Should throw UnsupportedOperationException");
    } catch (UnsupportedOperationException e) {
    // Expected
    }
    assertTrue("Returned false for contained object", //$NON-NLS-1$
    set.contains(Size.Middle));
    assertTrue("Returned false for contained object", //$NON-NLS-1$
    set.contains(Size.Big));
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(Size.Small));
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(new Integer(1)));
    assertTrue("Returned false when the object can be removed", //$NON-NLS-1$
    set.remove(Size.Big));
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(Size.Big));
    assertFalse("Returned true when the object can not be removed", //$NON-NLS-1$
    set.remove(Size.Big));
    assertFalse("Returned true when the object can not be removed", //$NON-NLS-1$
    set.remove(new Integer(1)));
    // The set is backed by the map so changes to one are reflected by the
    // other.
    enumSizeMap.put(Size.Big, 3);
    assertTrue("Returned false for contained object", //$NON-NLS-1$
    set.contains(Size.Big));
    enumSizeMap.remove(Size.Big);
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(Size.Big));
    //$NON-NLS-1$
    assertEquals("Wrong size", 1, set.size());
    set.clear();
    //$NON-NLS-1$
    assertEquals("Wrong size", 0, set.size());
    enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Middle, 1);
    enumSizeMap.put(Size.Big, null);
    set = enumSizeMap.keySet();
    Collection c = new ArrayList();
    c.add(Size.Big);
    //$NON-NLS-1$
    assertTrue("Should return true", set.containsAll(c));
    c.add(Size.Small);
    //$NON-NLS-1$
    assertFalse("Should return false", set.containsAll(c));
    //$NON-NLS-1$
    assertTrue("Should return true", set.removeAll(c));
    //$NON-NLS-1$
    assertEquals("Wrong size", 1, set.size());
    //$NON-NLS-1$
    assertFalse("Should return false", set.removeAll(c));
    //$NON-NLS-1$
    assertEquals("Wrong size", 1, set.size());
    try {
        set.addAll(c);
        //$NON-NLS-1$
        fail("Should throw UnsupportedOperationException");
    } catch (UnsupportedOperationException e) {
    // Expected
    }
    enumSizeMap.put(Size.Big, null);
    //$NON-NLS-1$
    assertEquals("Wrong size", 2, set.size());
    //$NON-NLS-1$
    assertTrue("Should return true", set.retainAll(c));
    //$NON-NLS-1$
    assertEquals("Wrong size", 1, set.size());
    //$NON-NLS-1$
    assertFalse("Should return false", set.retainAll(c));
    assertEquals(1, set.size());
    Object[] array = set.toArray();
    //$NON-NLS-1$
    assertEquals("Wrong length", 1, array.length);
    //$NON-NLS-1$
    assertEquals("Wrong key", Size.Big, array[0]);
    enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Middle, 1);
    enumSizeMap.put(Size.Big, null);
    set = enumSizeMap.keySet();
    c = new ArrayList();
    c.add(Color.Blue);
    //$NON-NLS-1$
    assertFalse("Should return false", set.remove(c));
    //$NON-NLS-1$
    assertEquals("Wrong size", 2, set.size());
    //$NON-NLS-1$
    assertTrue("Should return true", set.retainAll(c));
    //$NON-NLS-1$
    assertEquals("Wrong size", 0, set.size());
    enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Middle, 1);
    enumSizeMap.put(Size.Big, null);
    set = enumSizeMap.keySet();
    Iterator iter = set.iterator();
    Enum enumKey = (Enum) iter.next();
    //$NON-NLS-1$
    assertTrue("Returned false for contained object", set.contains(enumKey));
    enumKey = (Enum) iter.next();
    //$NON-NLS-1$
    assertTrue("Returned false for contained object", set.contains(enumKey));
    enumSizeMap.remove(Size.Big);
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(enumKey));
    iter.remove();
    try {
        iter.remove();
        //$NON-NLS-1$
        fail("Should throw IllegalStateException");
    } catch (IllegalStateException e) {
    // Expected
    }
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(enumKey));
    iter = set.iterator();
    enumKey = (Enum) iter.next();
    //$NON-NLS-1$
    assertTrue("Returned false for contained object", set.contains(enumKey));
    enumSizeMap.put(Size.Middle, 3);
    //$NON-NLS-1$
    assertTrue("Returned false for contained object", set.contains(enumKey));
    enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Middle, 1);
    enumSizeMap.put(Size.Big, null);
    set = enumSizeMap.keySet();
    iter = set.iterator();
    try {
        iter.remove();
        //$NON-NLS-1$
        fail("Should throw IllegalStateException");
    } catch (IllegalStateException e) {
    // Expected
    }
    enumKey = (Enum) iter.next();
    //$NON-NLS-1$
    assertEquals("Wrong key", Size.Middle, enumKey);
    //$NON-NLS-1$
    assertSame("Wrong key", Size.Middle, enumKey);
    //$NON-NLS-1$
    assertFalse("Returned true for unequal object", iter.equals(enumKey));
    iter.remove();
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(enumKey));
    try {
        iter.remove();
        //$NON-NLS-1$
        fail("Should throw IllegalStateException");
    } catch (IllegalStateException e) {
    // Expected
    }
    //$NON-NLS-1$
    assertEquals("Wrong size", 1, set.size());
    enumKey = (Enum) iter.next();
    //$NON-NLS-1$
    assertEquals("Wrong key", Size.Big, enumKey);
    iter.remove();
    try {
        iter.next();
        //$NON-NLS-1$
        fail("Should throw NoSuchElementException");
    } catch (NoSuchElementException e) {
    // Expected
    }
}
Also used : Set(java.util.Set) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Collection(java.util.Collection) EnumMap(java.util.EnumMap) NoSuchElementException(java.util.NoSuchElementException)

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