net.sf.aguacate.function.spi.impl.FunctionNotZero Maven / Gradle / Ivy
package net.sf.aguacate.function.spi.impl;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Collection;
import net.sf.aguacate.function.FunctionContext;
import net.sf.aguacate.function.FunctionEvalResult;
import net.sf.aguacate.function.Parameter;
import net.sf.aguacate.function.spi.AbstractFunction1;
public class FunctionNotZero extends AbstractFunction1 {
public FunctionNotZero(Collection methods, String name, String message, Parameter parameter) {
super(methods, name, message, parameter);
}
@Override
protected FunctionEvalResult evaluate(FunctionContext functionContext, String msg, Object value) {
Class extends Object> klass = value.getClass();
if (klass == BigInteger.class) {
if (BigInteger.ZERO.equals(value)) {
logFailure(msg);
return new FunctionEvalResult("Zero", null);
} else {
logSuccess(msg);
return new FunctionEvalResult(null, null);
}
} else {
if (Long.class == klass) {
if (Long.valueOf(0).equals(value)) {
logFailure(msg);
return new FunctionEvalResult("Zero", null);
} else {
logSuccess(msg);
return new FunctionEvalResult(null, null);
}
} else {
if (klass == BigDecimal.class) {
BigDecimal val = (BigDecimal) value;
BigDecimal zero = BigDecimal.ZERO.setScale(val.scale());
if (zero.equals(val)) {
logFailure(msg);
return new FunctionEvalResult("Zero", null);
} else {
logSuccess(msg);
return new FunctionEvalResult(null, null);
}
} else {
logFailure(msg);
return new FunctionEvalResult("Not implemented", null);
}
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy