lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From markrmil...@apache.org
Subject svn commit: r812248 - in /lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry: ./ shape/
Date Mon, 07 Sep 2009 18:31:44 GMT
Author: markrmiller
Date: Mon Sep  7 18:31:43 2009
New Revision: 812248

URL: http://svn.apache.org/viewvc?rev=812248&view=rev
Log:
LUCENE-1893: clean up equals/hashCode issues in spatial

Modified:
    lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/CartesianPoint.java
    lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/FixedLatLng.java
    lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/FloatLatLng.java
    lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/LatLng.java
    lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/shape/LLRect.java
    lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/shape/LineSegment.java
    lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/shape/Point2D.java
    lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/shape/Rectangle.java
    lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/shape/Vector2D.java

Modified: lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/CartesianPoint.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/CartesianPoint.java?rev=812248&r1=812247&r2=812248&view=diff
==============================================================================
--- lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/CartesianPoint.java
(original)
+++ lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/CartesianPoint.java
Mon Sep  7 18:31:43 2009
@@ -54,4 +54,30 @@
   public CartesianPoint translate(int deltaX, int deltaY) {
     return new CartesianPoint(this.x+deltaX, this.y+deltaY);
   }
+
+  @Override
+  public int hashCode() {
+    final int prime = 31;
+    int result = 1;
+    result = prime * result + x;
+    result = prime * result + y;
+    return result;
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (this == obj)
+      return true;
+    if (obj == null)
+      return false;
+    if (getClass() != obj.getClass())
+      return false;
+    CartesianPoint other = (CartesianPoint) obj;
+    if (x != other.x)
+      return false;
+    if (y != other.y)
+      return false;
+    return true;
+  }
+  
 }

Modified: lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/FixedLatLng.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/FixedLatLng.java?rev=812248&r1=812247&r2=812248&view=diff
==============================================================================
--- lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/FixedLatLng.java
(original)
+++ lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/FixedLatLng.java
Mon Sep  7 18:31:43 2009
@@ -50,11 +50,6 @@
     this.lng=lng;
   }
   
-  @Override
-  public boolean equals(LatLng other) {
-    return lat==other.getFixedLat() && lng==other.getFixedLng();
-  }
-  
   public static double fixedToDouble(int fixed) {
     return (fixed)/SCALE_FACTOR;
   }
@@ -137,4 +132,29 @@
         (lng+other.getFixedLng())/2);
   }
 
+  @Override
+  public int hashCode() {
+    final int prime = 31;
+    int result = prime + lat;
+    result = prime * result + lng;
+    result = prime * result + (normalized ? 1231 : 1237);
+    return result;
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (this == obj)
+      return true;
+    if (getClass() != obj.getClass())
+      return false;
+    FixedLatLng other = (FixedLatLng) obj;
+    if (lat != other.lat)
+      return false;
+    if (lng != other.lng)
+      return false;
+    if (normalized != other.normalized)
+      return false;
+    return true;
+  }
+  
 }

Modified: lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/FloatLatLng.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/FloatLatLng.java?rev=812248&r1=812247&r2=812248&view=diff
==============================================================================
--- lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/FloatLatLng.java
(original)
+++ lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/FloatLatLng.java
Mon Sep  7 18:31:43 2009
@@ -39,12 +39,6 @@
   }
   
   @Override
-  public boolean equals(LatLng other) {
-    return lat==other.getLat() && lng==other.getLng();
-  }
-
-  
-  @Override
   public LatLng copy() {
     return new FloatLatLng(this);
   }
@@ -118,4 +112,32 @@
         (lng+other.getLng())/2.0);
   }
 
+  @Override
+  public int hashCode() {
+    final int prime = 31;
+    long temp;
+    temp = Double.doubleToLongBits(lat);
+    int result = prime  + (int) (temp ^ (temp >>> 32));
+    temp = Double.doubleToLongBits(lng);
+    result = prime * result + (int) (temp ^ (temp >>> 32));
+    result = prime * result + (normalized ? 1231 : 1237);
+    return result;
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (this == obj)
+      return true;
+    if (getClass() != obj.getClass())
+      return false;
+    FloatLatLng other = (FloatLatLng) obj;
+    if (Double.doubleToLongBits(lat) != Double.doubleToLongBits(other.lat))
+      return false;
+    if (Double.doubleToLongBits(lng) != Double.doubleToLongBits(other.lng))
+      return false;
+    if (normalized != other.normalized)
+      return false;
+    return true;
+  }
+
 }

