Search in sources :

Example 76 with Iterator

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

the class NumberRangeTest method testStepByOneWithClosure.

/**
     * Tests stepping through a range with a closure.
     */
public void testStepByOneWithClosure() {
    final List callLog = new ArrayList();
    final Closure closure = new RecordingClosure(callLog);
    final Range range = createRange(1, 5);
    range.step(1, closure);
    assertEquals("wrong number of calls to closure", 5, callLog.size());
    final Iterator iter = callLog.iterator();
    for (int i = 1; i <= 5; i++) {
        assertEquals("wrong argument passed to closure", createValue(i), iter.next());
    }
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList)

Example 77 with Iterator

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

the class NumberRangeTest method testRemoveFromIterator.

/**
     * Tests removing an element from the range using an iterator (not supported).
     */
public void testRemoveFromIterator() {
    final Range range = createRange(1, 5);
    try {
        final Iterator iter = range.iterator();
        iter.remove();
        fail("successfully removed an element using an iterator");
    } catch (UnsupportedOperationException e) {
        assertTrue("expected exception thrown", true);
    }
}
Also used : Iterator(java.util.Iterator)

Example 78 with Iterator

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

the class NumberRangeTest method testStepByTwoWithClosure.

/**
     * Tests stepping through a range by two with a closure.
     */
public void testStepByTwoWithClosure() {
    final List callLog = new ArrayList();
    final Closure closure = new RecordingClosure(callLog);
    final Range range = createRange(0, 4);
    range.step(2, closure);
    assertEquals("wrong number of calls to closure", 3, callLog.size());
    final Iterator iter = callLog.iterator();
    for (int i = 0; i <= 4; i += 2) {
        assertEquals("wrong argument passed to closure", createValue(i), iter.next());
    }
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList)

Example 79 with Iterator

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

the class NumberRangeTest method testNegativeReverseStepByOneWithClosure.

/**
     * Tests stepping backwards through a reversed range with a closure.
     */
public void testNegativeReverseStepByOneWithClosure() {
    final List callLog = new ArrayList();
    final Closure closure = new RecordingClosure(callLog);
    final Range range = createRange(5, 1);
    range.step(-1, closure);
    assertEquals("wrong number of calls to closure", 5, callLog.size());
    final Iterator iter = callLog.iterator();
    for (int i = 1; i <= 5; i++) {
        assertEquals("wrong argument passed to closure", createValue(i), iter.next());
    }
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList)

Example 80 with Iterator

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

the class NumberRangeTest method testStepByOne.

/**
     * Tests stepping through a range by one.
     */
public void testStepByOne() {
    final Range range = createRange(1, 5);
    final List result = range.step(1);
    assertEquals("wrong number of calls", 5, result.size());
    final Iterator iter = result.iterator();
    for (int i = 1; i <= 5; i++) {
        assertEquals("incorrect value in result", createValue(i), iter.next());
    }
}
Also used : Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList)

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