use of java.util.Iterator in project nutz by nutzam.
the class Collection2Array method cast.
@Override
public Object cast(Collection src, Class<?> toType, String... args) throws FailToCastObjectException {
Class<?> compType = toType.getComponentType();
Object ary = Array.newInstance(compType, src.size());
int index = 0;
for (Iterator it = src.iterator(); it.hasNext(); ) {
Array.set(ary, index++, Castors.me().castTo(it.next(), compType));
}
return ary;
}
use of java.util.Iterator in project otter by alibaba.
the class IbatisDataColumnPairDAO method insertBatch.
public void insertBatch(List<DataColumnPairDO> dataColumnPairDos) {
try {
getSqlMapClientTemplate().getSqlMapClient().startBatch();
Iterator it = dataColumnPairDos.iterator();
while (it.hasNext()) {
DataColumnPairDO dataColumnPairDo = (DataColumnPairDO) it.next();
getSqlMapClientTemplate().getSqlMapClient().insert("insertDataColumnPair", dataColumnPairDo);
}
getSqlMapClientTemplate().getSqlMapClient().executeBatch();
} catch (SQLException ex1) {
ex1.printStackTrace();
}
}
use of java.util.Iterator in project groovy-core by groovy.
the class ClosureWriter method getClosureSharedVariables.
protected Parameter[] getClosureSharedVariables(ClosureExpression ce) {
VariableScope scope = ce.getVariableScope();
Parameter[] ret = new Parameter[scope.getReferencedLocalVariablesCount()];
int index = 0;
for (Iterator iter = scope.getReferencedLocalVariablesIterator(); iter.hasNext(); ) {
Variable element = (org.codehaus.groovy.ast.Variable) iter.next();
Parameter p = new Parameter(element.getType(), element.getName());
p.setOriginType(element.getOriginType());
p.setClosureSharedVariable(element.isClosureSharedVariable());
ret[index] = p;
index++;
}
return ret;
}
use of java.util.Iterator in project groovy-core by groovy.
the class AsmClassGenerator method visitArrayExpression.
public void visitArrayExpression(ArrayExpression expression) {
MethodVisitor mv = controller.getMethodVisitor();
ClassNode elementType = expression.getElementType();
String arrayTypeName = BytecodeHelper.getClassInternalName(elementType);
List sizeExpression = expression.getSizeExpression();
int size = 0;
int dimensions = 0;
if (sizeExpression != null) {
for (Iterator iter = sizeExpression.iterator(); iter.hasNext(); ) {
Expression element = (Expression) iter.next();
if (element == ConstantExpression.EMPTY_EXPRESSION)
break;
dimensions++;
// let's convert to an int
element.visit(this);
controller.getOperandStack().doGroovyCast(ClassHelper.int_TYPE);
}
controller.getOperandStack().remove(dimensions);
} else {
size = expression.getExpressions().size();
BytecodeHelper.pushConstant(mv, size);
}
int storeIns = AASTORE;
if (sizeExpression != null) {
arrayTypeName = BytecodeHelper.getTypeDescription(expression.getType());
mv.visitMultiANewArrayInsn(arrayTypeName, dimensions);
} else if (ClassHelper.isPrimitiveType(elementType)) {
int primType = 0;
if (elementType == ClassHelper.boolean_TYPE) {
primType = T_BOOLEAN;
storeIns = BASTORE;
} else if (elementType == ClassHelper.char_TYPE) {
primType = T_CHAR;
storeIns = CASTORE;
} else if (elementType == ClassHelper.float_TYPE) {
primType = T_FLOAT;
storeIns = FASTORE;
} else if (elementType == ClassHelper.double_TYPE) {
primType = T_DOUBLE;
storeIns = DASTORE;
} else if (elementType == ClassHelper.byte_TYPE) {
primType = T_BYTE;
storeIns = BASTORE;
} else if (elementType == ClassHelper.short_TYPE) {
primType = T_SHORT;
storeIns = SASTORE;
} else if (elementType == ClassHelper.int_TYPE) {
primType = T_INT;
storeIns = IASTORE;
} else if (elementType == ClassHelper.long_TYPE) {
primType = T_LONG;
storeIns = LASTORE;
}
mv.visitIntInsn(NEWARRAY, primType);
} else {
mv.visitTypeInsn(ANEWARRAY, arrayTypeName);
}
for (int i = 0; i < size; i++) {
mv.visitInsn(DUP);
BytecodeHelper.pushConstant(mv, i);
Expression elementExpression = expression.getExpression(i);
if (elementExpression == null) {
ConstantExpression.NULL.visit(this);
} else {
elementExpression.visit(this);
controller.getOperandStack().doGroovyCast(elementType);
}
mv.visitInsn(storeIns);
controller.getOperandStack().remove(1);
}
controller.getOperandStack().push(expression.getType());
}
use of java.util.Iterator in project grails-core by grails.
the class Grails5535Factory method replaceProperties.
/**
* Replaces any properties that appear in the supplied string
* with their actual values
*
* @param str the string to replace the properties in
* @return the same string but with any properties expanded out to their
* actual values
*/
private String replaceProperties(String str) {
Set props = configProps.entrySet();
for (Iterator it = props.iterator(); it.hasNext(); ) {
Map.Entry entry = (Map.Entry) it.next();
String key = (String) entry.getKey();
int idx;
while ((idx = str.indexOf(key)) >= 0) {
StringBuilder buf = new StringBuilder(100);
buf.append(str.substring(0, idx));
buf.append(entry.getValue());
buf.append(str.substring(idx + key.length()));
str = buf.toString();
}
}
return str;
}
Aggregations