1 17 18 package org.sape.carbon.services.clustering.test; 19 20 import java.io.InputStream ; 21 import java.io.Serializable ; 22 import java.util.Random ; 23 import java.util.zip.CRC32 ; 24 25 34 public class TestObject implements Serializable { 35 36 private static final int SIZE = 50; 37 38 private byte[] bytes; 39 40 public TestObject() { 41 TestObject.RandomBinarySource source = new 42 TestObject.RandomBinarySource(); 43 bytes = new byte[SIZE]; 44 try { 45 for (int i=0; i < SIZE; i++) { 46 bytes[i] = (byte) source.read(); 47 } 48 } catch (Exception e) { 49 } 51 } 52 53 public int hashCode() { 54 return (new Long (getCrc())).hashCode(); 55 } 56 57 public boolean equals(Object obj) { 58 return ((TestObject)obj).getCrc() == getCrc(); 59 } 60 61 public long getCrc() { 62 CRC32 crc = new CRC32 (); 63 64 crc.update(this.bytes); 65 66 return crc.getValue(); 67 68 } 69 70 71 72 76 static class RandomBinarySource extends InputStream { 77 private Random rand; 78 79 public RandomBinarySource() { 80 super(); 81 rand = new Random (); 82 } 83 84 public int read() 85 throws java.io.IOException { 86 return (rand.nextInt(255)); 87 } 88 89 public void close() { 90 } 91 } 92 93 } 94 | Popular Tags |