Operation of includes() operation [message #481862] |
Mon, 24 August 2009 15:19 |
Eclipse User |
|
|
|
Originally posted by: c.k.holmes.lboro.ac.uk
Hi,
I have a class containing an attribute of type String, when instantiated
I expect the attribute to take any (one) of the values 'A', 'B', or
'C'. I wrote a simple helper operation to check the value against the
set of allowable values, however the include() operation doesn't appear
to return the expected result, see simple example below:
operation MyClass anOp() : Boolean {
var allowableItems : Set(String) := Set{'A', 'B', 'C'};
var item : String := 'B';
return allowableItems.includes(item);
}
It doesn't appear to be an address pointer issue as I can set item to
allowableItems.first() and still anOp() returns false. I think the
operation is running the following query:
Set{'A', 'B', 'C'}.includes('B')
Hence I expected the result 'true'. What am I doing incorrectly?
Best Wishes
Chris
|
|
|
Re: Operation of includes() operation [message #481902 is a reply to message #481862] |
Mon, 24 August 2009 16:53 |
Dimitrios Kolovos Messages: 1776 Registered: July 2009 |
Senior Member |
|
|
Hi Chris,
This is a known issue that I've fixed in my working copy - but is still
under testing for regressions - and it also affects the count()
operation. As a workaround you can use the select() method as follows:
return allowableItems.selectOne(i|i = item).isDefined();
Cheers,
Dimitris
Chris Holmes wrote:
> Hi,
> I have a class containing an attribute of type String, when instantiated
> I expect the attribute to take any (one) of the values 'A', 'B', or
> 'C'. I wrote a simple helper operation to check the value against the
> set of allowable values, however the include() operation doesn't appear
> to return the expected result, see simple example below:
>
> operation MyClass anOp() : Boolean {
> var allowableItems : Set(String) := Set{'A', 'B', 'C'};
> var item : String := 'B';
> return allowableItems.includes(item);
> }
>
> It doesn't appear to be an address pointer issue as I can set item to
> allowableItems.first() and still anOp() returns false. I think the
> operation is running the following query:
> Set{'A', 'B', 'C'}.includes('B')
> Hence I expected the result 'true'. What am I doing incorrectly?
>
> Best Wishes
> Chris
|
|
|
Re: Operation of includes() operation [message #574803 is a reply to message #481862] |
Mon, 24 August 2009 16:53 |
Dimitrios Kolovos Messages: 1776 Registered: July 2009 |
Senior Member |
|
|
Hi Chris,
This is a known issue that I've fixed in my working copy - but is still
under testing for regressions - and it also affects the count()
operation. As a workaround you can use the select() method as follows:
return allowableItems.selectOne(i|i = item).isDefined();
Cheers,
Dimitris
Chris Holmes wrote:
> Hi,
> I have a class containing an attribute of type String, when instantiated
> I expect the attribute to take any (one) of the values 'A', 'B', or
> 'C'. I wrote a simple helper operation to check the value against the
> set of allowable values, however the include() operation doesn't appear
> to return the expected result, see simple example below:
>
> operation MyClass anOp() : Boolean {
> var allowableItems : Set(String) := Set{'A', 'B', 'C'};
> var item : String := 'B';
> return allowableItems.includes(item);
> }
>
> It doesn't appear to be an address pointer issue as I can set item to
> allowableItems.first() and still anOp() returns false. I think the
> operation is running the following query:
> Set{'A', 'B', 'C'}.includes('B')
> Hence I expected the result 'true'. What am I doing incorrectly?
>
> Best Wishes
> Chris
|
|
|
Powered by
FUDForum. Page generated in 0.02194 seconds