Modified: lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/LatLng.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/LatLng.java?rev=812248&r1=812247&r2=812248&view=diff
==============================================================================
--- lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/LatLng.java
(original)
+++ lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/LatLng.java
Mon Sep  7 18:31:43 2009
@@ -50,14 +50,6 @@
 
   public abstract FloatLatLng toFloat();
   
-  public abstract boolean equals(LatLng other);
-
-  @Override
-  public boolean equals(Object other) {
-    if (!(other instanceof LatLng)) return false;
-    return equals((LatLng)other);
-  }
-  
   /**
    * Convert the lat/lng into the cartesian coordinate plane such that all
    * world coordinates are represented in the first quadrant.
@@ -159,4 +151,8 @@
    * @param other
    */
   public abstract LatLng calculateMidpoint(LatLng other);
+  
+  public abstract int hashCode();
+
+  public abstract boolean equals(Object obj);
 }

Modified: lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/shape/LLRect.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/shape/LLRect.java?rev=812248&r1=812247&r2=812248&view=diff
==============================================================================
--- lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/shape/LLRect.java
(original)
+++ lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/shape/LLRect.java
Mon Sep  7 18:31:43 2009
@@ -59,16 +59,6 @@
   }
   
   @Override
-  public boolean equals(Object otherObj) {
-    if (!(otherObj instanceof LLRect)) return false;
-    return equals((LLRect)otherObj);
-  }
-  
-  public boolean equals(LLRect other) {
-    return getLowerLeft().equals(other.getLowerLeft()) && getUpperRight().equals(other.getUpperRight());
-  }
-  
-  @Override
   public String toString() {
     return "{" + ll + ", " + ur + "}";
   }
@@ -103,4 +93,37 @@
   public Rectangle toRectangle() {
     return new Rectangle(ll.getLng(), ll.getLat(), ur.getLng(), ur.getLat());
   }
+
+  @Override
+  public int hashCode() {
+    final int prime = 31;
+    int result = 1;
+    result = prime * result + ((ll == null) ? 0 : ll.hashCode());
+    result = prime * result + ((ur == null) ? 0 : ur.hashCode());
+    return result;
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (this == obj)
+      return true;
+    if (obj == null)
+      return false;
+    if (getClass() != obj.getClass())
+      return false;
+    LLRect other = (LLRect) obj;
+    if (ll == null) {
+      if (other.ll != null)
+        return false;
+    } else if (!ll.equals(other.ll))
+      return false;
+    if (ur == null) {
+      if (other.ur != null)
+        return false;
+    } else if (!ur.equals(other.ur))
+      return false;
+    return true;
+  }
+  
+  
 }

Modified: lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/shape/LineSegment.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/shape/LineSegment.java?rev=812248&r1=812247&r2=812248&view=diff
==============================================================================
--- lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/shape/LineSegment.java
(original)
+++ lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/shape/LineSegment.java
Mon Sep  7 18:31:43 2009
@@ -82,4 +82,36 @@
     closestPt.add(A);
     return new Vector2D(closestPt, P).norm();
   }
+
+  @Override
+  public int hashCode() {
+    final int prime = 31;
+    int result = 1;
+    result = prime * result + ((A == null) ? 0 : A.hashCode());
+    result = prime * result + ((B == null) ? 0 : B.hashCode());
+    return result;
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (this == obj)
+      return true;
+    if (obj == null)
+      return false;
+    if (getClass() != obj.getClass())
+      return false;
+    LineSegment other = (LineSegment) obj;
+    if (A == null) {
+      if (other.A != null)
+        return false;
+    } else if (!A.equals(other.A))
+      return false;
+    if (B == null) {
+      if (other.B != null)
+        return false;
+    } else if (!B.equals(other.B))
+      return false;
+    return true;
+  }
+  
 }

