use of java.util.Iterator in project groovy-core by groovy.
the class StatementWriter method writeSwitch.
public void writeSwitch(SwitchStatement statement) {
controller.getAcg().onLineNumber(statement, "visitSwitch");
writeStatementLabel(statement);
statement.getExpression().visit(controller.getAcg());
// switch does not have a continue label. use its parent's for continue
Label breakLabel = controller.getCompileStack().pushSwitch();
int switchVariableIndex = controller.getCompileStack().defineTemporaryVariable("switch", true);
List caseStatements = statement.getCaseStatements();
int caseCount = caseStatements.size();
Label[] labels = new Label[caseCount + 1];
for (int i = 0; i < caseCount; i++) {
labels[i] = new Label();
}
int i = 0;
for (Iterator iter = caseStatements.iterator(); iter.hasNext(); i++) {
CaseStatement caseStatement = (CaseStatement) iter.next();
writeCaseStatement(caseStatement, switchVariableIndex, labels[i], labels[i + 1]);
}
statement.getDefaultStatement().visit(controller.getAcg());
controller.getMethodVisitor().visitLabel(breakLabel);
controller.getCompileStack().pop();
}
use of java.util.Iterator in project groovy-core by groovy.
the class Janitor method cleanup.
public void cleanup() {
Iterator iterator = pending.iterator();
while (iterator.hasNext()) {
HasCleanup object = (HasCleanup) iterator.next();
try {
object.cleanup();
} catch (Exception e) {
// Ignore
}
}
pending.clear();
}
use of java.util.Iterator in project groovy-core by groovy.
the class CharacterRangeTest method testIterate.
/**
* Tests iterating through the range.
*/
public void testIterate() {
Iterator iter = range.iterator();
assertEquals(FROM, iter.next());
for (char expected = (char) (FROM.charValue() + 1); expected <= TO.charValue(); expected++) {
assertEquals(expected, ((Character) iter.next()).charValue());
}
}
use of java.util.Iterator in project grails-core by grails.
the class LazyMetaPropertyMap method putAll.
public void putAll(Map map) {
for (Iterator i = map.keySet().iterator(); i.hasNext(); ) {
Object key = i.next();
put(key, map.get(key));
}
}
use of java.util.Iterator in project grails-core by grails.
the class DefaultUrlCreator method appendRequestParams.
/*
* Appends all the request parameters to the URI buffer
*/
private void appendRequestParams(FastStringWriter actualUriBuf, Map<Object, Object> params, String encoding) {
boolean querySeparator = false;
for (Map.Entry<Object, Object> entry : params.entrySet()) {
Object name = entry.getKey();
if (name.equals(GrailsControllerClass.CONTROLLER) || name.equals(GrailsControllerClass.ACTION) || name.equals(ARGUMENT_ID)) {
continue;
}
if (!querySeparator) {
actualUriBuf.append('?');
querySeparator = true;
} else {
actualUriBuf.append(ENTITY_AMPERSAND);
}
Object value = entry.getValue();
if (value instanceof Collection) {
Collection values = (Collection) value;
Iterator valueIterator = values.iterator();
while (valueIterator.hasNext()) {
Object currentValue = valueIterator.next();
appendRequestParam(actualUriBuf, name, currentValue, encoding);
if (valueIterator.hasNext()) {
actualUriBuf.append(ENTITY_AMPERSAND);
}
}
} else if (value != null && value.getClass().isArray()) {
Object[] array = (Object[]) value;
for (int j = 0; j < array.length; j++) {
Object currentValue = array[j];
appendRequestParam(actualUriBuf, name, currentValue, encoding);
if (j < (array.length - 1)) {
actualUriBuf.append(ENTITY_AMPERSAND);
}
}
} else {
appendRequestParam(actualUriBuf, name, value, encoding);
}
}
}
Aggregations