[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Orekit Users] Overloading of equals method
- To: orekit-users@orekit.org
- Subject: Re: [Orekit Users] Overloading of equals method
- From: "Carlos M. Casas Cuadrado" <carlos.marce@gmail.com>
- Date: Mon, 12 Mar 2012 15:01:17 +0000
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=XFtWBoL8jtY50Eujd+MLhjdAMXQ0vrPrwOOK+2rYDDs=; b=LNNlD/RJ46rFRX61tjOnjZJk2CA9/60n97a1Ucxos5NG8ix/sy7IdrE27oImLQM/fy C+uYsJsiTlKtp/+xsyzU+khYdIi3WQ4rndKvE4qXfZGkelMXr89JK6MyPhy5ZfREFaxH 5i5PEoBimic9jxFscMw5V/neWZNawkuFn1owJnWITwNor07Hymckljp+HcjHJLQIdANU G36ULu7lFKyVB6qRWz/JBTSeGi3q2woiB+W+U6ezbV7GRp42NaQSG+BZkZscZVujrmvt Zi0cklfvOBlImswRbaaWVPJci52fAUAJg//T99t+7FeY1Es3Qckoe2lQHdyYLqfXhGC7 QB7A==
- In-reply-to: <4F5DFE98.7020407@c-s.fr>
- References: <sympa.1331558590.26302.688@orekit.org> <4F5DFE98.7020407@c-s.fr>
Hello Luc,
thanks for your quick answer. I agree that objects which contain
double fields are difficult to compare. Nevertheless, you could still
compare them without using a threshold (bit to bit). This won't be
useful for objects whose fields are the result of a mathematical
operations, but still it will be useful for pure data handling
applications.
In my particular case, I have a regression test which checks that a
certain impulsive manoeuvre has been successfully read from a XML file
and loaded into an ImpulsiveManeuver object. Instead of checking the
result of each getter method in ImpulsiveManeuver, it would be more
convenient to create a reference ImpulsiveManeuver object, and
"equals" it against the object whose data is read from the file. In
this case, double comparisons should be exact since no operation has
been performed outside the class (and hopefully, the arguments of the
constructor have gone through the same operations within the class).
Code would look like:
ImpulsiveManeuver refMan = new ImpulsiveManeuver(...);
ImpulsiveManeuver xmlMan = readFromXML(...);
assert(refMan.equals(xmlMan));
I understand that you don't want to override the equals method because
of real field comparison, but leaving the default behaviour could also
be misleading (it took me some time to find out why the test was
failed). I couldn't find anything about this issue in the Orekit
documentation. If it's not already there, could you please add a
paragraph about it?
Regards,
Carlos.
On 12 March 2012 13:48, Luc Maisonobe <Luc.Maisonobe@c-s.fr> wrote:
> Le 12/03/2012 14:27, carlos.marce@gmail.com a écrit :
>> Hi,
>
> Hello Carlos,
>
>> I just realised that some classes in Orekit don't override the equals method.
>> This makes difficult the comparisson of two different objects (i.e. for
>> regression testing). Do you plan on adding this in the future?
>
> It depends on the class. Typically, classes that have some primitive
> double fields are difficult to compare. Any code change, regardless of
> the fact it is minor or not (just think about replacing a + (b+c) by
> (a+b) + c) may slightly change the least significant bits. Using exact
> comparison would therefore fail despite the change should be considered
> acceptable. On the other hand, using some threshold for equality is
> difficult has a difference that would be considered as acceptable in one
> context may be too large in another one (typically, two orbits differing
> in position by 1m would be considered the same in station keeping for a
> regular mission, but different for precise orbit determination
> applications like altimetry missions). The equals method does not allow
> user providing a threshold parameter.
>
> So we implemented equals scarcely, in some limited cases. We implemented
> it for AbsoluteDate, we did not implement it for Orbit.
>
> For such "difficult" classes, I would recommend using something more
> robust for regression testing. Equals is clearly not sufficient.
>
> For which class would you need an equals method ?
>
> best regards,
> Luc
>
>> Regards.
>>
>