Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » OCL constraint: blank character in a string(OCL constraint that checks the blank character in a string)
OCL constraint: blank character in a string [message #533329] Thu, 13 May 2010 12:14 Go to next message
Esin Karabacakoglu is currently offline Esin Karabacakoglu
Messages: 11
Registered: May 2010
Location: Turkey
Junior Member
Hi there,

I have a trouble in an OCL constraint that checks the blank characters in a string. I cannot write a constraint using the operations defined on OCL String. Following constraint is not working either. Could anyone help me?

 " not (self.name->includes(' ')) "


....

[Updated on: Thu, 13 May 2010 12:15]

Report message to a moderator

Re: OCL constraint [message #533765 is a reply to message #533329] Sun, 16 May 2010 20:43 Go to previous messageGo to next message
Eclipse User
Originally posted by: Alexander.Igdalov.gmail.com

Hi Esin,

I would recommend you to write this operation in Java. Refer to
"Customizing the Environment" section of the OCL Developer Guide (in
Help) for details.


Your statement
> " not (self.name->includes(' ')) "

doesn't check for spaces but converts a String (i.e. self.name) to a Set
of Strings containing one element (self.name) and attempts to find a
String equal to ' '.

HTH,
- Alex.

esin wrote:
> Hi there,
>
> I have a trouble in an OCL constraint that checks the blank characters
> in a string. I cannot write a constraint using the operations defined on
> OCL String. Following constraint is not working either. Could anyone
> help me?
>
>
> " not (self.name->includes(' ')) "
>
>
> ...
Re: OCL constraint [message #533773 is a reply to message #533329] Sun, 16 May 2010 21:20 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4116
Registered: July 2009
Senior Member
Hi esin

OCL 2.2 adds

String::characters() : Sequence(String)

which breaks a String up into one chaacer per String allowing you to do
what you want.

Unfortunately MDT/OCL does not yet support this function. Should be in
MDT/OCL 4.0.0.

For now, as Alex suggested, you need Java, which will also be much
easier in MDT/OCL 4.0.0.

Regards

Ed Willink

On 13/05/2010 13:14, esin wrote:
> Hi there,
>
> I have a trouble in an OCL constraint that checks the blank characters
> in a string. I cannot write a constraint using the operations defined on
> OCL String. Following constraint is not working either. Could anyone
> help me?
>
>
> " not (self.name->includes(' ')) "
>
>
> ....
Re: OCL constraint [message #533921 is a reply to message #533329] Mon, 17 May 2010 13:28 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. Damus
Messages: 809
Registered: July 2009
Senior Member
Hi, all,

A less pleasant-looking alternative to Java is:

(1..self.name.size())->collect(i |
self.name.substring(i, i))->excludes(' ')

which basically includes an expansion of the OCL 2.2 characters() operation.

:-)

Christian


On 13/05/10 08:14 AM, esin wrote:
> Hi there,
>
> I have a trouble in an OCL constraint that checks the blank characters
> in a string. I cannot write a constraint using the operations defined on
> OCL String. Following constraint is not working either. Could anyone
> help me?
>
>
> " not (self.name->includes(' ')) "
>
>
> ...
Re: OCL constraint [message #533935 is a reply to message #533921] Mon, 17 May 2010 14:06 Go to previous messageGo to next message
Eclipse User
Originally posted by: Alexander.Igdalov.gmail.com

Cool! That's what an expert advice is!

Christian W. Damus wrote:
> Hi, all,
>
> A less pleasant-looking alternative to Java is:
>
> (1..self.name.size())->collect(i |
> self.name.substring(i, i))->excludes(' ')
>
> which basically includes an expansion of the OCL 2.2 characters()
> operation.
>
> :-)
>
> Christian
>
>
> On 13/05/10 08:14 AM, esin wrote:
>> Hi there,
>>
>> I have a trouble in an OCL constraint that checks the blank characters
>> in a string. I cannot write a constraint using the operations defined on
>> OCL String. Following constraint is not working either. Could anyone
>> help me?
>>
>>
>> " not (self.name->includes(' ')) "
>>
>>
>> ...
>
Re: OCL constraint [message #533946 is a reply to message #533921] Mon, 17 May 2010 14:27 Go to previous message
Esin Karabacakoglu is currently offline Esin Karabacakoglu
Messages: 11
Registered: May 2010
Location: Turkey
Junior Member
Hi all,

Thanks for your replies. With the helps of all you, i solved my problem. And here is the solution:

Sequence{1..self.name.size()}->collect(i |self.name.substring(i, i))->excludes(' ')

Previous Topic:Re: EAnnotations and their contents
Next Topic:Add Pacakge imports to the OclParser
Goto Forum:
  


Current Time: Sat Nov 01 13:29:43 GMT 2014

Powered by FUDForum. Page generated in 0.02777 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software