package com.healthmarketscience.jackcess.expr;
import java.math.BigDecimal;
-import java.math.BigInteger;
import java.util.Date;
/**
{
public enum Type
{
- NULL, STRING, DATE, TIME, DATE_TIME, LONG, DOUBLE, BIG_INT, BIG_DEC;
+ NULL, STRING, DATE, TIME, DATE_TIME, LONG, DOUBLE, BIG_DEC;
public boolean isNumeric() {
return inRange(LONG, BIG_DEC);
public boolean isIntegral() {
// note when BOOLEAN is converted to number, it is integral
- return ((this == LONG) || (this == BIG_INT));
+ return (this == LONG);
}
public boolean isTemporal() {
public Double getAsDouble();
- public BigInteger getAsBigInteger();
-
public BigDecimal getAsBigDecimal();
}
package com.healthmarketscience.jackcess.impl.expr;
import java.math.BigDecimal;
-import java.math.BigInteger;
import java.text.DateFormat;
import java.util.Date;
-import com.healthmarketscience.jackcess.expr.Value;
import com.healthmarketscience.jackcess.impl.ColumnImpl;
/**
return getNumber();
}
- @Override
- public BigInteger getAsBigInteger() {
- return getAsBigDecimal().toBigInteger();
- }
-
@Override
public BigDecimal getAsBigDecimal() {
return BigDecimal.valueOf(getNumber());
package com.healthmarketscience.jackcess.impl.expr;
import java.math.BigDecimal;
-import java.math.BigInteger;
import java.util.Date;
import com.healthmarketscience.jackcess.expr.Value;
return getDelegate().getAsDouble();
}
- public BigInteger getAsBigInteger() {
- return getDelegate().getAsBigInteger();
- }
-
public BigDecimal getAsBigDecimal() {
return getDelegate().getAsBigDecimal();
}
package com.healthmarketscience.jackcess.impl.expr;
import java.math.BigDecimal;
-import java.math.BigInteger;
import java.util.Date;
import com.healthmarketscience.jackcess.expr.Value;
throw invalidConversion(Value.Type.DOUBLE);
}
- public BigInteger getAsBigInteger() {
- throw invalidConversion(Value.Type.BIG_INT);
- }
-
public BigDecimal getAsBigDecimal() {
throw invalidConversion(Value.Type.BIG_DEC);
}
package com.healthmarketscience.jackcess.impl.expr;
import java.math.BigDecimal;
-import java.math.BigInteger;
/**
*
return _val.toPlainString();
}
- @Override
- public BigInteger getAsBigInteger() {
- return _val.toBigInteger();
- }
-
@Override
public BigDecimal getAsBigDecimal() {
return _val;
+++ /dev/null
-/*
-Copyright (c) 2016 James Ahlborn
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-package com.healthmarketscience.jackcess.impl.expr;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-
-/**
- *
- * @author James Ahlborn
- */
-public class BigIntegerValue extends BaseNumericValue
-{
- private final BigInteger _val;
-
- public BigIntegerValue(BigInteger val)
- {
- _val = val;
- }
-
- public Type getType() {
- return Type.BIG_INT;
- }
-
- public Object get() {
- return _val;
- }
-
- @Override
- protected Number getNumber() {
- return _val;
- }
-
- @Override
- public boolean getAsBoolean() {
- return (_val.compareTo(BigInteger.ZERO) != 0L);
- }
-
- @Override
- public BigInteger getAsBigInteger() {
- return _val;
- }
-
- @Override
- public BigDecimal getAsBigDecimal() {
- return new BigDecimal(_val);
- }
-}
import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.DateFormat;
-import java.text.Format;
import java.util.Date;
import java.util.regex.Pattern;
return toValue(-param1.getAsLong());
case DOUBLE:
return toValue(-param1.getAsDouble());
- case BIG_INT:
- return toValue(param1.getAsBigInteger().negate());
case BIG_DEC:
return toValue(param1.getAsBigDecimal().negate());
default:
return toValue(param1.getAsLong() + param2.getAsLong());
case DOUBLE:
return toValue(param1.getAsDouble() + param2.getAsDouble());
- case BIG_INT:
- return toValue(param1.getAsBigInteger().add(param2.getAsBigInteger()));
case BIG_DEC:
return toValue(param1.getAsBigDecimal().add(param2.getAsBigDecimal()));
default:
return toValue(param1.getAsLong() - param2.getAsLong());
case DOUBLE:
return toValue(param1.getAsDouble() - param2.getAsDouble());
- case BIG_INT:
- return toValue(param1.getAsBigInteger().subtract(param2.getAsBigInteger()));
case BIG_DEC:
return toValue(param1.getAsBigDecimal().subtract(param2.getAsBigDecimal()));
default:
return toValue(param1.getAsLong() * param2.getAsLong());
case DOUBLE:
return toValue(param1.getAsDouble() * param2.getAsDouble());
- case BIG_INT:
- return toValue(param1.getAsBigInteger().multiply(param2.getAsBigInteger()));
case BIG_DEC:
return toValue(param1.getAsBigDecimal().multiply(param2.getAsBigDecimal()));
default:
throw new ArithmeticException(DIV_BY_ZERO);
}
return toValue(param1.getAsDouble() / d2);
- case BIG_INT:
- BigInteger bip1 = param1.getAsBigInteger();
- BigInteger bip2 = param2.getAsBigInteger();
- BigInteger[] res = bip1.divideAndRemainder(bip2);
- if(res[1].compareTo(BigInteger.ZERO) == 0) {
- return toValue(res[0]);
- }
- return toValue(new BigDecimal(bip1).divide(new BigDecimal(bip2)));
case BIG_DEC:
return toValue(param1.getAsBigDecimal().divide(param2.getAsBigDecimal()));
default:
case DOUBLE:
wasDouble = true;
// fallthrough
- case BIG_INT:
case BIG_DEC:
- BigInteger result = param1.getAsBigInteger().divide(
- param2.getAsBigInteger());
+ BigInteger result = getAsBigInteger(param1).divide(
+ getAsBigInteger(param2));
return (wasDouble ? toValue(result.longValue()) : toValue(result));
default:
throw new RuntimeException("Unexpected type " + mathType);
double result = Math.pow(param1.getAsDouble(), param2.getAsDouble());
// attempt to convert integral types back to integrals if possible
- switch(mathType) {
- case LONG:
- if(isIntegral(result)) {
- return toValue((long)result);
- }
- break;
- case BIG_INT:
- if(isIntegral(result)) {
- return toValue(BigDecimal.valueOf(result).toBigInteger());
- }
- break;
+ if((mathType == Value.Type.LONG) && isIntegral(result)) {
+ return toValue((long)result);
}
return toValue(result);
case DOUBLE:
wasDouble = true;
// fallthrough
- case BIG_INT:
case BIG_DEC:
- BigInteger bi1 = param1.getAsBigInteger();
- BigInteger bi2 = param2.getAsBigInteger().abs();
+ BigInteger bi1 = getAsBigInteger(param1);
+ BigInteger bi2 = getAsBigInteger(param2).abs();
if(bi2.signum() == 0) {
throw new ArithmeticException(DIV_BY_ZERO);
}
return param1.getAsLong().compareTo(param2.getAsLong());
case DOUBLE:
return param1.getAsDouble().compareTo(param2.getAsDouble());
- case BIG_INT:
- return param1.getAsBigInteger().compareTo(param2.getAsBigInteger());
case BIG_DEC:
return param1.getAsBigDecimal().compareTo(param2.getAsBigDecimal());
default:
}
}
- private static int compare(long l1, long l2) {
- return ((l1 < l2) ? -1 : ((l1 > l2) ? 1 : 0));
- }
-
public static Value toValue(boolean b) {
return (b ? TRUE_VAL : FALSE_VAL);
}
}
public static Value toValue(BigInteger s) {
- return new BigIntegerValue(s);
+ return toValue(new BigDecimal(s));
}
public static Value toValue(BigDecimal s) {
return ((d == Math.rint(d)) && !Double.isInfinite(d) && !Double.isNaN(d));
}
+ private static BigInteger getAsBigInteger(Value v) {
+ return v.getAsBigDecimal().toBigInteger();
+ }
}
package com.healthmarketscience.jackcess.impl.expr;
import java.math.BigDecimal;
-import java.math.BigInteger;
/**
*
return _val;
}
- @Override
- public BigInteger getAsBigInteger() {
- return getAsBigDecimal().toBigInteger();
- }
-
@Override
public BigDecimal getAsBigDecimal() {
return BigDecimal.valueOf(_val);
package com.healthmarketscience.jackcess.impl.expr;
import java.math.BigDecimal;
-import java.math.BigInteger;
/**
*
return _val;
}
- @Override
- public BigInteger getAsBigInteger() {
- return BigInteger.valueOf(_val);
- }
-
@Override
public BigDecimal getAsBigDecimal() {
return BigDecimal.valueOf(_val);