use of java.util.Iterator in project groovy-core by groovy.
the class NumberRangeTest method testReverseStepByOneWithClosure.
/**
* Tests stepping through a reversed range by one with a closure.
*/
public void testReverseStepByOneWithClosure() {
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 = 5; i >= 1; i--) {
assertEquals("wrong argument passed to closure", createValue(i), iter.next());
}
}
use of java.util.Iterator in project groovy-core by groovy.
the class RangeTest method testIterator.
public void testIterator() {
Range r = createRange(5, 11);
int i = 5;
for (Iterator it = r.iterator(); it.hasNext(); ) {
assertEquals("equals to " + i, new Integer(i), (Integer) (it.next()));
i++;
}
r = createRange(new BigDecimal("5.0"), new BigDecimal("11.0"));
BigDecimal one = new BigDecimal("1.0");
BigDecimal val = new BigDecimal("5.0");
for (Iterator it = r.iterator(); it.hasNext(); ) {
assertEquals("equals to " + val, val, (BigDecimal) (it.next()));
val = val.add(one);
}
}
use of java.util.Iterator in project groovy-core by groovy.
the class AntProjectPropertiesDelegate method putAll.
public synchronized void putAll(Map t) {
Set keySet = t.keySet();
for (Iterator iterator = keySet.iterator(); iterator.hasNext(); ) {
Object key = iterator.next();
Object value = t.get(key);
put(key, value);
}
}
use of java.util.Iterator in project groovy-core by groovy.
the class SpoofTaskContainer method execute.
public void execute() throws BuildException {
spoof("begin SpoofTaskContainer execute");
for (Iterator iter = tasks.iterator(); iter.hasNext(); ) {
Task task = (Task) iter.next();
task.perform();
}
spoof("end SpoofTaskContainer execute");
}
use of java.util.Iterator in project groovy-core by groovy.
the class TupleListTest method testIterateOverList.
public void testIterateOverList() throws Exception {
StringBuilder buffer = new StringBuilder();
for (Iterator iter = InvokerHelper.asIterator(InvokerHelper.createList(new Object[] { "a", "b", "c" })); iter.hasNext(); ) {
Object i = iter.next();
buffer.append(i);
}
assertEquals("buffer", "abc", buffer.toString());
}
Aggregations