[postgis-devel] Re: Implementing support for PostGIS spatial types in JPOX

Markus Schaber schabi at logix-tt.com
Wed May 10 03:48:47 PDT 2006


Hi, @all,

I forgot to attach the patch that reflects my current combined set of
changes, against CVS head.

HTH,
Markus


-- 
Markus Schaber | Logical Tracking&Tracing International AG
Dipl. Inf.     | Software Development GIS

Fight against software patents in EU! www.ffii.org www.nosoftwarepatents.org
-------------- next part --------------
Index: jdbc2/jtssrc/org/postgis/jts/JtsGeometry.java
===================================================================
RCS file: /home/cvs/postgis/postgis/jdbc2/jtssrc/org/postgis/jts/JtsGeometry.java,v
retrieving revision 1.11
diff -u -r1.11 JtsGeometry.java
--- jdbc2/jtssrc/org/postgis/jts/JtsGeometry.java	9 May 2006 13:06:56 -0000	1.11
+++ jdbc2/jtssrc/org/postgis/jts/JtsGeometry.java	10 May 2006 10:48:03 -0000
@@ -126,6 +126,9 @@
     }
 
     public String toString() {
+        if (geom == null) {
+            return null;
+        }
         return geom.toString();
     }
 
@@ -140,14 +143,16 @@
     }
 
     public boolean equals(Object obj) {
-        if ((obj != null) && (obj instanceof JtsGeometry)) {
-            Geometry other = ((JtsGeometry) obj).geom;
-            if (this.geom == other) { // handles identity as well as both ==null
-                return true;
-            } else if (this.geom != null && other != null) {
-                return other.equals(this.geom);
-            }
+        if (obj == this)
+            return true;
+        if (!(obj instanceof JtsGeometry))
+            return false;
+
+        Geometry other = ((JtsGeometry) obj).geom;
+        if (other == null) {
+            return (this.geom == null);
+        } else {
+            return other.equals(this.geom);
         }
-        return false;
     }
 }
Index: jdbc2/src/org/postgis/ComposedGeom.java
===================================================================
RCS file: /home/cvs/postgis/postgis/jdbc2/src/org/postgis/ComposedGeom.java,v
retrieving revision 1.7
diff -u -r1.7 ComposedGeom.java
--- jdbc2/src/org/postgis/ComposedGeom.java	28 Jul 2005 12:23:16 -0000	1.7
+++ jdbc2/src/org/postgis/ComposedGeom.java	10 May 2006 10:48:04 -0000
@@ -126,10 +126,15 @@
      */
     protected abstract Geometry[] createSubGeomArray(int size);
 
