|
I was wondering if there was a reason that the EntityComparisonOperator methods "compareEqual" and "compareNotEqual" both take a Comparable argument but don't use that object's compareTo() method - instead they use equals().
I ran into the problem where: EntityComparisonOperator.compareEqual(BigDecimal.ZERO.setScale(6), BigDecimal.ZERO) returns false… because BigDecimal's equals() method requires the scale to be the same. I believe I encountered this when using a view entity which sums a BigDecimal column, then trying to filter the results using a condition: List<EntityCondition> conditionList = Lists.newArrayList(); conditionList.add(EntityCondition.makeCondition("quantityNotAvailable", EntityOperator.EQUALS, null)); conditionList.add(EntityCondition.makeCondition("quantityNotAvailable", EntityOperator.EQUALS, BigDecimal.ZERO)); EntityCondition condition = EntityCondition.makeCondition(quantityNotAvailableConditionList, EntityOperator.OR); In the cases where quantityNotAvailable is zero (technically "0.000000"), EntityCondition.makeCondition("quantityNotAvailable", EntityOperator.EQUALS, BigDecimal.ZERO) will return false. |
|
That sounds like a good change to make.
Adrian Crum Sandglass Software www.sandglass-software.com On 9/28/2013 8:27 AM, J. Eckard wrote: > I was wondering if there was a reason that the EntityComparisonOperator methods "compareEqual" and "compareNotEqual" both take a Comparable argument but don't use that object's compareTo() method - instead they use equals(). > > I ran into the problem where: > > EntityComparisonOperator.compareEqual(BigDecimal.ZERO.setScale(6), BigDecimal.ZERO) > > returns false… because BigDecimal's equals() method requires the scale to be the same. > > > I believe I encountered this when using a view entity which sums a BigDecimal column, then trying to filter the results using a condition: > > List<EntityCondition> conditionList = Lists.newArrayList(); > conditionList.add(EntityCondition.makeCondition("quantityNotAvailable", EntityOperator.EQUALS, null)); > conditionList.add(EntityCondition.makeCondition("quantityNotAvailable", EntityOperator.EQUALS, BigDecimal.ZERO)); > EntityCondition condition = EntityCondition.makeCondition(quantityNotAvailableConditionList, EntityOperator.OR); > > In the cases where quantityNotAvailable is zero (technically "0.000000"), > > EntityCondition.makeCondition("quantityNotAvailable", EntityOperator.EQUALS, BigDecimal.ZERO) > > will return false. > |
|
Administrator
|
+1, I can't see any reasons to not doing so
Jacques Adrian Crum wrote: > That sounds like a good change to make. > > Adrian Crum > Sandglass Software > www.sandglass-software.com > > On 9/28/2013 8:27 AM, J. Eckard wrote: >> I was wondering if there was a reason that the EntityComparisonOperator methods "compareEqual" and "compareNotEqual" both take a >> Comparable argument but don't use that object's compareTo() method - instead they use equals(). >> >> I ran into the problem where: >> >> EntityComparisonOperator.compareEqual(BigDecimal.ZERO.setScale(6), BigDecimal.ZERO) >> >> returns false… because BigDecimal's equals() method requires the scale to be the same. >> >> >> I believe I encountered this when using a view entity which sums a BigDecimal column, then trying to filter the results using a >> condition: >> >> List<EntityCondition> conditionList = Lists.newArrayList(); >> conditionList.add(EntityCondition.makeCondition("quantityNotAvailable", EntityOperator.EQUALS, null)); >> conditionList.add(EntityCondition.makeCondition("quantityNotAvailable", EntityOperator.EQUALS, BigDecimal.ZERO)); >> EntityCondition condition = EntityCondition.makeCondition(quantityNotAvailableConditionList, EntityOperator.OR); >> >> In the cases where quantityNotAvailable is zero (technically "0.000000"), >> >> EntityCondition.makeCondition("quantityNotAvailable", EntityOperator.EQUALS, BigDecimal.ZERO) >> >> will return false. |
| Free forum by Nabble | Edit this page |
