use of org.matheclipse.core.patternmatching.PatternMatcherList in project symja_android_library by axkr.
the class Functors method listRules.
public static Function<IExpr, IExpr> listRules(IAST astRules, IASTAppendable result, EvalEngine engine) {
final Map<IExpr, IExpr> equalRules;
List<PatternMatcherList> matchers = new ArrayList<PatternMatcherList>();
if (astRules.isList()) {
if (astRules.size() > 1) {
// assuming multiple rules in a list
IAST rule;
int argsSize = astRules.argSize();
if (argsSize <= 5) {
equalRules = new OpenFixedSizeMap<IExpr, IExpr>(argsSize * 3 - 1);
} else {
equalRules = new HashMap<IExpr, IExpr>();
}
for (final IExpr expr : astRules) {
if (expr.isRuleAST()) {
rule = (IAST) expr;
createPatternMatcherList(equalRules, matchers, rule);
} else {
throw new ArgumentTypeException("rule expression (x->y or x:>y) expected instead of " + expr.toString());
}
}
} else {
equalRules = new HashMap<IExpr, IExpr>();
}
} else {
if (astRules.isRuleAST()) {
equalRules = new OpenFixedSizeMap<IExpr, IExpr>(3);
createPatternMatcherList(equalRules, matchers, astRules);
} else {
throw new ArgumentTypeException("rule expression (x->y or x:>y) expected instead of " + astRules.toString());
}
}
if (matchers.size() > 0) {
return new ListRulesPatternFunctor(equalRules, matchers, result, engine);
}
return listRules(equalRules, result);
}
Aggregations