summaryrefslogtreecommitdiff
path: root/java/awt/geom
diff options
context:
space:
mode:
authorEric Blake <ebb9@byu.net>2002-03-21 09:12:38 +0000
committerEric Blake <ebb9@byu.net>2002-03-21 09:12:38 +0000
commitdb7c97c69f72308d8f84d90b82c32ccf24e7941c (patch)
treec8c81737f20fa243a0eaa58eace54db840597735 /java/awt/geom
parent4332db89d690b15e98be69e3b58d22d14814c40d (diff)
downloadclasspath-db7c97c69f72308d8f84d90b82c32ccf24e7941c.tar.gz
2002-03-21 Eric Blake <ebb9@email.byu.edu>
* java/awt/Rectangle.java: Spelling typo. * java/awt/geom/Rectangle2D.java (hashCode, equals): Missed these in last commit.
Diffstat (limited to 'java/awt/geom')
-rw-r--r--java/awt/geom/Rectangle2D.java40
1 files changed, 40 insertions, 0 deletions
diff --git a/java/awt/geom/Rectangle2D.java b/java/awt/geom/Rectangle2D.java
index 0caa790b7..050868dfa 100644
--- a/java/awt/geom/Rectangle2D.java
+++ b/java/awt/geom/Rectangle2D.java
@@ -498,6 +498,46 @@ public abstract class Rectangle2D extends RectangularShape
}
/**
+ * Return the hashcode for this rectangle. The formula is not documented, but
+ * appears to be the same as:
+ * <pre>
+ * long l = Double.doubleToLongBits(getX())
+ * + 37 * Double.doubleToLongBits(getY())
+ * + 43 * Double.doubleToLongBits(getWidth())
+ * + 47 * Double.doubleToLongBits(getHeight());
+ * return (int) ((l >> 32) ^ l);
+ * </pre>
+ *
+ * @return the hashcode
+ */
+ public int hashCode()
+ {
+ // Talk about a fun time reverse engineering this one!
+ long l = Double.doubleToLongBits(getX())
+ + 37 * Double.doubleToLongBits(getY())
+ + 43 * Double.doubleToLongBits(getWidth())
+ + 47 * Double.doubleToLongBits(getHeight());
+ return (int) ((l >> 32) ^ l);
+ }
+
+ /**
+ * Tests this rectangle for equality against the specified object. This
+ * will be true if an only if the specified object is an instance of
+ * Rectangle2D with the same coordinates and dimensions.
+ *
+ * @param obj the object to test against for equality
+ * @return true if the specified object is equal to this one
+ */
+ public boolean equals(Object obj)
+ {
+ if (! (obj instanceof Rectangle2D))
+ return false;
+ Rectangle2D r = (Rectangle2D) obj;
+ return r.getX() == getX() && r.getY() == getY()
+ && r.getWidth() == getWidth() && r.getHeight() == getHeight();
+ }
+
+ /**
* This class defines a rectangle in <code>double</code> precision.
*
* @author Eric Blake <ebb9@email.byu.edu>