git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/exprs@1074 f203690c-595d-4dc9-a70b-905162fa7fd2tags/jackcess-2.2.0
@@ -57,6 +57,8 @@ public interface Value | |||
public Object get(); | |||
public boolean isNull(); | |||
public boolean getAsBoolean(); | |||
public String getAsString(); | |||
@@ -70,6 +72,4 @@ public interface Value | |||
public BigInteger getAsBigInteger(); | |||
public BigDecimal getAsBigDecimal(); | |||
public Value toNumericValue(); | |||
} |
@@ -77,9 +77,4 @@ public abstract class BaseDateValue extends BaseValue | |||
public BigDecimal getAsBigDecimal() { | |||
return BigDecimal.valueOf(getNumber()); | |||
} | |||
@Override | |||
public Value toNumericValue() { | |||
return new DoubleValue(getNumber()); | |||
} | |||
} |
@@ -26,6 +26,10 @@ public abstract class BaseDelayedValue implements Value | |||
return _val; | |||
} | |||
public boolean isNull() { | |||
return(getType() == Type.NULL); | |||
} | |||
public Value.Type getType() { | |||
return getDelegate().getType(); | |||
} | |||
@@ -62,9 +66,5 @@ public abstract class BaseDelayedValue implements Value | |||
return getDelegate().getAsBigDecimal(); | |||
} | |||
public Value toNumericValue() { | |||
return getDelegate().toNumericValue(); | |||
} | |||
protected abstract Value eval(); | |||
} |
@@ -30,10 +30,5 @@ public abstract class BaseNumericValue extends BaseValue | |||
return getNumber().doubleValue(); | |||
} | |||
@Override | |||
public Value toNumericValue() { | |||
return this; | |||
} | |||
protected abstract Number getNumber(); | |||
} |
@@ -28,6 +28,10 @@ import com.healthmarketscience.jackcess.expr.Value; | |||
*/ | |||
public abstract class BaseValue implements Value | |||
{ | |||
public boolean isNull() { | |||
return(getType() == Type.NULL); | |||
} | |||
public boolean getAsBoolean() { | |||
throw invalidConversion(Value.Type.LONG); | |||
} | |||
@@ -56,10 +60,6 @@ public abstract class BaseValue implements Value | |||
throw invalidConversion(Value.Type.BIG_DEC); | |||
} | |||
public Value toNumericValue() { | |||
throw invalidConversion(Value.Type.LONG); | |||
} | |||
private UnsupportedOperationException invalidConversion(Value.Type newType) { | |||
return new UnsupportedOperationException( | |||
getType() + " value cannot be converted to " + newType); |
@@ -64,7 +64,7 @@ public class BuiltinOperators | |||
// FIXME, Imp operator? | |||
public static Value negate(Value param1) { | |||
if(paramIsNull(param1)) { | |||
if(param1.isNull()) { | |||
// null propagation | |||
return NULL_VAL; | |||
} | |||
@@ -319,11 +319,11 @@ public class BuiltinOperators | |||
public static Value concat(Value param1, Value param2) { | |||
// note, this op converts null to empty string | |||
if(paramIsNull(param1)) { | |||
if(param1.isNull()) { | |||
param1 = EMPTY_STR_VAL; | |||
} | |||
if(paramIsNull(param2)) { | |||
if(param2.isNull()) { | |||
param2 = EMPTY_STR_VAL; | |||
} | |||
@@ -335,7 +335,7 @@ public class BuiltinOperators | |||
} | |||
public static Value not(Value param1) { | |||
if(paramIsNull(param1)) { | |||
if(param1.isNull()) { | |||
// null propagation | |||
return NULL_VAL; | |||
} | |||
@@ -401,7 +401,7 @@ public class BuiltinOperators | |||
// "and" uses short-circuit logic | |||
if(paramIsNull(param1)) { | |||
if(param1.isNull()) { | |||
return NULL_VAL; | |||
} | |||
@@ -410,7 +410,7 @@ public class BuiltinOperators | |||
return FALSE_VAL; | |||
} | |||
if(paramIsNull(param2)) { | |||
if(param2.isNull()) { | |||
return NULL_VAL; | |||
} | |||
@@ -421,7 +421,7 @@ public class BuiltinOperators | |||
// "or" uses short-circuit logic | |||
if(paramIsNull(param1)) { | |||
if(param1.isNull()) { | |||
return NULL_VAL; | |||
} | |||
@@ -430,7 +430,7 @@ public class BuiltinOperators | |||
return TRUE_VAL; | |||
} | |||
if(paramIsNull(param2)) { | |||
if(param2.isNull()) { | |||
return NULL_VAL; | |||
} | |||
@@ -465,8 +465,8 @@ public class BuiltinOperators | |||
// "imp" uses short-circuit logic | |||
if(paramIsNull(param1)) { | |||
if(paramIsNull(param2) || !param2.getAsBoolean()) { | |||
if(param1.isNull()) { | |||
if(param2.isNull() || !param2.getAsBoolean()) { | |||
// null propagation | |||
return NULL_VAL; | |||
} | |||
@@ -479,7 +479,7 @@ public class BuiltinOperators | |||
return TRUE_VAL; | |||
} | |||
if(paramIsNull(param2)) { | |||
if(param2.isNull()) { | |||
// null propagation | |||
return NULL_VAL; | |||
} | |||
@@ -496,7 +496,7 @@ public class BuiltinOperators | |||
} | |||
public static Value like(Value param1, Pattern pattern) { | |||
if(paramIsNull(param1)) { | |||
if(param1.isNull()) { | |||
// null propagation | |||
return NULL_VAL; | |||
} | |||
@@ -530,13 +530,13 @@ public class BuiltinOperators | |||
public static Value in(Value param1, Value[] params) { | |||
// null propagate any param. uses short circuit eval of params | |||
if(paramIsNull(param1)) { | |||
if(param1.isNull()) { | |||
// null propagation | |||
return NULL_VAL; | |||
} | |||
for(Value val : params) { | |||
if(paramIsNull(val)) { | |||
if(val.isNull()) { | |||
continue; | |||
} | |||
@@ -555,16 +555,12 @@ public class BuiltinOperators | |||
private static boolean anyParamIsNull(Value param1, Value param2) { | |||
return (paramIsNull(param1) || paramIsNull(param2)); | |||
return (param1.isNull() || param2.isNull()); | |||
} | |||
private static boolean anyParamIsNull(Value param1, Value param2, | |||
Value param3) { | |||
return (paramIsNull(param1) || paramIsNull(param2) || paramIsNull(param3)); | |||
} | |||
private static boolean paramIsNull(Value param1) { | |||
return (param1.getType() == Value.Type.NULL); | |||
return (param1.isNull() || param2.isNull() || param3.isNull()); | |||
} | |||
protected static int nonNullCompareTo( |
@@ -56,6 +56,7 @@ public class DefaultFunctions | |||
} | |||
public boolean isPure() { | |||
// most functions are probably pure, so make this the default | |||
return true; | |||
} | |||
@@ -118,25 +119,22 @@ public class DefaultFunctions | |||
protected abstract Value eval3(Value param1, Value param2, Value param3); | |||
} | |||
public static final Function IIF = new Func3("IIf") { | |||
public static final Function IIF = registerFunc(new Func3("IIf") { | |||
@Override | |||
protected Value eval3(Value param1, Value param2, Value param3) { | |||
// FIXME | |||
// return (paramToBoolean(param1) ? param2 : param3); | |||
return null; | |||
return (param1.getAsBoolean() ? param2 : param3); | |||
} | |||
}; | |||
}); | |||
// https://www.techonthenet.com/access/functions/ | |||
// https://support.office.com/en-us/article/Access-Functions-by-category-b8b136c3-2716-4d39-94a2-658ce330ed83 | |||
private static void registerFunc(Function func) { | |||
private static Function registerFunc(Function func) { | |||
if(FUNCS.put(func.getName().toLowerCase(), func) != null) { | |||
throw new IllegalStateException("Duplicate function " + func); | |||
} | |||
} | |||
static { | |||
registerFunc(IIF); | |||
return func; | |||
} | |||
} |