This is correct. Each step of the recalculation results in an update so there will be N-1 updates where N is the number of members in the Group.
It will match, but only if 2.0 is actually 2.0. The way that floating point numbers are represented, not every possible floating point value can be represented. Consequently when you have a value that can’t be represented (e.g. 9.2) you end up with a value that is really close to 9.2. But all those little errors can add up so it’s really easy if you’ve done a calculation where you have the value 2.0000003 instead of 2.0 and if you use == to the integer 2 it will return false. This is why, as a general rule, == and != should never be used with floating point numbers except in cases where the floating point number is rounded first.
In this case though, dancemichi is right. The state of the Group that get’s calculated should exactly match the state of one of the Items because there isn’t any math taking place. It just postUpdate’s the Group’s state with the state from the min Item. I don’t think a conversion or the like is at play here.
Almost, but I’m a tricky deamon. You have to get my name exactly right.
The error doesn’t make a whole lot of sense to me. If findFirst doesn’t find a match, it returns null, not void. How did you declare cheapestItem? Did you give it’s type? The type of the variable get’s defined either explicitly, or by inferring the type based on the value that get’s passed to it when it get’s declared.
If you declare:
I think cheapestItem’s type will be void since you didn’t give the language any other idea about what type it should be.
var cheapestItem = null
I’m not sure what type cheapestItem will be. I don’t think it will be void but it doesn’t have anything else to infer a type. Maybe it would be Object.
In order to set the type correctly you need to supply it. Either
var NumberItem cheapestItem
var cheapeastItem = gSpritpreise.members.findFirst[ p | p.state == gSpritpreise.state ] as NumberItem
Both of these lines tell the Rules engine that cheapestItem needs to be a NumberItem.
on instance: null
This error is somewhat misleading. When the Rules Engine in unable to convert the type of a variable to one appropriate for the operation you are trying to do, a null exception is generated. Thus, it doesn’t necessarily mean that the findFirst failed to return a value . It could be the value returned cannot be used with the + operator.
I would expect
val cheapestItem = gSpritpreise.members.findFirst[ p | p.state == gSpritpreise.state ] as NumberItem