Upload files to "java/expression"
This commit is contained in:
67
java/expression/Negate.java
Normal file
67
java/expression/Negate.java
Normal file
@@ -0,0 +1,67 @@
|
||||
package expression;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Doschennikov Nikita (me@fymio.us)
|
||||
*/
|
||||
public class Negate extends AbstractExpression {
|
||||
|
||||
private final AbstractExpression operand;
|
||||
|
||||
public Negate(AbstractExpression operand) {
|
||||
this.operand = operand;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int evaluate(int x) {
|
||||
return -operand.evaluate(x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int evaluate(int x, int y, int z) {
|
||||
return -operand.evaluate(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int evaluate(List<Integer> vars) {
|
||||
return -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 Negate)) return false;
|
||||
return operand.equals(((Negate) obj).operand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return -operand.hashCode();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user