first commit
This commit is contained in:
75
java/expression/Ceiling.java
Normal file
75
java/expression/Ceiling.java
Normal file
@@ -0,0 +1,75 @@
|
||||
package expression;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Doschennikov Nikita (me@fymio.us)
|
||||
*/
|
||||
public class Ceiling extends AbstractExpression {
|
||||
|
||||
private final AbstractExpression operand;
|
||||
|
||||
public Ceiling(AbstractExpression operand) {
|
||||
this.operand = operand;
|
||||
}
|
||||
|
||||
private static int ceilInt(int n) {
|
||||
return Math.ceilDiv(n, 1000) * 1000;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int evaluate(int x) {
|
||||
return ceilInt(operand.evaluate(x));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int evaluate(int x, int y, int z) {
|
||||
return ceilInt(operand.evaluate(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int evaluate(List<Integer> vars) {
|
||||
return ceilInt(operand.evaluate(vars));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigInteger evaluateBi(List<BigInteger> vars) {
|
||||
throw new UnsupportedOperationException(
|
||||
"ceiling not supported for BigInteger"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal evaluateBd(List<BigDecimal> vars) {
|
||||
throw new UnsupportedOperationException(
|
||||
"ceiling not supported for BigDecimal"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ceiling(" + operand + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toMiniString() {
|
||||
if (operand instanceof AbstractBinaryOperation) {
|
||||
return "ceiling(" + operand.toMiniString() + ")";
|
||||
}
|
||||
return "ceiling " + operand.toMiniString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof Ceiling)) return false;
|
||||
return operand.equals(((Ceiling) obj).operand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return operand.hashCode() ^ 0x43454C47;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user