use of org.drools.model.functions.accumulate.AccumulateFunction in project drools by kiegroup.
the class ViewFlowBuilder method viewItem2Condition.
private static Condition viewItem2Condition(ViewItem viewItem, Condition condition, BuildContext ctx) {
if (viewItem instanceof AbstractExprViewItem) {
((PatternImpl) condition).addWatchedProps(((AbstractExprViewItem) viewItem).getWatchedProps());
}
if (viewItem instanceof Expr1ViewItemImpl) {
Expr1ViewItemImpl expr = (Expr1ViewItemImpl) viewItem;
if (expr.getPredicate() != null) {
((PatternImpl) condition).addConstraint(new SingleConstraint1(expr));
}
return condition;
}
if (viewItem instanceof ExprNViewItem) {
((PatternImpl) condition).addConstraint(SingleConstraint.createConstraint((ExprNViewItem) viewItem));
return condition;
}
if (viewItem instanceof TemporalExprViewItem) {
TemporalExprViewItem expr = (TemporalExprViewItem) viewItem;
((PatternImpl) condition).addConstraint(new TemporalConstraint(expr));
return condition;
}
if (viewItem instanceof AccumulateExprViewItem) {
AccumulateExprViewItem acc = (AccumulateExprViewItem) viewItem;
for (AccumulateFunction accFunc : acc.getAccumulateFunctions()) {
ctx.usedVars.add(accFunc.getVariable());
}
final Condition newCondition = acc.getExpr() instanceof InputViewItem ? condition : viewItem2Condition(acc.getExpr(), condition, ctx);
return new AccumulatePatternImpl(newCondition, acc.getAccumulateFunctions());
}
if (viewItem instanceof CombinedExprViewItem) {
CombinedExprViewItem combined = (CombinedExprViewItem) viewItem;
CompositePatterns patterns = viewItems2Condition(new BuildContext(ctx, combined.getExpressions()), combined.getType(), false);
return patterns.getSubConditions().size() == 1 ? patterns.getSubConditions().get(0) : patterns;
}
throw new UnsupportedOperationException("Unknown ViewItem: " + viewItem);
}
use of org.drools.model.functions.accumulate.AccumulateFunction in project drools by kiegroup.
the class KiePackagesBuilder method buildAccumulate.
private Accumulate buildAccumulate(RuleContext ctx, AccumulatePattern accPattern, RuleConditionElement source, Pattern pattern, List<String> usedVariableName, Binding binding) {
AccumulateFunction[] accFunctions = accPattern.getAccumulateFunctions();
Accumulate accumulate;
if (accFunctions.length == 1) {
final Class<?> functionClass = accFunctions[0].getFunctionClass();
final Accumulator accumulator = createAccumulator(usedVariableName, binding, functionClass);
final Variable boundVar = accPattern.getBoundVariables()[0];
final Declaration declaration = new Declaration(boundVar.getName(), getReadAcessor(JAVA_CLASS_OBJECT_TYPE), pattern, true);
pattern.addDeclaration(declaration);
Declaration[] bindingDeclaration = binding != null ? new Declaration[0] : new Declaration[] { ctx.getPattern(accFunctions[0].getSource()).getDeclaration() };
accumulate = new SingleAccumulate(source, bindingDeclaration, accumulator);
} else {
InternalReadAccessor reader = new SelfReferenceClassFieldReader(Object[].class);
Accumulator[] accumulators = new Accumulator[accFunctions.length];
for (int i = 0; i < accFunctions.length; i++) {
final Class<?> functionClass = accFunctions[i].getFunctionClass();
final Accumulator accumulator = createAccumulator(usedVariableName, binding, functionClass);
Variable boundVar = accPattern.getBoundVariables()[i];
pattern.addDeclaration(new Declaration(boundVar.getName(), new ArrayElementReader(reader, i, boundVar.getType()), pattern, true));
accumulators[i] = accumulator;
}
accumulate = new MultiAccumulate(source, new Declaration[0], accumulators);
}
for (Variable boundVar : accPattern.getBoundVariables()) {
ctx.addAccumulateSource(boundVar, accumulate);
}
return accumulate;
}
Aggregations