Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » difflrents instances(how to verify constraint)
difflrents instances [message #1755580] Mon, 06 March 2017 02:48 Go to next message
khalid nasr is currently offline khalid nasrFriend
Messages: 23
Registered: March 2017
Junior Member
hi


I have a problem of verfier that all the instances of a meta class are disctinct, please if you could correct me the code that I put in places but that does not work.
***********************
public boolean valid() {
// TODO: implement this method
// Ensure that you remove @generated or mark it @generated NOT
EList<tp1.Type> types= this.getChildren();
for (int i = 0; i < types.size(); i++)
{
for (int j = 1; j < i; j++)
{
Object o1 = types.get(i);
Object o2 = types.get(j);
getChildren().equals(o2);

if (o1.equals(o2))
{
return false;
} }}
return true;
*****************************

And for the test I use the following code that calls the function Valid ()

******************
public void testValid() {
// TODO: implement this operation test method
// Ensure that you remove @generated or mark it @generated NOT
URI fileURI= URI.createFileURI("E:/runtime-EclipseApplication/mymodel/monmodel.tp1");
ResourceSet resourceSet= new ResourceSetImpl();
Resource resource= resourceSet.getResource(fileURI,true);
try{
resource.load(null);
}
catch(IOException e){
e.printStackTrace();}
if(resource.isLoaded() && resource.getContents().size()>0)
{
simplemodel mm=(simplemodel) resource.getContents().get(0);
if(mm.valid())
{
System.out.println("valid");
}
else{
System.out.println("non valide");}
}}

//fail();
}
************************************
thank you in advance



Re: difflrents instances [message #1755583 is a reply to message #1755580] Mon, 06 March 2017 05:46 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Given that EObject implementations must not override .equals and that all EObject containing lists must have unique contents, there will never be duplicates. You can use EcoreUtil.equals to test for structural equality. Of course your loops don't properly compare every pair of objects either.

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: difflrents instances [message #1755658 is a reply to message #1755583] Mon, 06 March 2017 16:09 Go to previous messageGo to next message
khalid nasr is currently offline khalid nasrFriend
Messages: 23
Registered: March 2017
Junior Member
No Message Body

[Updated on: Fri, 24 March 2017 20:55]

Report message to a moderator

Re: difflrents instances [message #1755664 is a reply to message #1755658] Mon, 06 March 2017 16:29 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

As Ed M pointed out, all objects are inherently distinct by the memory address criterion.

What is your criterion for distinct/unique?

If for instance you require a name property to be distinct, then you need to code that as part of your equivalence testing method.

Regards

Ed Willink
Re: difflrents instances [message #1755665 is a reply to message #1755664] Mon, 06 March 2017 16:59 Go to previous messageGo to next message
khalid nasr is currently offline khalid nasrFriend
Messages: 23
Registered: March 2017
Junior Member
I send you a image that can give you an idea of what I want

in the example gg is a duplicate instance
  • Attachment: exp.JPG
    (Size: 16.27KB, Downloaded 99 times)

[Updated on: Mon, 06 March 2017 17:01]

Report message to a moderator

Re: difflrents instances [message #1755666 is a reply to message #1755665] Mon, 06 March 2017 17:04 Go to previous messageGo to next message
khalid nasr is currently offline khalid nasrFriend
Messages: 23
Registered: March 2017
Junior Member
No Message Body

[Updated on: Fri, 24 March 2017 20:56]

Report message to a moderator

Re: difflrents instances [message #1755669 is a reply to message #1755666] Mon, 06 March 2017 17:26 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Ok so you need to check that getTName() is distinct. But what is a TName? Your earlier example suggests that it is an Object, so your earlier use of "==" should work. Much more likely a TName is a String, which you have not interned, so you must use "equals()".

Regards

Ed Willink
Re: difflrents instances [message #1755679 is a reply to message #1755669] Mon, 06 March 2017 19:03 Go to previous messageGo to next message
khalid nasr is currently offline khalid nasrFriend
Messages: 23
Registered: March 2017
Junior Member
TName is an attribute of the class Type
i Sent you The meta-model

thanks for All

[Updated on: Fri, 24 March 2017 20:54]

Report message to a moderator

Re: difflrents instances [message #1755684 is a reply to message #1755679] Mon, 06 March 2017 19:26 Go to previous messageGo to next message
khalid nasr is currently offline khalid nasrFriend
Messages: 23
Registered: March 2017
Junior Member
thanks every body for help

specially Merks and Willink

and sorry of may very bad english
I finaly did it
now is ok

[Updated on: Mon, 06 March 2017 19:29]

Report message to a moderator

Re: difflrents instances [message #1755706 is a reply to message #1755684] Tue, 07 March 2017 06:50 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Note that you might be able to express your constraint directly in the Ecore model. I.e., each EReference has a key's feature that you can populate with zero one or more attributes of the referenced EClass. The EObjectValidator will validate that the combination of these keys is unique among all instances by that reference's value.

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: difflrents instances [message #1756105 is a reply to message #1755706] Sat, 11 March 2017 11:59 Go to previous message
khalid nasr is currently offline khalid nasrFriend
Messages: 23
Registered: March 2017
Junior Member
Thanks MERKERS i didnot know that

I will Tray that

Previous Topic:[Validation] ConstraintProxy and currentConstraintData
Next Topic:strange behavior in my dsl editor
Goto Forum:
  


Current Time: Fri Mar 29 06:08:31 GMT 2024

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

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

Back to the top