2016-11-02 21:56:40 +01:00
|
|
|
package org.warp.picalculator.math.functions;
|
|
|
|
|
|
|
|
import org.warp.picalculator.Error;
|
2017-05-26 22:37:18 +02:00
|
|
|
import org.warp.picalculator.gui.expression.blocks.Block;
|
2017-07-24 23:11:29 +02:00
|
|
|
import org.warp.picalculator.gui.expression.blocks.BlockChar;
|
|
|
|
import org.warp.picalculator.gui.expression.blocks.BlockParenthesis;
|
2017-02-14 20:02:03 +01:00
|
|
|
import org.warp.picalculator.math.Function;
|
|
|
|
import org.warp.picalculator.math.FunctionSingle;
|
2017-05-16 22:02:44 +02:00
|
|
|
import org.warp.picalculator.math.MathContext;
|
2017-07-24 23:11:29 +02:00
|
|
|
import org.warp.picalculator.math.MathematicalSymbols;
|
2016-11-02 21:56:40 +01:00
|
|
|
|
2017-05-16 22:02:44 +02:00
|
|
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
|
|
|
|
2017-02-14 20:02:03 +01:00
|
|
|
public class Negative extends FunctionSingle {
|
2016-11-02 21:56:40 +01:00
|
|
|
|
2017-02-14 20:02:03 +01:00
|
|
|
public Negative(MathContext root, Function value) {
|
2017-01-17 22:32:40 +01:00
|
|
|
super(root, value);
|
2016-11-02 21:56:40 +01:00
|
|
|
}
|
2017-01-17 22:32:40 +01:00
|
|
|
|
2016-11-25 22:40:43 +01:00
|
|
|
@Override
|
|
|
|
public boolean equals(Object o) {
|
|
|
|
if (o instanceof Negative) {
|
2017-03-03 23:06:43 +01:00
|
|
|
return ((Negative) o).getParameter().equals(parameter);
|
2016-11-25 22:40:43 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2017-03-03 23:06:43 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Negative clone() {
|
|
|
|
return new Negative(mathContext, parameter);
|
|
|
|
}
|
2017-09-24 18:47:30 +02:00
|
|
|
|
2017-05-26 22:37:18 +02:00
|
|
|
@Override
|
|
|
|
public ObjectArrayList<Block> toBlock(MathContext context) throws Error {
|
2017-07-24 23:11:29 +02:00
|
|
|
ObjectArrayList<Block> blocks = new ObjectArrayList<Block>();
|
|
|
|
blocks.add(new BlockChar(MathematicalSymbols.MINUS));
|
|
|
|
if (new Expression(context, getParameter()).parenthesisNeeded()) {
|
|
|
|
BlockParenthesis par = new BlockParenthesis();
|
|
|
|
ObjectArrayList<Block> parBlocks = getParameter().toBlock(context);
|
2017-09-24 18:47:30 +02:00
|
|
|
for (Block b : parBlocks) {
|
2017-07-24 23:11:29 +02:00
|
|
|
par.getNumberContainer().appendBlockUnsafe(b); // Skips recomputeDimension
|
|
|
|
}
|
|
|
|
par.recomputeDimensions(); // Recompute dimensions after appendBlockUnsafe
|
|
|
|
blocks.add(par);
|
|
|
|
} else {
|
|
|
|
blocks.addAll(getParameter().toBlock(context));
|
|
|
|
}
|
|
|
|
return blocks;
|
|
|
|
// throw new Error(Errors.NOT_IMPLEMENTED, "Unknown function " + getClass().getSimpleName());
|
2017-05-26 22:37:18 +02:00
|
|
|
}
|
2016-11-02 21:56:40 +01:00
|
|
|
}
|