first commit

This commit is contained in:
me
2026-04-08 21:25:17 +03:00
parent 3681b8eccd
commit 371b14c5e3
173 changed files with 14126 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
package expression.exceptions;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.List;
import expression.*;
/**
* @author Doschennikov Nikita (me@fymio.us)
*/
public class CheckedNegate extends AbstractExpression {
private final AbstractExpression operand;
public CheckedNegate(AbstractExpression operand) {
this.operand = operand;
}
private static int checkedNegate(int n) {
if (n == Integer.MIN_VALUE) throw new OverflowException("negation");
return -n;
}
@Override public int evaluate(int x) { return checkedNegate(operand.evaluate(x)); }
@Override public int evaluate(int x, int y, int z) { return checkedNegate(operand.evaluate(x,y,z)); }
@Override public int evaluate(List<Integer> vars) { return checkedNegate(operand.evaluate(vars)); }
@Override public BigInteger evaluateBi(List<BigInteger> vars) { return operand.evaluateBi(vars).negate(); }
@Override public BigDecimal evaluateBd(List<BigDecimal> vars) { return operand.evaluateBd(vars).negate(); }
@Override public String toString() { return "-(" + operand + ")"; }
@Override public String toMiniString() {
if (operand instanceof AbstractBinaryOperation) return "-(" + operand.toMiniString() + ")";
return "- " + operand.toMiniString();
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof CheckedNegate)) return false;
return operand.equals(((CheckedNegate) obj).operand);
}
@Override public int hashCode() { return -operand.hashCode(); }
}