classpath-patches
[Top][All Lists]
Advanced

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

[cp-patches] FYI: Hashcode for NameComponent.


From: Meskauskas Audrius
Subject: [cp-patches] FYI: Hashcode for NameComponent.
Date: Wed, 14 Sep 2005 21:14:18 +0200
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

This is a hashcode function for the NameComponent, computed using Adler by content rather than by identity (same as .equals works).

2005-09-14    Audrius Meskauskas  <address@hidden>

* org/omg/CosNaming/NameComponent (hashCode): New method.


Index: org/omg/CosNaming/NameComponent.java
===================================================================
RCS file: /cvsroot/classpath/classpath/org/omg/CosNaming/NameComponent.java,v
retrieving revision 1.3
diff -u -r1.3 NameComponent.java
--- org/omg/CosNaming/NameComponent.java        2 Jul 2005 20:32:59 -0000       
1.3
+++ org/omg/CosNaming/NameComponent.java        14 Sep 2005 19:06:22 -0000
@@ -40,6 +40,8 @@
 
 import org.omg.CORBA.portable.IDLEntity;
 
+import java.util.zip.Adler32;
+
 /**
  * The name component, a node in the multi-comonent name.
  *
@@ -115,4 +117,14 @@
   {
     return id + "." + kind;
   }
-}
\ No newline at end of file
+
+  /**
+   * Return the hashCode of this NameComponent.
+   */
+  public int hashCode()
+  {
+    Adler32 adler = new Adler32();
+    adler.update(toString().getBytes());
+    return (int) adler.getValue() & Integer.MAX_VALUE;
+  }
+}

reply via email to

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