private MethodDeclaration createCreatePropertyVector() {
SimpleName columnNames = f.newSimpleName("columnNames");
SimpleName vector = f.newSimpleName("vector");
List<Statement> statements = Lists.create();
statements.add(new TypeBuilder(f, context.resolve(int[].class))
.newArray(new ExpressionBuilder(f, f.newSimpleName(NAME_PROPERTY_POSITIONS))
.method("size")
.toExpression())
.toLocalVariableDeclaration(context.resolve(int[].class), vector));
SimpleName index = f.newSimpleName("i");
SimpleName column = f.newSimpleName("column");
SimpleName position = f.newSimpleName("position");
statements.add(f.newForStatement(
f.newLocalVariableDeclaration(
new AttributeBuilder(f).toAttributes(),
context.resolve(int.class),
Arrays.asList(
f.newVariableDeclarator(
index,
Models.toLiteral(f, 0)),
f.newVariableDeclarator(
f.newSimpleName("n"),
new ExpressionBuilder(f, columnNames)
.method("size")
.toExpression()))),
new ExpressionBuilder(f, index)
.apply(InfixOperator.LESS, f.newSimpleName("n"))
.toExpression(),
f.newStatementExpressionList(new ExpressionBuilder(f, index)
.apply(PostfixOperator.INCREMENT)
.toExpression()),
f.newBlock(new Statement[] {
new ExpressionBuilder(f, columnNames)
.method("get", index)
.toLocalVariableDeclaration(context.resolve(String.class), column),
new ExpressionBuilder(f, f.newSimpleName(NAME_PROPERTY_POSITIONS))
.method("get", column)
.toLocalVariableDeclaration(context.resolve(Integer.class), position),
f.newIfStatement(
new ExpressionBuilder(f, position)
.apply(InfixOperator.EQUALS, Models.toNullLiteral(f))
.apply(InfixOperator.CONDITIONAL_OR, new ExpressionBuilder(f, vector)
.array(position)
.apply(InfixOperator.NOT_EQUALS, Models.toLiteral(f, 0))
.toExpression())
.toExpression(),
f.newBlock(new TypeBuilder(f, context.resolve(IllegalArgumentException.class))
.newObject(column)
.toThrowStatement())),
new ExpressionBuilder(f, vector)
.array(position)
.assignFrom(new ExpressionBuilder(f, index)