Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Ocl question- check string is an integer similar to Integer.parseInt(myString)?
Ocl question- check string is an integer similar to Integer.parseInt(myString)? [message #217449] Fri, 06 February 2009 12:12 Go to next message
Achilleas is currently offline AchilleasFriend
Messages: 88
Registered: July 2009
Member
Hi,

I would like to ask if there is any way to check if a String is an Integer
using an Ocl constraint.

For example in java you can do something like:
1. Integer.parseInt(myString) and catch the exception or
2. boolean isInteger = Pattern.matches("^\d*$", myString)

Is there any way to perform something similar to the above in OCL?

I tried to use something like self.value.oclIsTypeOf(Integer) but the
oclIsTypeOf property deals with the direct type of an object.
e.g. context Person
inv: self.oclIsTypeOf( Person ) -- is true
inv: self.oclIsTypeOf( Company) -- is false

I tried to use something like self.value.oclIsKindOf(Integer) but the
oclIsKindOf property determines whether value is either the direct type or
one of the supertypes of an object.

Any suggestions how this can be done?

Thanks,

Achilleas
Re: Ocl question- check string is an integer similar to Integer.parseInt(myString)? [message #217480 is a reply to message #217449] Fri, 06 February 2009 13:31 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.zeligsoft.com

Hi, Achilleas,

Try this:

not self.value.toInteger().oclIsInvalid()

This should check that conversion from String to Integer is feasible.

cW

Achilleas wrote:
> Hi,
>
> I would like to ask if there is any way to check if a String is an
> Integer using an Ocl constraint.
>
> For example in java you can do something like:
> 1. Integer.parseInt(myString) and catch the exception or 2. boolean
> isInteger = Pattern.matches("^\d*$", myString)
>
> Is there any way to perform something similar to the above in OCL?
> I tried to use something like self.value.oclIsTypeOf(Integer) but the
> oclIsTypeOf property deals with the direct type of an object.
> e.g. context Person
> inv: self.oclIsTypeOf( Person ) -- is true
> inv: self.oclIsTypeOf( Company) -- is false
>
> I tried to use something like self.value.oclIsKindOf(Integer) but the
> oclIsKindOf property determines whether value is either the direct type
> or one of the supertypes of an object.
>
> Any suggestions how this can be done?
>
> Thanks,
>
> Achilleas
>
>
>
>
Re: Ocl question- check string is an integer similar to Integer.parseInt(myString)? [message #217512 is a reply to message #217480] Fri, 06 February 2009 14:46 Go to previous message
Achilleas is currently offline AchilleasFriend
Messages: 88
Registered: July 2009
Member
Thanks Christian,

It works just fine.
Previous Topic:Changing a label to a dropdown menu
Next Topic:GMF mapping Audit Rules
Goto Forum:
  


Current Time: Fri Mar 05 04:42:10 GMT 2021

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

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

Back to the top