From: James Ahlborn Date: Fri, 9 Dec 2016 15:06:15 +0000 (+0000) Subject: ditch boolean type X-Git-Tag: jackcess-2.2.0~24^2~59 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ea7b355f898466e4c9f344e6750e1508ed0541b0;p=jackcess.git ditch boolean type git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/exprs@1068 f203690c-595d-4dc9-a70b-905162fa7fd2 --- diff --git a/src/main/java/com/healthmarketscience/jackcess/expr/Value.java b/src/main/java/com/healthmarketscience/jackcess/expr/Value.java index c9a2a22..59f99c0 100644 --- a/src/main/java/com/healthmarketscience/jackcess/expr/Value.java +++ b/src/main/java/com/healthmarketscience/jackcess/expr/Value.java @@ -28,8 +28,7 @@ public interface Value { public enum Type { - // FIXME, ditch boolean type -> -1,0 - NULL, BOOLEAN, STRING, DATE, TIME, DATE_TIME, LONG, DOUBLE, BIG_INT, BIG_DEC; + NULL, STRING, DATE, TIME, DATE_TIME, LONG, DOUBLE, BIG_INT, BIG_DEC; public boolean isNumeric() { return inRange(LONG, BIG_DEC); @@ -37,7 +36,7 @@ public interface Value public boolean isIntegral() { // note when BOOLEAN is converted to number, it is integral - return ((this == LONG) || (this == BIG_INT) || (this == BOOLEAN)); + return ((this == LONG) || (this == BIG_INT)); } public boolean isTemporal() { @@ -58,7 +57,7 @@ public interface Value public Object get(); - public Boolean getAsBoolean(); + public boolean getAsBoolean(); public String getAsString(); diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/expr/BaseDateValue.java b/src/main/java/com/healthmarketscience/jackcess/impl/expr/BaseDateValue.java index 8a3ff8f..ed1b8b5 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/expr/BaseDateValue.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/expr/BaseDateValue.java @@ -48,9 +48,9 @@ public abstract class BaseDateValue extends BaseValue } @Override - public Boolean getAsBoolean() { + public boolean getAsBoolean() { // ms access seems to treat dates/times as "true" - return Boolean.TRUE; + return true; } @Override diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/expr/BaseDelayedValue.java b/src/main/java/com/healthmarketscience/jackcess/impl/expr/BaseDelayedValue.java index 8849390..ffb919b 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/expr/BaseDelayedValue.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/expr/BaseDelayedValue.java @@ -34,7 +34,7 @@ public abstract class BaseDelayedValue implements Value return getDelegate().get(); } - public Boolean getAsBoolean() { + public boolean getAsBoolean() { return getDelegate().getAsBoolean(); } diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/expr/BaseValue.java b/src/main/java/com/healthmarketscience/jackcess/impl/expr/BaseValue.java index d75e671..89e9de3 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/expr/BaseValue.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/expr/BaseValue.java @@ -28,8 +28,8 @@ import com.healthmarketscience.jackcess.expr.Value; */ public abstract class BaseValue implements Value { - public Boolean getAsBoolean() { - throw invalidConversion(Value.Type.BOOLEAN); + public boolean getAsBoolean() { + throw invalidConversion(Value.Type.LONG); } public String getAsString() { diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/expr/BigDecimalValue.java b/src/main/java/com/healthmarketscience/jackcess/impl/expr/BigDecimalValue.java index 386eb79..d3ff58e 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/expr/BigDecimalValue.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/expr/BigDecimalValue.java @@ -46,7 +46,7 @@ public class BigDecimalValue extends BaseNumericValue } @Override - public Boolean getAsBoolean() { + public boolean getAsBoolean() { return (_val.compareTo(BigDecimal.ZERO) != 0L); } diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/expr/BigIntegerValue.java b/src/main/java/com/healthmarketscience/jackcess/impl/expr/BigIntegerValue.java index 9aa787f..fce73ec 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/expr/BigIntegerValue.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/expr/BigIntegerValue.java @@ -46,7 +46,7 @@ public class BigIntegerValue extends BaseNumericValue } @Override - public Boolean getAsBoolean() { + public boolean getAsBoolean() { return (_val.compareTo(BigInteger.ZERO) != 0L); } diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/expr/BooleanValue.java b/src/main/java/com/healthmarketscience/jackcess/impl/expr/BooleanValue.java deleted file mode 100644 index cc31617..0000000 --- a/src/main/java/com/healthmarketscience/jackcess/impl/expr/BooleanValue.java +++ /dev/null @@ -1,89 +0,0 @@ -/* -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; - -import com.healthmarketscience.jackcess.expr.Value; - -/** - * - * @author James Ahlborn - */ -public class BooleanValue extends BaseValue -{ - private final Boolean _val; - - public BooleanValue(Boolean val) - { - _val = val; - } - - public Type getType() { - return Type.BOOLEAN; - } - - public Object get() { - return _val; - } - - @Override - public Boolean getAsBoolean() { - return _val; - } - - @Override - public String getAsString() { - // access seems to like -1 for true and 0 for false - return (_val ? "-1" : "0"); - } - - @Override - public Long getAsLong() { - // access seems to like -1 for true and 0 for false - return numericBoolean(_val); - } - - @Override - public Double getAsDouble() { - // access seems to like -1 for true and 0 for false - return (_val ? -1d : 0d); - } - - @Override - public BigInteger getAsBigInteger() { - // access seems to like -1 for true and 0 for false - return (_val ? BigInteger.valueOf(-1) : BigInteger.ZERO); - } - - @Override - public BigDecimal getAsBigDecimal() { - // access seems to like -1 for true and 0 for false - return (_val ? BigDecimal.valueOf(-1) : BigDecimal.ZERO); - } - - @Override - public Value toNumericValue() { - return new LongValue(getAsLong()); - } - - protected static long numericBoolean(Boolean b) { - // access seems to like -1 for true and 0 for false - return (b ? -1L : 0L); - } -} diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/expr/BuiltinOperators.java b/src/main/java/com/healthmarketscience/jackcess/impl/expr/BuiltinOperators.java index 2ef3c23..040bcf1 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/expr/BuiltinOperators.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/expr/BuiltinOperators.java @@ -42,8 +42,10 @@ public class BuiltinOperators return null; } }; - public static final Value TRUE_VAL = new BooleanValue(Boolean.TRUE); - public static final Value FALSE_VAL = new BooleanValue(Boolean.FALSE); + // access seems to like -1 for true and 0 for false (boolean values are + // basically an illusion) + public static final Value TRUE_VAL = new LongValue(-1L); + public static final Value FALSE_VAL = new LongValue(0L); public static final Value EMPTY_STR_VAL = new StringValue(""); private BuiltinOperators() {} @@ -69,8 +71,6 @@ public class BuiltinOperators Value.Type mathType = param1.getType(); switch(mathType) { - case BOOLEAN: - return toValue(-getAsNumericBoolean(param1)); // case STRING: break; unsupported case DATE: case TIME: @@ -100,8 +100,6 @@ public class BuiltinOperators Value.Type mathType = getSimpleMathTypePrecedence(param1, param2); switch(mathType) { - case BOOLEAN: - return toValue(getAsNumericBoolean(param1) + getAsNumericBoolean(param2)); case STRING: // string '+' is a null-propagation (handled above) concat return nonNullConcat(param1, param2); @@ -133,8 +131,6 @@ public class BuiltinOperators Value.Type mathType = getSimpleMathTypePrecedence(param1, param2); switch(mathType) { - case BOOLEAN: - return toValue(getAsNumericBoolean(param1) - getAsNumericBoolean(param2)); // case STRING: break; unsupported case DATE: case TIME: @@ -164,8 +160,6 @@ public class BuiltinOperators Value.Type mathType = getGeneralMathTypePrecedence(param1, param2); switch(mathType) { - case BOOLEAN: - return toValue(getAsNumericBoolean(param1) * getAsNumericBoolean(param2)); // case STRING: break; unsupported // case DATE: break; promoted to double // case TIME: break; promoted to double @@ -192,8 +186,6 @@ public class BuiltinOperators Value.Type mathType = getGeneralMathTypePrecedence(param1, param2); switch(mathType) { - case BOOLEAN: - return toValue(getAsNumericBoolean(param1) / getAsNumericBoolean(param2)); // case STRING: break; unsupported // case DATE: break; promoted to double // case TIME: break; promoted to double @@ -233,8 +225,6 @@ public class BuiltinOperators boolean wasDouble = false; switch(mathType) { - case BOOLEAN: - return toValue(getAsNumericBoolean(param1) / getAsNumericBoolean(param2)); // case STRING: break; unsupported // case DATE: break; promoted to double // case TIME: break; promoted to double @@ -267,7 +257,6 @@ public class BuiltinOperators // attempt to convert integral types back to integrals if possible switch(mathType) { - case BOOLEAN: case LONG: if(isIntegral(result)) { return toValue((long)result); @@ -294,8 +283,6 @@ public class BuiltinOperators boolean wasDouble = false; switch(mathType) { - case BOOLEAN: - return toValue(getAsNumericBoolean(param1) % getAsNumericBoolean(param2)); // case STRING: break; unsupported // case DATE: break; promoted to double // case TIME: break; promoted to double @@ -561,8 +548,6 @@ public class BuiltinOperators Value.Type compareType = getGeneralMathTypePrecedence(param1, param2); switch(compareType) { - case BOOLEAN: - return compare(getAsNumericBoolean(param1), getAsNumericBoolean(param2)); case STRING: // string comparison is only valid if _both_ params are strings if(param1.getType() != param2.getType()) { @@ -589,10 +574,6 @@ public class BuiltinOperators return ((l1 < l2) ? -1 : ((l1 > l2) ? 1 : 0)); } - private static long getAsNumericBoolean(Value v) { - return BooleanValue.numericBoolean(v.getAsBoolean()); - } - public static Value toValue(boolean b) { return (b ? TRUE_VAL : FALSE_VAL); } diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/expr/DoubleValue.java b/src/main/java/com/healthmarketscience/jackcess/impl/expr/DoubleValue.java index 4a77fb9..edaf887 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/expr/DoubleValue.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/expr/DoubleValue.java @@ -46,7 +46,7 @@ public class DoubleValue extends BaseNumericValue } @Override - public Boolean getAsBoolean() { + public boolean getAsBoolean() { return (_val.doubleValue() != 0.0d); } diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/expr/Expressionator.java b/src/main/java/com/healthmarketscience/jackcess/impl/expr/Expressionator.java index e616393..5d9c1d1 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/expr/Expressionator.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/expr/Expressionator.java @@ -1304,14 +1304,15 @@ public class Expressionator return null; } - if(val.getType() != Value.Type.BOOLEAN) { - // a single value as a conditional expression seems to act like an - // implicit "=" - // FIXME, what about row validators? - val = BuiltinOperators.equals(val, ctx.getThisColumnValue()); - } - - return (Boolean)val.get(); + // FIXME, is this only true for non-numeric...? + // if(val.getType() != Value.Type.BOOLEAN) { + // // a single value as a conditional expression seems to act like an + // // implicit "=" + // // FIXME, what about row validators? + // val = BuiltinOperators.equals(val, ctx.getThisColumnValue()); + // } + + return val.getAsBoolean(); } @Override diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/expr/LongValue.java b/src/main/java/com/healthmarketscience/jackcess/impl/expr/LongValue.java index a85b7ff..8501082 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/expr/LongValue.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/expr/LongValue.java @@ -46,7 +46,7 @@ public class LongValue extends BaseNumericValue } @Override - public Boolean getAsBoolean() { + public boolean getAsBoolean() { return (_val.longValue() != 0L); } diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/expr/StringValue.java b/src/main/java/com/healthmarketscience/jackcess/impl/expr/StringValue.java index 5bbaa9d..ac3688d 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/expr/StringValue.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/expr/StringValue.java @@ -38,9 +38,9 @@ public class StringValue extends BaseValue } @Override - public Boolean getAsBoolean() { + public boolean getAsBoolean() { // ms access seems to treat strings as "true" - return Boolean.TRUE; + return true; } @Override