package foundation.translator;
|
|
import java.math.BigDecimal;
|
import java.util.Date;
|
|
import foundation.server.config.DBaseType;
|
import foundation.util.Util;
|
|
|
public class BigDecimalTranslator extends ITranslator {
|
|
@Override
|
public String toString(Object value) throws Exception {
|
if (value == null || value == ValueType.Null) {
|
return null;
|
}
|
|
return value.toString();
|
}
|
|
@Override
|
public String toSqlString(DBaseType dbaseType, Object value) throws Exception {
|
if (value == null || value == ValueType.Null) {
|
return "null";
|
}
|
|
return value.toString();
|
}
|
|
@Override
|
public String toJSONString(Object value) throws Exception {
|
if (value == null || value == ValueType.Null) {
|
return "null";
|
}
|
|
return value.toString();
|
}
|
|
@Override
|
public String toSchemaString(Object value) throws Exception {
|
if (value == null || value == ValueType.Null) {
|
return "";
|
}
|
|
return value.toString();
|
}
|
|
@Override
|
public Integer toInteger(Object value) throws Exception {
|
if (value == null || value == ValueType.Null) {
|
return null;
|
}
|
|
return ((BigDecimal)value).intValue();
|
}
|
|
@Override
|
public Double toDouble(Object value) throws Exception {
|
if (value == null || value == ValueType.Null) {
|
return null;
|
}
|
|
return ((BigDecimal)value).doubleValue();
|
}
|
|
public BigDecimal toBigDecimal(Object value) throws Exception {
|
if (value == null || value == ValueType.Null) {
|
return null;
|
}
|
|
BigDecimal result = new BigDecimal(value.toString());
|
return result;
|
}
|
|
public Boolean toBoolean(Object value) throws Exception {
|
if (value == null || value == ValueType.Null) {
|
return false;
|
}
|
|
|
return ((BigDecimal)value).compareTo(BigDecimal.ZERO) > 0;
|
}
|
|
public Date toDate(Object value) throws Exception {
|
if (value == null || value == ValueType.Null) {
|
return null;
|
}
|
|
return new Date(((BigDecimal)value).longValue());
|
}
|
|
@Override
|
public Object toTranslatorTypeValue(Object value) throws Exception {
|
return new BigDecimal(value.toString());
|
}
|
|
public Object loadObjectFrom(String value) throws Exception {
|
if (Util.isEmpty(value)) {
|
return null;
|
}
|
|
return BigDecimal.valueOf(Double.valueOf(value));
|
}
|
|
@Override
|
public Class<?> getDataClass() {
|
return BigDecimal.class;
|
}
|
|
}
|