-    protected boolean equalsintern(Geometry other) {
-        // Can be assumed to be the same subclass of Geometry, so it must be a
-        // ComposedGeom, too.
-        ComposedGeom cother = (ComposedGeom) other;
+    public boolean equals(Object obj) {
+        if (obj == this)
+            return true;
+    	if (!(obj instanceof ComposedGeom)) 
+            return false;    	
+    	if (!super.equals(obj)) 
+            return false;
+    	
+        ComposedGeom cother = (ComposedGeom) obj;
 
         if (cother.subgeoms == null && subgeoms == null) {
             return true;
@@ -141,7 +146,7 @@
             return true;
         } else {
             for (int i = 0; i < subgeoms.length; i++) {
-                if (!cother.subgeoms[i].equalsintern(this.subgeoms[i])) {
+                if (!cother.subgeoms[i].equals(this.subgeoms[i])) {
                     return false;
                 }
             }
@@ -150,7 +155,7 @@
     }
 
     public int numPoints() {
-        if ((subgeoms == null) || (subgeoms.length == 0)) {
+        if (isEmpty()) {
             return 0;
         } else {
             int result = 0;
@@ -164,7 +169,7 @@
     public Point getPoint(int n) {
         if (n < 0) {
             throw new ArrayIndexOutOfBoundsException("Negative index not allowed");
-        } else if ((subgeoms == null) || (subgeoms.length == 0)) {
+        } else if (isEmpty()) {
             throw new ArrayIndexOutOfBoundsException("Empty Geometry has no Points!");
         } else {
             for (int i = 0; i < subgeoms.length; i++) {
@@ -185,7 +190,7 @@
      * Optimized version
      */
     public Point getLastPoint() {
-        if ((subgeoms == null) || (subgeoms.length == 0)) {
+        if (isEmpty()) {
             throw new ArrayIndexOutOfBoundsException("Empty Geometry has no Points!");
         } else {
             return subgeoms[subgeoms.length - 1].getLastPoint();
@@ -196,7 +201,7 @@
      * Optimized version
      */
     public Point getFirstPoint() {
-        if ((subgeoms == null) || (subgeoms.length == 0)) {
+        if (isEmpty()) {
             throw new ArrayIndexOutOfBoundsException("Empty Geometry has no Points!");
         } else {
             return subgeoms[0].getFirstPoint();
@@ -207,12 +212,12 @@
         return java.util.Arrays.asList(subgeoms).iterator();
     }
 
-    public boolean isEmpty() {
+    public final boolean isEmpty() {
         return (subgeoms == null) || (subgeoms.length == 0);
     }
 
     protected void mediumWKT(StringBuffer sb) {
-        if ((subgeoms == null) || (subgeoms.length == 0)) {
+        if (isEmpty()) {
             sb.append(" EMPTY");
         } else {
             sb.append('(');
Index: jdbc2/src/org/postgis/Geometry.java
===================================================================
RCS file: /home/cvs/postgis/postgis/jdbc2/src/org/postgis/Geometry.java,v
retrieving revision 1.8
diff -u -r1.8 Geometry.java
--- jdbc2/src/org/postgis/Geometry.java	9 May 2006 13:06:55 -0000	1.8
+++ jdbc2/src/org/postgis/Geometry.java	10 May 2006 10:48:04 -0000
@@ -136,35 +136,21 @@
     /**
      * java.lang.Object equals implementation
      */
-    public boolean equals(Object other) {
-        return (other != null) && (other instanceof Geometry) && equals((Geometry) other);
+    public boolean equals(Object obj) {
+        if (obj == this)
+            return true;
+    	if (!(obj instanceof Geometry))
+            return false;
+
+    	Geometry other = (Geometry)obj;
+    	
+    	return (this.dimension == other.dimension) 
+            && (this.type == other.type)
+            && (this.srid == other.srid) 
+            && (this.haveMeasure == other.haveMeasure);
     }
 
     /**
-     * geometry specific equals implementation - only defined for non-null
-     * values
-     */
-    public boolean equals(Geometry other) {
-        boolean firstline = (other != null) && (this.dimension == other.dimension)
-                && (this.type == other.type);
-        boolean sridequals = (this.srid == other.srid);
-        boolean measEquals = (this.haveMeasure == other.haveMeasure);
-        boolean secondline = sridequals && measEquals;
-        boolean classequals = other.getClass().equals(this.getClass());
-        boolean equalsintern = this.equalsintern(other);
-        boolean result = firstline && secondline && classequals && equalsintern;
-        return result;
-    }
-
-    /**
-     * Whether test coordinates for geometry - subclass specific code
-     * 
-     * Implementors can assume that dimensin, type, srid and haveMeasure are
-     * equal, other != null and other is the same subclass.
-     */
-    protected abstract boolean equalsintern(Geometry other);
-
-    /**
      * Return the number of Points of the geometry
      */
     public abstract int numPoints();
Index: jdbc2/src/org/postgis/Point.java
===================================================================
RCS file: /home/cvs/postgis/postgis/jdbc2/src/org/postgis/Point.java,v
retrieving revision 1.12
diff -u -r1.12 Point.java
--- jdbc2/src/org/postgis/Point.java	10 May 2006 10:47:35 -0000	1.12
+++ jdbc2/src/org/postgis/Point.java	10 May 2006 10:48:05 -0000
@@ -45,12 +45,16 @@
         return (int) (v ^ (v >>> 32));
     }
 
-    protected boolean equalsintern(Geometry otherg) {
-        Point other = (Point) otherg;
-        return equals(other);
-    }
+    public boolean equals(Object obj) {
+        if (obj == this)
+            return true;
+        if (!(obj instanceof Point))
+            return false;
+        if ( !super.equals(obj) ) 
+            return false;
+
+        Point other = (Point)obj;
 
-    public final boolean equals(Point other) {
         boolean xequals = x == other.x;
         boolean yequals = y == other.y;
         boolean zequals = ((dimension == 2) || (z == other.z));