|
Re: Is it possible to change sum() behavior? [message #38787 is a reply to message #38719] |
Wed, 26 September 2007 13:48 |
Eclipse User |
|
|
|
Originally posted by: cdamus.ca.ibm.com
Hi, Hao,
If you expect to find at most one commodity whose id is 'aaa', then you
might find the "any" iterator to be convenient:
Commodity.allInstances()->any(id='aaa').weight
which will give you a weight or else OclInvalid if there is no such
commodity. (OclInvalid returns true to an oclIsUndefined() test just as
null does).
However, that's all beside the point, because the sum of an empty collection
of integers is supposed to be zero, not null. The specification of this
operation makes that clear.
Would you mind raising a bug? That would be better than asking you to work
around this with a custom EvaluationEnvironment implementation, which would
be feasible but shouldn't be necessary.
Thanks,
Christian
Hao Zhang wrote:
> Hi,
>
> I found evaluating following expression would returns null:
>
> Commodity.allInstances()->select(id='aaa').weight->sum()
>
> if there is no commodity whose id is "aaa". I'm wondering whether it is
> possible to let above expression returns Integer 0 rather than null, so
> that I can safely evaluate this expression:
>
> Commodity.allInstances()->select(id='aaa').weight->sum() > 0
>
> otherwise evaluating above expression would result an exception. Of course
> I can write following expression to judge whether the set is empty, but it
> is somehow too complex:
>
> let coms:Set(Commodity) = Commodity.allInstances()->select(id='aaa')
> in
> not coms->isEmpty() and coms.weight->sum()>0
>
> Can I archive this by customizing the environment, or there is other
> recommended way for this situation?
>
> Regards,
> Hao
|
|
|
Re: Is it possible to change sum() behavior? [message #39226 is a reply to message #38787] |
Thu, 27 September 2007 01:43 |
Hao Zhang Messages: 161 Registered: July 2009 |
Senior Member |
|
|
I created
https://bugs.eclipse.org/bugs/show_bug.cgi?id=204753
Thanks for your instruction.
"Christian W. Damus" <cdamus@ca.ibm.com>
??????:fddnut$6la$1@build.eclipse.org...
> Hi, Hao,
>
> If you expect to find at most one commodity whose id is 'aaa', then you
> might find the "any" iterator to be convenient:
>
> Commodity.allInstances()->any(id='aaa').weight
>
> which will give you a weight or else OclInvalid if there is no such
> commodity. (OclInvalid returns true to an oclIsUndefined() test just as
> null does).
>
> However, that's all beside the point, because the sum of an empty
> collection
> of integers is supposed to be zero, not null. The specification of this
> operation makes that clear.
>
> Would you mind raising a bug? That would be better than asking you to
> work
> around this with a custom EvaluationEnvironment implementation, which
> would
> be feasible but shouldn't be necessary.
>
> Thanks,
>
> Christian
>
>
> Hao Zhang wrote:
>
>> Hi,
>>
>> I found evaluating following expression would returns null:
>>
>> Commodity.allInstances()->select(id='aaa').weight->sum()
>>
>> if there is no commodity whose id is "aaa". I'm wondering whether it is
>> possible to let above expression returns Integer 0 rather than null, so
>> that I can safely evaluate this expression:
>>
>> Commodity.allInstances()->select(id='aaa').weight->sum() > 0
>>
>> otherwise evaluating above expression would result an exception. Of
>> course
>> I can write following expression to judge whether the set is empty, but
>> it
>> is somehow too complex:
>>
>> let coms:Set(Commodity) = Commodity.allInstances()->select(id='aaa')
>> in
>> not coms->isEmpty() and coms.weight->sum()>0
>>
>> Can I archive this by customizing the environment, or there is other
>> recommended way for this situation?
>>
>> Regards,
>> Hao
>
|
|
|
Powered by
FUDForum. Page generated in 0.03344 seconds