Skip to content

Commit

Permalink
Implement equals and hashCode for geometry objects
Browse files Browse the repository at this point in the history
  • Loading branch information
ivakegg committed Jan 10, 2025
1 parent 55d92d5 commit f8c08e6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/main/java/datawave/data/type/util/AbstractGeometry.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package datawave.data.type.util;

import java.io.Serializable;
import java.util.Objects;

/**
* The base GeoWave geometry delegate object, which wraps the underlying JTS geometry
Expand All @@ -19,7 +20,22 @@ public T getJTSGeometry() {
return jtsGeom;
}

@Override
public String toString() {
return jtsGeom.toText();
}

@Override
public int hashCode() {
return Objects.hashCode(jtsGeom);
}

@Override
public boolean equals(Object o) {
if (o instanceof Geometry) {
Geometry other = (Geometry) o;
return Objects.equals(jtsGeom, other.jtsGeom);
}
return false;
}
}
10 changes: 9 additions & 1 deletion src/main/java/datawave/data/type/util/Geometry.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ public Geometry(org.locationtech.jts.geom.Geometry jtsGeom) {

@Override
public int compareTo(Geometry o) {
return jtsGeom.compareTo(o.jtsGeom);
if (jtsGeom == o.jtsGeom) {
return 0;
} else if (jtsGeom == null) {
return -1;
} else if (o.jtsGeom == null) {
return 1;
} else {
return jtsGeom.compareTo(o.jtsGeom);
}
}
}

0 comments on commit f8c08e6

Please sign in to comment.