classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] FYI: Documentation and hashCode() for BasicStroke


From: Mark Wielaard
Subject: [cp-patches] FYI: Documentation and hashCode() for BasicStroke
Date: Thu, 20 Jan 2005 13:40:17 +0100

Hi,

Here is an implementation for hashcode and some documentation updates
for BasicStroke. I couldn't find any documentation on the value of the
hashcode, but this implementation is consistent with the equals()
implementation.

2005-01-20  Mark Wielaard  <address@hidden>

        * java/awt/BasicStroke.java (hashCode): Implement.
        (equals): Document.

This helps when BasicStrokes are stored in collections (as in the
jcommon tests). Still missing is the createStrokedShape() method. Our
own Graphics2D implementation doesn't need it since it knows cairo can
more efficiently handle it atm. It would still be good to have a real
implementation. But (as Sven suggested) it is probably better to wait
till cairo stabilizes a bit so we can be sure to use the exect same
algorithm.

Cheers,

Mark
Index: java/awt/BasicStroke.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/BasicStroke.java,v
retrieving revision 1.5
diff -u -r1.5 BasicStroke.java
--- java/awt/BasicStroke.java   16 Nov 2004 09:59:11 -0000      1.5
+++ java/awt/BasicStroke.java   20 Jan 2005 12:39:16 -0000
@@ -1,5 +1,5 @@
 /* BasicStroke.java -- 
-   Copyright (C) 2002, 2003, 2004  Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003, 2004, 2005  Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -48,6 +48,7 @@
   public static final int JOIN_MITER = 0;
   public static final int JOIN_ROUND = 1;
   public static final int JOIN_BEVEL = 2;
+
   public static final int CAP_BUTT = 0;
   public static final int CAP_ROUND = 1;
   public static final int CAP_SQUARE = 2;
@@ -208,11 +209,33 @@
     return phase;
   }
 
+  /**
+   * Returns the hash code for this object. The hash is calculated by
+   * xoring the hash, cap, join, limit, dash array and phase values
+   * (converted to <code>int</code> first with
+   * <code>Float.floatToIntBits()</code> if the value is a
+   * <code>float</code>).
+   */
   public int hashCode()
   {
-    throw new Error("not implemented");
+    int hash = Float.floatToIntBits(width);
+    hash ^= cap;
+    hash ^= join;
+    hash ^= Float.floatToIntBits(limit);
+    
+    for (int i = 0; i < dash.length; i++)
+      hash ^=  Float.floatToIntBits(dash[i]);
+
+    hash ^= Float.floatToIntBits(phase);
+
+    return hash;
   }
 
+  /**
+   * Returns true if the given Object is an instance of BasicStroke
+   * and the width, cap, join, limit, dash array and phase are all
+   * equal.
+   */
   public boolean equals(Object o)
   {
     if (! (o instanceof BasicStroke))

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]