Author: toad
Date: 2009-02-03 18:02:55 +0000 (Tue, 03 Feb 2009)
New Revision: 25499

Modified:
   branches/db4o/freenet/src/freenet/keys/ClientCHK.java
Log:
ClientCHK: equals(), hashCode()


Modified: branches/db4o/freenet/src/freenet/keys/ClientCHK.java
===================================================================
--- branches/db4o/freenet/src/freenet/keys/ClientCHK.java       2009-02-03 
17:44:22 UTC (rev 25498)
+++ branches/db4o/freenet/src/freenet/keys/ClientCHK.java       2009-02-03 
18:02:55 UTC (rev 25499)
@@ -12,6 +12,7 @@
 import com.db4o.ObjectContainer;
 
 import freenet.support.Base64;
+import freenet.support.Fields;
 
 /**
  * Client level CHK. Can be converted into a FreenetURI, can be used to decrypt
@@ -31,6 +32,7 @@
     final byte cryptoAlgorithm;
     /** Compression algorithm, negative means uncompressed */
     final short compressionAlgorithm;
+    final int hashCode;
     
     /* We use EXTRA_LENGTH above for consistency, rather than dis.read etc. 
Some code depends on this
      * being accurate. Change those uses if you like. */
@@ -49,6 +51,7 @@
        this.cryptoAlgorithm = key.cryptoAlgorithm;
        this.compressionAlgorithm = key.compressionAlgorithm;
         if(routingKey == null) throw new NullPointerException();
+        hashCode = Fields.hashCode(routingKey) ^ Fields.hashCode(routingKey) ^ 
compressionAlgorithm;
     }
     
     /**
@@ -71,6 +74,7 @@
         this.cryptoAlgorithm = algo;
         this.compressionAlgorithm = compressionAlgorithm;
         if(routingKey == null) throw new NullPointerException();
+        hashCode = Fields.hashCode(routingKey) ^ Fields.hashCode(encKey) ^ 
compressionAlgorithm;
     }
 
     /**
@@ -90,6 +94,7 @@
                        throw new MalformedURLException("Invalid crypto 
algorithm");
         controlDocument = (extra[2] & 0x02) != 0;
         compressionAlgorithm = (short)(((extra[3] & 0xff) << 8) + (extra[4] & 
0xff));
+        hashCode = Fields.hashCode(routingKey) ^ Fields.hashCode(cryptoKey) ^ 
compressionAlgorithm;
     }
 
     /**
@@ -110,6 +115,7 @@
                dis.readFully(routingKey);
                cryptoKey = new byte[CRYPTO_KEY_LENGTH];
                dis.readFully(cryptoKey);
+        hashCode = Fields.hashCode(routingKey) ^ Fields.hashCode(cryptoKey) ^ 
compressionAlgorithm;
        }
 
        /**
@@ -191,4 +197,19 @@
        public void removeFrom(ObjectContainer container) {
                container.delete(this);
        }
+       
+       public int hashCode() {
+               return hashCode;
+       }
+       
+       public boolean equals(Object o) {
+               if(!(o instanceof ClientCHK)) return false;
+               ClientCHK key = (ClientCHK) o;
+               if(controlDocument != key.controlDocument) return false;
+               if(cryptoAlgorithm != key.cryptoAlgorithm) return false;
+               if(compressionAlgorithm != key.compressionAlgorithm) return 
false;
+               if(!Arrays.equals(routingKey, key.routingKey)) return false;
+               if(!Arrays.equals(cryptoKey, key.cryptoKey)) return false;
+               return true;
+       }
 }

_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to