Modified: lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/shape/Point2D.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/shape/Point2D.java?rev=812248&r1=812247&r2=812248&view=diff
==============================================================================
--- lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/shape/Point2D.java
(original)
+++ lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/shape/Point2D.java
Mon Sep  7 18:31:43 2009
@@ -28,7 +28,7 @@
 public class Point2D {
   private double x;
   private double y;
-  
+
   public Point2D(double x, double y) {
     this.x=x;
     this.y=y;
@@ -86,16 +86,6 @@
     this.y=y;
   }
 
-  public boolean equals(Point2D other) {
-    return other!=null && x==other.x && y==other.y;
-  }
-  
-  @Override
-  public boolean equals(Object other) {
-    if (!(other instanceof Point2D)) return false;
-    return equals((Point2D)other);
-  }
-
   public void add(Vector2D v) {
     this.x+=v.getX();
     this.y+=v.getY();
@@ -116,5 +106,32 @@
     this.y=v.getY();
   }
   
+  @Override
+  public int hashCode() {
+    final int prime = 31;
+    int result = 1;
+    long temp;
+    temp = Double.doubleToLongBits(x);
+    result = prime * result + (int) (temp ^ (temp >>> 32));
+    temp = Double.doubleToLongBits(y);
+    result = prime * result + (int) (temp ^ (temp >>> 32));
+    return result;
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (this == obj)
+      return true;
+    if (obj == null)
+      return false;
+    if (getClass() != obj.getClass())
+      return false;
+    Point2D other = (Point2D) obj;
+    if (Double.doubleToLongBits(x) != Double.doubleToLongBits(other.x))
+      return false;
+    if (Double.doubleToLongBits(y) != Double.doubleToLongBits(other.y))
+      return false;
+    return true;
+  }
   
 }

Modified: lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/shape/Rectangle.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/shape/Rectangle.java?rev=812248&r1=812247&r2=812248&view=diff
==============================================================================
--- lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/shape/Rectangle.java
(original)
+++ lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/shape/Rectangle.java
Mon Sep  7 18:31:43 2009
@@ -52,16 +52,6 @@
     this.ptMax=new Point2D(Math.max(x1, x2), Math.max(y1, y2));
   }
   
-  public boolean equals(Rectangle other) {
-    return other.ptMin.equals(ptMin) && other.ptMax.equals(ptMax);
-  }
-  
-  @Override
-  public boolean equals(Object other) {
-    if (!(other instanceof Rectangle)) return false;
-    return equals((Rectangle)other);
-  }
-  
   public double area() {
     return (ptMax.getX() - ptMin.getX()) * (ptMax.getY() - ptMin.getY());
   }
@@ -104,4 +94,35 @@
     return ptMin;
   }
 
+  @Override
+  public int hashCode() {
+    final int prime = 31;
+    int result = 1;
+    result = prime * result + ((ptMax == null) ? 0 : ptMax.hashCode());
+    result = prime * result + ((ptMin == null) ? 0 : ptMin.hashCode());
+    return result;
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (this == obj)
+      return true;
+    if (obj == null)
+      return false;
+    if (getClass() != obj.getClass())
+      return false;
+    Rectangle other = (Rectangle) obj;
+    if (ptMax == null) {
+      if (other.ptMax != null)
+        return false;
+    } else if (!ptMax.equals(other.ptMax))
+      return false;
+    if (ptMin == null) {
+      if (other.ptMin != null)
+        return false;
+    } else if (!ptMin.equals(other.ptMin))
+      return false;
+    return true;
+  }
+
 }

Modified: lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/shape/Vector2D.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/shape/Vector2D.java?rev=812248&r1=812247&r2=812248&view=diff
==============================================================================
--- lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/shape/Vector2D.java
(original)
+++ lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/geometry/shape/Vector2D.java
Mon Sep  7 18:31:43 2009
@@ -94,13 +94,6 @@
     return other != null && x == other.x && y == other.y;
   }
 
-  @Override
-  public boolean equals(Object other) {
-    if (!(other instanceof Vector2D))
-      return false;
-    return equals((Vector2D) other);
-  }
-
   public double dot(Vector2D in) {
     return ((x) * in.x) + (y * in.y);
   }
@@ -121,4 +114,32 @@
     return new Vector2D(x*d, y*d);
   }
 
+  @Override
+  public int hashCode() {
+    final int prime = 31;
+    int result = 1;
+    long temp;
+    temp = Double.doubleToLongBits(x);
+    result = prime * result + (int) (temp ^ (temp >>> 32));
+    temp = Double.doubleToLongBits(y);
+    result = prime * result + (int) (temp ^ (temp >>> 32));
+    return result;
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (this == obj)
+      return true;
+    if (obj == null)
+      return false;
+    if (getClass() != obj.getClass())
+      return false;
+    Vector2D other = (Vector2D) obj;
+    if (Double.doubleToLongBits(x) != Double.doubleToLongBits(other.x))
+      return false;
+    if (Double.doubleToLongBits(y) != Double.doubleToLongBits(other.y))
+      return false;
+    return true;
+  }
+  
 }



Mime
View raw message