Author: mrglavas
Date: Sun Jan  8 20:38:12 2006
New Revision: 367193

URL: http://svn.apache.org/viewcvs?rev=367193&view=rev
Log:
Adding hashCode methods to several value classes. These need to be defined
if we're going to be storing instances of these classes in hashtables.

Modified:
    xerces/java/trunk/src/org/apache/xerces/impl/dv/xs/Base64BinaryDV.java
    xerces/java/trunk/src/org/apache/xerces/impl/dv/xs/DoubleDV.java
    xerces/java/trunk/src/org/apache/xerces/impl/dv/xs/FloatDV.java
    xerces/java/trunk/src/org/apache/xerces/impl/dv/xs/HexBinaryDV.java
    xerces/java/trunk/src/org/apache/xerces/impl/dv/xs/ListDV.java

Modified: xerces/java/trunk/src/org/apache/xerces/impl/dv/xs/Base64BinaryDV.java
URL: 
http://svn.apache.org/viewcvs/xerces/java/trunk/src/org/apache/xerces/impl/dv/xs/Base64BinaryDV.java?rev=367193&r1=367192&r2=367193&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/dv/xs/Base64BinaryDV.java 
(original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/dv/xs/Base64BinaryDV.java Sun 
Jan  8 20:38:12 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 2001, 2002,2004 The Apache Software Foundation.
+ * Copyright 2001,2002,2004,2006 The Apache Software Foundation.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -77,6 +77,14 @@
                     return false;
             }
             return true;
+        }
+        
+        public int hashCode() {
+            int hash = 0;
+            for (int i = 0; i < data.length; ++i) {
+                hash = hash * 37 + (((int) data[i]) & 0xff);
+            }
+            return hash;
         }
     }
 } // class Base64BinaryDV

Modified: xerces/java/trunk/src/org/apache/xerces/impl/dv/xs/DoubleDV.java
URL: 
http://svn.apache.org/viewcvs/xerces/java/trunk/src/org/apache/xerces/impl/dv/xs/DoubleDV.java?rev=367193&r1=367192&r2=367193&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/dv/xs/DoubleDV.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/dv/xs/DoubleDV.java Sun Jan  8 
20:38:12 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 2001-2005 The Apache Software Foundation.
+ * Copyright 2001-2006 The Apache Software Foundation.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -112,6 +112,15 @@
                 return true;
 
             return false;
+        }
+        
+        public int hashCode() {
+            // This check is necessary because doubleToLongBits(+0) != 
doubleToLongBits(-0)
+            if (value == 0d) {
+                return 0;
+            }
+            long v = Double.doubleToLongBits(value);
+            return (int) (v ^ (v >>> 32));
         }
         
         // NOTE: 0.0 is equal but not identical to -0.0

Modified: xerces/java/trunk/src/org/apache/xerces/impl/dv/xs/FloatDV.java
URL: 
http://svn.apache.org/viewcvs/xerces/java/trunk/src/org/apache/xerces/impl/dv/xs/FloatDV.java?rev=367193&r1=367192&r2=367193&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/dv/xs/FloatDV.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/dv/xs/FloatDV.java Sun Jan  8 
20:38:12 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 2001-2005 The Apache Software Foundation.
+ * Copyright 2001-2006 The Apache Software Foundation.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -96,6 +96,11 @@
                 return true;
 
             return false;
+        }
+        
+        public int hashCode() {
+            // This check is necessary because floatToIntBits(+0) != 
floatToIntBits(-0)
+            return (value == 0f) ? 0 : Float.floatToIntBits(value);
         }
         
         // NOTE: 0.0 is equal but not identical to -0.0

Modified: xerces/java/trunk/src/org/apache/xerces/impl/dv/xs/HexBinaryDV.java
URL: 
http://svn.apache.org/viewcvs/xerces/java/trunk/src/org/apache/xerces/impl/dv/xs/HexBinaryDV.java?rev=367193&r1=367192&r2=367193&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/dv/xs/HexBinaryDV.java 
(original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/dv/xs/HexBinaryDV.java Sun Jan 
 8 20:38:12 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 2001, 2002,2004 The Apache Software Foundation.
+ * Copyright 2001,2002,2004,2006 The Apache Software Foundation.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -75,6 +75,13 @@
             }
             return true;
         }
-
+        
+        public int hashCode() {
+            int hash = 0;
+            for (int i = 0; i < data.length; ++i) {
+                hash = hash * 37 + (((int) data[i]) & 0xff);
+            }
+            return hash;
+        }
     }
 }

Modified: xerces/java/trunk/src/org/apache/xerces/impl/dv/xs/ListDV.java
URL: 
http://svn.apache.org/viewcvs/xerces/java/trunk/src/org/apache/xerces/impl/dv/xs/ListDV.java?rev=367193&r1=367192&r2=367193&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/dv/xs/ListDV.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/dv/xs/ListDV.java Sun Jan  8 
20:38:12 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 2001,2002,2004,2005 The Apache Software Foundation.
+ * Copyright 2001,2002,2004-2006 The Apache Software Foundation.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -87,6 +87,14 @@
     
             //everything went fine.
             return true;
+        }
+        
+        public int hashCode() {
+            int hash = 0;
+            for (int i = 0; i < data.length; ++i) {
+                hash ^= data[i].hashCode();
+            }
+            return hash;
         }
         
         public boolean contains(Object item) {



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to