jscience
  1. jscience
  2. JSCIENCE-45

Measure equals() is not consistent with compareTo()

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: current
    • Fix Version/s: Version 6.0
    • Component/s: www
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      45

      Description

      This is relative to JScience v3.3-Beta (Feb. 12, 2007 build).

      Is it intentional that Measure equals() is not consistent with compareTo()?
      (Consistent as described in the Comparable interface's javadocs.)

      Whether "1000 m" should be equals to "1 km", does seem to have some non-obvious
      wrinkles. From a layman's viewpoint it would seem true would be the answer.
      However, from an OO techie's viewpoint, who knew that the two Measure objects
      have different unit values ("m" vs. "km"), false might be the answer.

      I mostly lean to the layman's viewpoint for a couple reasons. First, if I asked
      someone if 1000m was equal to 1km they would say yes. Second, having equals()
      and compareTo() be consistent is a desirable thing, and it seems that
      compareTo() should return 0 (equality). The second point does contain a degree
      of "self defining truism" in its reasoning.

      To support strict equality checks, there could be a different method for that
      (e.g. strictEquals() or something like that).

      I will attach a simple Java class as an example.

        Activity

        Hide
        shanmann added a comment -

        Created an attachment (id=4)
        Example of Measure equals() and compareTo() being inconsistent

        Show
        shanmann added a comment - Created an attachment (id=4) Example of Measure equals() and compareTo() being inconsistent
        Hide
        shanmann added a comment -

        I hadn't thought to look at javax.measure.quantities.Scalar<Q> when considering
        the Measure equals() and compareTo().

        I created a separate issue (#46) for Scalar's equals() and compareTo(),
        describing that its equals() ignores units, and that its equals() and
        compareTo() are not consistent.

        It seems desirable for Scalar and Measure to have conceptually equivalent
        implementations for equals() and compareTo().

        Hopefully this doesn't cause a major problem, especially with the javax.measure
        packages being prepared for JSR-275.

        Show
        shanmann added a comment - I hadn't thought to look at javax.measure.quantities.Scalar<Q> when considering the Measure equals() and compareTo(). I created a separate issue (#46) for Scalar's equals() and compareTo(), describing that its equals() ignores units, and that its equals() and compareTo() are not consistent. It seems desirable for Scalar and Measure to have conceptually equivalent implementations for equals() and compareTo(). Hopefully this doesn't cause a major problem, especially with the javax.measure packages being prepared for JSR-275.
        Hide
        dautelle added a comment -

        Under investigation will be fixed shortly.

        Show
        dautelle added a comment - Under investigation will be fixed shortly.
        Hide
        shanmann added a comment -

        It didn't come to mind when I submitted the original issue, that modifying the
        equals() implementation would likely trigger the need for an update to
        hashCode(). This would be done to maintain the equals/hashCode contract, where
        equal objects have equal hash codes (Javadocs for Object equals/hashCode).

        Show
        shanmann added a comment - It didn't come to mind when I submitted the original issue, that modifying the equals() implementation would likely trigger the need for an update to hashCode(). This would be done to maintain the equals/hashCode contract, where equal objects have equal hash codes (Javadocs for Object equals/hashCode).

          People

          • Assignee:
            jscience-issues
            Reporter:
            shanmann
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: