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));
}
}
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());
}
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();
}
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
}
}
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
}
}
Aggregations