@Override public int hashCode() { int result = dimension.hashCode(); result = 31 * result + (hash != null ? hash.hashCode() : 0); result = 31 * result + (extractionFn != null ? extractionFn.hashCode() : 0); return result; } }
public void testObjectHashCode() { HashCode hashCode42 = HashCode.fromInt(42); assertEquals(42, hashCode42.hashCode()); }
public void testObjectHashCodeWithSameLowOrderBytes() { // These will have the same first 4 bytes (all 0). byte[] bytesA = new byte[5]; byte[] bytesB = new byte[5]; // Change only the last (5th) byte bytesA[4] = (byte) 0xbe; bytesB[4] = (byte) 0xef; HashCode hashCodeA = HashCode.fromBytes(bytesA); HashCode hashCodeB = HashCode.fromBytes(bytesB); // They aren't equal... assertFalse(hashCodeA.equals(hashCodeB)); // But they still have the same Object#hashCode() value. // Technically not a violation of the equals/hashCode contract, but...? assertEquals(hashCodeA.hashCode(), hashCodeB.hashCode()); }
@Override public boolean acceptOffset(long offset) { int hashValue = Math.abs(strategy == DequeueStrategy.HASH ? 0 : ROUND_ROBIN_HASHER.hashLong(offset).hashCode()); return instanceId == (hashValue % groupSize); } };
@Override public int hashCode() { ensureHashCode(); return goodHashCode.hashCode(); } }
/** * FIXME why is this a long when crc32 returns an int? * @return a checksum of the graph, for use in verifying whether it changed or remained the same after * some operation. */ public long checksum () { LOG.info("Calculating transport network checksum..."); try { File tempFile = File.createTempFile("r5-network-checksum-", ".dat"); tempFile.deleteOnExit(); KryoNetworkSerializer.write(this, tempFile); HashCode crc32 = Files.hash(tempFile, Hashing.crc32()); tempFile.delete(); LOG.info("Network CRC is {}", crc32.hashCode()); return crc32.hashCode(); } catch (IOException e) { throw new RuntimeException(); } }
/** * FIXME why is this a long when crc32 returns an int? * @return a checksum of the graph, for use in verifying whether it changed or remained the same after * some operation. */ public long checksum () { LOG.info("Calculating transport network checksum..."); try { File tempFile = File.createTempFile("r5-network-checksum-", ".dat"); tempFile.deleteOnExit(); KryoNetworkSerializer.write(this, tempFile); HashCode crc32 = Files.hash(tempFile, Hashing.crc32()); tempFile.delete(); LOG.info("Network CRC is {}", crc32.hashCode()); return crc32.hashCode(); } catch (IOException e) { throw new RuntimeException(); } }
@Override public int hashCode() { return Hashing.md5().newHasher().putInt(a).putChar('.').putInt(b).putChar('.').putInt(c) .putChar('.').putInt(d).hash().hashCode(); }
@Override public int hashCode() { return Hashing.md5().newHasher().putInt(a).putChar('.').putInt(b).putChar('.').putInt(c) .putChar('.').putInt(d).hash().hashCode(); }
public void testObjectHashCode() { HashCode hashCode42 = HashCode.fromInt(42); assertEquals(42, hashCode42.hashCode()); }
public void testObjectHashCodeWithSameLowOrderBytes() { // These will have the same first 4 bytes (all 0). byte[] bytesA = new byte[5]; byte[] bytesB = new byte[5]; // Change only the last (5th) byte bytesA[4] = (byte) 0xbe; bytesB[4] = (byte) 0xef; HashCode hashCodeA = HashCode.fromBytes(bytesA); HashCode hashCodeB = HashCode.fromBytes(bytesB); // They aren't equal... assertFalse(hashCodeA.equals(hashCodeB)); // But they still have the same Object#hashCode() value. // Technically not a violation of the equals/hashCode contract, but...? assertEquals(hashCodeA.hashCode(), hashCodeB.hashCode()); }