|
Re: EDataTypeImpl equality? [message #425603 is a reply to message #425598] |
Wed, 03 December 2008 11:48 |
Ed Merks 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. The types are
equivalent - both are EString.
<br>
<br>
SimpleAnyType simpleValue = (SimpleAnyType) value;
<br>
<br>
if(!parameter.getType().equals(simpleValue.getInstanceType() ))
<br>
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>
<br>
if(!parameter.getType().getInstanceClass().equals(simpleValu e.getInstanceType().getInstanceClass()))
<br>
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()? </blockquote>
One reason is that fact that it's an EObject which states that:<br>
<blockquote> * The framework also assumes that implementations will not
specialize {@link #equals(Object)} (nor {@link #hashCode()})<br>
* so that "<code>==</code>" can be always used for
equality testing;<br>
* {@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.
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. 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...<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 |
Bryan Hunt 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. The types are
> equivalent - both are EString.
> <br>
> <br>
> SimpleAnyType simpleValue = (SimpleAnyType) value;
> <br>
> <br>
> if(!parameter.getType().equals(simpleValue.getInstanceType() ))
> <br>
> 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>
> <br>
> if(!parameter.getType().getInstanceClass().equals(simpleValu e.getInstanceType().getInstanceClass()))
>
> <br>
> 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()?
> </blockquote>
> One reason is that fact that it's an EObject which states that:<br>
> <blockquote> * The framework also assumes that implementations will not
> specialize {@link #equals(Object)} (nor {@link #hashCode()})<br>
> * so that "<code>==</code>" can be always used for
> equality testing;<br>
> * {@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.
> 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. 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...<br>
> <blockquote cite="mid:gh4tko$jji$1@build.eclipse.org" type="cite"><br>
> Bryan
> <br>
> <br>
> </blockquote>
> </body>
> </html>
|
|
|
Powered by
FUDForum. Page generated in 0.03031 seconds