44 lines
1.2 KiB
Java
44 lines
1.2 KiB
Java
package it.cavallium.warppi.math.parser.steps;
|
|
|
|
import it.cavallium.warppi.math.Function;
|
|
import it.cavallium.warppi.math.MathContext;
|
|
import it.cavallium.warppi.math.functions.Expression;
|
|
import it.cavallium.warppi.math.parser.MathParserStep;
|
|
import it.cavallium.warppi.util.IntWrapper;
|
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
|
|
|
public class RemoveParentheses implements MathParserStep {
|
|
|
|
@SuppressWarnings("unused")
|
|
private final MathContext context;
|
|
|
|
public RemoveParentheses(MathContext context) {
|
|
this.context = context;
|
|
}
|
|
|
|
@Override
|
|
public boolean eval(IntWrapper curIndex, Function lastFunction, Function currentFunction,
|
|
ObjectArrayList<Function> functionsList) {
|
|
if (currentFunction instanceof Expression) {
|
|
if (((Expression) currentFunction).getParameter() == null) {
|
|
functionsList.remove(curIndex.i);
|
|
} else {
|
|
functionsList.set(curIndex.i, ((Expression) currentFunction).getParameter());
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean requiresReversedIteration() {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public String getStepName() {
|
|
return "Remove parentheses";
|
|
}
|
|
|
|
}
|