Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EDataTypeImpl equality?
EDataTypeImpl equality? [message #425598] Wed, 03 December 2008 03:15 Go to next message
Bryan Hunt is currently offline Bryan HuntFriend
Messages: 366
Registered: July 2009
Senior Member
The following code fails (it throws the exception) because the
parameter type instance is not the same as the simple value type. The
types are equivalent - both are EString.

SimpleAnyType simpleValue = (SimpleAnyType) value;

if(!parameter.getType().equals(simpleValue.getInstanceType() ))
throw new WorkflowRuntimeException("Expected type: " +
parameter.getType() + " but found type: " +
simpleValue.getInstanceType());

My current fix is:

SimpleAnyType simpleValue = (SimpleAnyType) value;

if(!parameter.getType().getInstanceClass().equals(simpleValu e.getInstanceType().getInstanceClass()))
throw

new WorkflowRuntimeException("Expected type: " + parameter.getType() +
" but found type: " + simpleValue.getInstanceType());

Is there a reason for EDataTypeImpl to not overload equals()? Also, is
my fix to compare the instanceClass the best solution?

Bryan
Re: EDataTypeImpl equality? [message #425603 is a reply to message #425598] Wed, 03 December 2008 11:48 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------060601070308030405030009
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Bryan,

Comments below.

Bryan Hunt wrote:
> The following code fails (it throws the exception) because the
> parameter type instance is not the same as the simple value type. The
> types are equivalent - both are EString.
>
> SimpleAnyType simpleValue = (SimpleAnyType) value;
>
> if(!parameter.getType().equals(simpleValue.getInstanceType() ))
> throw new WorkflowRuntimeException("Expected type: " +
> parameter.getType() + " but found type: " +
> simpleValue.getInstanceType());
>
> My current fix is:
>
> SimpleAnyType simpleValue = (SimpleAnyType) value;
>
> if(!parameter.getType().getInstanceClass().equals(simpleValu e.getInstanceType().getInstanceClass()))
>
> throw
> new WorkflowRuntimeException("Expected type: " + parameter.getType() +
> " but found type: " + simpleValue.getInstanceType());
>
> Is there a reason for EDataTypeImpl to not overload equals()?
One reason is that fact that it's an EObject which states that:

* The framework also assumes that implementations will not
specialize {@link #equals(Object)} (nor {@link #hashCode()})
* so that "<code>==</code>" can be always used for equality testing;
* {@link org.eclipse.emf.ecore.util.EcoreUtil#equals(EObject,
EObject) EcoreUtil.equals} should be used for doing structural
equality testing.

Consider for example that XMLTypePackage's HEX_BINARY and BASE64_BINARY
are both byte[] but represent those bytes differently in string form.
Should they be considered equals?
> Also, is my fix to compare the instanceClass the best solution?
Probably I need more context to answer why parameter.getType() !=
simpleValue.getInstanceType() is insufficient. I.e., why are the types
different. What kinds of type differences are acceptable? Is
parameter.getType().isInstance(simpleValue.getValue()) good enough? Or
perhaps Diagnostician.INSTANCE.validate(parameter.getType(),
simpleValue.getValue()) is needed to ensure that any constraints on the
value are enforced...
>
> Bryan
>

--------------060601070308030405030009
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Bryan,<br>
<br>
Comments below.<br>
<br>
Bryan Hunt wrote:
<blockquote cite="mid:gh4tko$jji$1@build.eclipse.org" type="cite">The
following code fails (it throws the exception) because the parameter
type instance is not the same as the simple value type.&nbsp; The types are
equivalent - both are EString.
<br>
<br>
SimpleAnyType simpleValue = (SimpleAnyType) value;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; <br>
if(!parameter.getType().equals(simpleValue.getInstanceType() ))
<br>
&nbsp;&nbsp;&nbsp;&nbsp;throw new WorkflowRuntimeException("Expected type: " +
parameter.getType() + " but found type: " +
simpleValue.getInstanceType());
<br>
<br>
My current fix is:
<br>
<br>
SimpleAnyType simpleValue = (SimpleAnyType) value;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; <br>
if(!parameter.getType().getInstanceClass().equals(simpleValu e.getInstanceType().getInstanceClass()))
<br>
&nbsp;&nbsp;&nbsp;&nbsp;throw <br>
new WorkflowRuntimeException("Expected type: " + parameter.getType() +
" but found type: " + simpleValue.getInstanceType());
<br>
<br>
Is there a reason for EDataTypeImpl to not overload equals()?&nbsp; </blockquote>
One reason is that fact that it's an EObject which states that:<br>
<blockquote>&nbsp;* The framework also assumes that implementations will not
specialize {@link #equals(Object)} (nor {@link #hashCode()})<br>
&nbsp;* so that "&lt;code&gt;==&lt;/code&gt;" can be always used for
equality testing;<br>
&nbsp;* {@link org.eclipse.emf.ecore.util.EcoreUtil#equals(EObject, EObject)
EcoreUtil.equals} should be used for doing structural equality testing.<br>
</blockquote>
Consider for example that XMLTypePackage's HEX_BINARY and BASE64_BINARY
are both byte[] but represent those bytes differently in string form.&nbsp;
Should they be considered equals?<br>
<blockquote cite="mid:gh4tko$jji$1@build.eclipse.org" type="cite">Also,
is my fix to compare the instanceClass the best solution?
<br>
</blockquote>
Probably I need more context to answer why parameter.getType() !=
simpleValue.getInstanceType() is insufficient.&nbsp; I.e., why are the types
different.&nbsp; What kinds of type differences are acceptable?&nbsp; Is
parameter.getType().isInstance(simpleValue.getValue()) good enough?&nbsp; Or
perhaps Diagnostician.INSTANCE.validate(parameter.getType(),
simpleValue.getValue()) is needed to ensure that any constraints on the
value are enforced...<br>
<blockquote cite="mid:gh4tko$jji$1@build.eclipse.org" type="cite"><br>
Bryan
<br>
<br>
</blockquote>
</body>
</html>

--------------060601070308030405030009--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EDataTypeImpl equality? [message #425659 is a reply to message #425603] Thu, 04 December 2008 01:29 Go to previous message
Bryan Hunt is currently offline Bryan HuntFriend
Messages: 366
Registered: July 2009
Senior Member
Ed,

After looking at the code again, I decided that the check wasn't really
providing much value, so I've removed it altogether.

Bryan

On 2008-12-03 05:48:30 -0600, Ed Merks <Ed.Merks@gmail.com> said:

>
> Bryan,
>
> Comments below.
>
> Bryan Hunt wrote:
>> The following code fails (it throws the exception) because the
>> parameter type instance is not the same as the simple value type. The
>> types are equivalent - both are EString.
>>
>> SimpleAnyType simpleValue = (SimpleAnyType) value;
>>
>> if(!parameter.getType().equals(simpleValue.getInstanceType() ))
>> throw new WorkflowRuntimeException("Expected type: " +
>> parameter.getType() + " but found type: " +
>> simpleValue.getInstanceType());
>>
>> My current fix is:
>>
>> SimpleAnyType simpleValue = (SimpleAnyType) value;
>>
>> if(!parameter.getType().getInstanceClass().equals(simpleValu e.getInstanceType().getInstanceClass()))

throw
new
>>
>> WorkflowRuntimeException("Expected type: " + parameter.getType() +
>> " but found type: " + simpleValue.getInstanceType());
>>
>> Is there a reason for EDataTypeImpl to not overload equals()?
> One reason is that fact that it's an EObject which states that:
>
> * The framework also assumes that implementations will not
> specialize {@link #equals(Object)} (nor {@link #hashCode()})
> * so that "<code>==</code>" can be always used for equality testing;
> * {@link org.eclipse.emf.ecore.util.EcoreUtil#equals(EObject,
> EObject) EcoreUtil.equals} should be used for doing structural
> equality testing.
>
> Consider for example that XMLTypePackage's HEX_BINARY and BASE64_BINARY
> are both byte[] but represent those bytes differently in string form.
> Should they be considered equals?
>> Also, is my fix to compare the instanceClass the best solution?
> Probably I need more context to answer why parameter.getType() !=
> simpleValue.getInstanceType() is insufficient. I.e., why are the types
> different. What kinds of type differences are acceptable? Is
> parameter.getType().isInstance(simpleValue.getValue()) good enough? Or
> perhaps Diagnostician.INSTANCE.validate(parameter.getType(),
> simpleValue.getValue()) is needed to ensure that any constraints on the
> value are enforced...
>>
>> Bryan
>>
>
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> <html>
> <head>
> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
> </head>
> <body bgcolor="#ffffff" text="#000000">
> Bryan,<br>
> <br>
> Comments below.<br>
> <br>
> Bryan Hunt wrote:
> <blockquote cite="mid:gh4tko$jji$1@build.eclipse.org" type="cite">The
> following code fails (it throws the exception) because the parameter
> type instance is not the same as the simple value type.&nbsp; The types are
> equivalent - both are EString.
> <br>
> <br>
> SimpleAnyType simpleValue = (SimpleAnyType) value;
> <br>
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; <br>
> if(!parameter.getType().equals(simpleValue.getInstanceType() ))
> <br>
> &nbsp;&nbsp;&nbsp;&nbsp;throw new WorkflowRuntimeException("Expected type: " +
> parameter.getType() + " but found type: " +
> simpleValue.getInstanceType());
> <br>
> <br>
> My current fix is:
> <br>
> <br>
> SimpleAnyType simpleValue = (SimpleAnyType) value;
> <br>
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; <br>
> if(!parameter.getType().getInstanceClass().equals(simpleValu e.getInstanceType().getInstanceClass()))

>
> <br>
> &nbsp;&nbsp;&nbsp;&nbsp;throw <br>
> new WorkflowRuntimeException("Expected type: " + parameter.getType() +
> " but found type: " + simpleValue.getInstanceType());
> <br>
> <br>
> Is there a reason for EDataTypeImpl to not overload equals()?&nbsp;
> </blockquote>
> One reason is that fact that it's an EObject which states that:<br>
> <blockquote>&nbsp;* The framework also assumes that implementations will not
> specialize {@link #equals(Object)} (nor {@link #hashCode()})<br>
> &nbsp;* so that "&lt;code&gt;==&lt;/code&gt;" can be always used for
> equality testing;<br>
> &nbsp;* {@link org.eclipse.emf.ecore.util.EcoreUtil#equals(EObject, EObject)
> EcoreUtil.equals} should be used for doing structural equality testing.<br>
> </blockquote>
> Consider for example that XMLTypePackage's HEX_BINARY and BASE64_BINARY
> are both byte[] but represent those bytes differently in string form.&nbsp;
> Should they be considered equals?<br>
> <blockquote cite="mid:gh4tko$jji$1@build.eclipse.org" type="cite">Also,
> is my fix to compare the instanceClass the best solution?
> <br>
> </blockquote>
> Probably I need more context to answer why parameter.getType() !=
> simpleValue.getInstanceType() is insufficient.&nbsp; I.e., why are the types
> different.&nbsp; What kinds of type differences are acceptable?&nbsp; Is
> parameter.getType().isInstance(simpleValue.getValue()) good enough?&nbsp; Or
> perhaps Diagnostician.INSTANCE.validate(parameter.getType(),
> simpleValue.getValue()) is needed to ensure that any constraints on the
> value are enforced...<br>
> <blockquote cite="mid:gh4tko$jji$1@build.eclipse.org" type="cite"><br>
> Bryan
> <br>
> <br>
> </blockquote>
> </body>
> </html>
Previous Topic:How do I structure a large .ecore model?
Next Topic:EDataType and Resource
Goto Forum:
  


Current Time: Thu Apr 25 01:55:28 GMT 2024

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

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

Back to the top