WarpPI/src/main/resources/rules/functions/ExpressionRule.java

59 lines
1.6 KiB
Java

/*
SETTINGS: (please don't move this part)
PATH=functions.ExpressionRule
*/
import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.FunctionOperator;
import org.warp.picalculator.math.FunctionDynamic;
import org.warp.picalculator.math.FunctionSingle;
import org.warp.picalculator.math.MathContext;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import org.warp.picalculator.ScriptUtils;
import org.warp.picalculator.math.rules.Rule;
import org.warp.picalculator.math.rules.RuleType;
import org.warp.picalculator.math.rules.RulesManager;
import org.warp.picalculator.math.functions.Multiplication;
import org.warp.picalculator.math.functions.Sum;
import org.warp.picalculator.math.functions.Subtraction;
import org.warp.picalculator.math.functions.SumSubtraction;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.functions.Expression;
/**
* Expression
* (x) = x
*
* @author Andrea Cavalli
*
*/
public class ExpressionRule implements Rule {
// Rule name
@Override
public String getRuleName() {
return "Expression";
}
// Rule type
@Override
public RuleType getRuleType() {
return RuleType.CALCULATION;
}
/* Rule function
Returns:
- null if it's not executable on the function "f"
- An ObjectArrayList<Function> if it did something
*/
@Override
public ObjectArrayList<Function> execute(Function f) {
if (f instanceof Expression) {
ObjectArrayList<Function> result = new ObjectArrayList<>();
result.add(f.getParameter(0));
return result;
}
return null;
}
}