EntityComparisonOperator's compareEqual / compareNotEqual

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

EntityComparisonOperator's compareEqual / compareNotEqual

J. Eckard-2
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.

Reply | Threaded
Open this post in threaded view
|

Re: EntityComparisonOperator's compareEqual / compareNotEqual

Adrian Crum-3
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.
>
Reply | Threaded
Open this post in threaded view
|

Re: EntityComparisonOperator's compareEqual / compareNotEqual

Jacques Le Roux
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.