[Webfunds-commits] java/webfunds/client AccountInfo.java

Ian Grigg iang@cypherpunks.ai
Fri, 13 Apr 2001 13:35:02 -0400 (AST)


iang        01/04/13 13:35:02

  Modified:    webfunds/client AccountInfo.java
  Log:
  can now handle any length, as it is generic info, not limited to AccountId.
  (and the creation of targets from the Payment dialog could break it badly!)

Revision  Changes    Path
1.27      +13 -4     java/webfunds/client/AccountInfo.java

Index: AccountInfo.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/AccountInfo.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- AccountInfo.java	2001/04/12 19:02:49	1.26
+++ AccountInfo.java	2001/04/13 17:35:02	1.27
@@ -1,5 +1,5 @@
 /*
- * $Id: AccountInfo.java,v 1.26 2001/04/12 19:02:49 iang Exp $
+ * $Id: AccountInfo.java,v 1.27 2001/04/13 17:35:02 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -9,6 +9,7 @@
 import java.io.*;
 
 import webfunds.util.Hex;
+import webfunds.util.Panic;
 
 import webfunds.sox.Utils;
 import webfunds.sox.Encodable;
@@ -33,13 +34,16 @@
     }
 
     public byte[]      getByteArray()           { return id; }
-    public void        setByteArray(byte[] id)
+    public void        setByteArray(byte[] id)  { this.id = id; }
+
+/* XXX:  fixed, who knows what hash user provides...
     {
         // check that it is valid for hashCode, 1,2,3 bytes doesn't work
         if (id != null && (0 < id.length && id.length < 4))
-            throw new RuntimeException("id too small");
+            throw new Panic("id too small");
         this.id = id;
     }
+*/
 
     // This should not really be here,
     // client doesn't want to know about
@@ -260,9 +264,14 @@
      */
     public int hashCode()
     {
-        if (id == null || id.length == 0)
+        if (id == null)
             return 0;
-        return id[0] | (id[1]<<8) | (id[2]<<16) | (id[3]<<24);
+
+        // return id[0] | (id[1]<<8) | (id[2]<<16) | (id[3]<<24);
+        int hash = 0;
+        for (int i = 0; (i < id.length) && (i < 4); i++)
+            hash |= id[i] << (i * 8);
+        return hash;
     }
 
     /**