Skip to content

OGCGeometry.equals #110

Closed
Closed

Description

@randallwhitman

Let me know if there is something wrong with the following test, but I think it indicates an issue with OGCGeometry.equals(Object).

    public void testEquals() {
        Point pt = new Point(15.0, 5.0);
        // For comparison/reference
        assertEquals(new MapGeometry(pt, null), new MapGeometry(pt, null));
        assertEquals(new MapGeometry(new Point(1.0, 2.0), null), new MapGeometry(new Point(1.0, 2.0), null));
        // Test OGCGeometry#equals
        assertTrue(OGCGeometry.createFromEsriGeometry(pt, null).equals(OGCGeometry.createFromEsriGeometry(pt, null)));  // ok
        assertEquals(OGCGeometry.createFromEsriGeometry(pt, null), OGCGeometry.createFromEsriGeometry(pt, null));  // fail
        assertEquals(OGCGeometry.createFromEsriGeometry(new Point(1.0, 2.0), null), OGCGeometry.createFromEsriGeometry(new Point(1.0, 2.0), null));  // fail

    }

Maybe need OGCGeometry.equals(Object) similar to that of MapGeometry, such as:

    @Override
    public boolean equals(Object other) {
        if (other == this)
            return true;
        if (other == null  ||  other.getClass() != getClass())
            return false;
        return equals((OGCGeometry)other);
    }

(Ran across this issue while writing unit tests for JSON SerDe classes in Spatial-Framework-for-Hadoop.)

Activity

  1. randallwhitman commented on Mar 9, 2016

    @randallwhitman
    ContributorAuthor

    As mentioned in the incomplete patch, it would then also need hashCode.

  2. stolstov commented on Mar 9, 2016

    @stolstov
    Member

    @randallwhitman I have different fix in the full version. Note that the OGC equals is not same as java equals. Java equals is identity comparison, while OGC equals is topological.

  3. stolstov commented on Mar 9, 2016

    @stolstov
    Member

    Name is not good. Maybe we should rename OGC equals to Equals(OGCGeometry), and leave java equals(Object) to do Java identity thing.

  4. randallwhitman commented on Mar 9, 2016

    @randallwhitman
    ContributorAuthor

    In Java, operator == is identity, whereas CustomType.equals is conceptual equality.

  5. stolstov commented on Mar 9, 2016

    @stolstov
    Member

    The ogc equals is slow, and also, probably not what one expects when storing a class in a container, such a hash map. I think ogc equals it should be different from identity equals.

  6. added this to the 2.0.0 milestone on Aug 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions