SimpleName l2 = factory.newSimpleName("l2");
List<Statement> statements = Lists.create();
SimpleName segmentId1 = factory.newSimpleName("segmentId1");
SimpleName segmentId2 = factory.newSimpleName("segmentId2");
statements.add(new TypeBuilder(factory, t(WritableComparator.class))
.method("readInt", b1, s1)
.toLocalVariableDeclaration(t(int.class), segmentId1));
statements.add(new TypeBuilder(factory, t(WritableComparator.class))
.method("readInt", b2, s2)
.toLocalVariableDeclaration(t(int.class), segmentId2));
SimpleName diff = factory.newSimpleName("diff");
statements.add(new ExpressionBuilder(factory, factory.newThis())
.method(ShuffleEmiterUtil.COMPARE_INT,
new ExpressionBuilder(factory, factory.newThis())
.method(ShuffleEmiterUtil.PORT_TO_ELEMENT, segmentId1)
.toExpression(),
new ExpressionBuilder(factory, factory.newThis())
.method(ShuffleEmiterUtil.PORT_TO_ELEMENT, segmentId2)
.toExpression())
.toLocalVariableDeclaration(t(int.class), diff));
statements.add(createDiffBranch(diff));
SimpleName o1 = factory.newSimpleName("o1");
SimpleName o2 = factory.newSimpleName("o2");
SimpleName size1 = factory.newSimpleName("size1");
SimpleName size2 = factory.newSimpleName("size2");
statements.add(new ExpressionBuilder(factory, v(4))
.toLocalVariableDeclaration(t(int.class), o1));
statements.add(new ExpressionBuilder(factory, v(4))
.toLocalVariableDeclaration(t(int.class), o2));
statements.add(new ExpressionBuilder(factory, v(-1))
.toLocalVariableDeclaration(t(int.class), size1));
statements.add(new ExpressionBuilder(factory, v(-1))
.toLocalVariableDeclaration(t(int.class), size2));
List<Statement> cases = Lists.create();
for (List<Segment> segments : ShuffleEmiterUtil.groupByElement(model)) {
for (Segment segment : segments) {
cases.add(factory.newSwitchCaseLabel(v(segment.getPortId())));
}
for (Term term : segments.get(0).getTerms()) {
if (term.getArrangement() != Arrangement.GROUPING) {
continue;
}
cases.add(new ExpressionBuilder(factory, size1)
.assignFrom(term.getSource().createBytesSize(
b1,
factory.newInfixExpression(s1, InfixOperator.PLUS, o1),
factory.newInfixExpression(l1, InfixOperator.MINUS, o1)))
.toStatement());
cases.add(new ExpressionBuilder(factory, size2)
.assignFrom(term.getSource().createBytesSize(
b2,
factory.newInfixExpression(s2, InfixOperator.PLUS, o2),
factory.newInfixExpression(l2, InfixOperator.MINUS, o2)))
.toStatement());
cases.add(new ExpressionBuilder(factory, diff)
.assignFrom(
term.getSource().createBytesDiff(
b1,
factory.newInfixExpression(s1, InfixOperator.PLUS, o1),
size1,
b2,
factory.newInfixExpression(s2, InfixOperator.PLUS, o2),
size2))
.toStatement());
cases.add(createDiffBranch(diff));
cases.add(new ExpressionBuilder(factory, o1)
.assignFrom(InfixOperator.PLUS, size1)
.toStatement());
cases.add(new ExpressionBuilder(factory, o2)
.assignFrom(InfixOperator.PLUS, size2)
.toStatement());
}
cases.add(factory.newBreakStatement());
}
cases.add(factory.newSwitchDefaultLabel());
cases.add(new TypeBuilder(factory, t(AssertionError.class))
.newObject()
.toThrowStatement());
statements.add(factory.newSwitchStatement(segmentId1, cases));
statements.add(new ExpressionBuilder(factory, v(0))