@Override public int hashCode() { HashFunction hf = Hashing.goodFastHash(32); Hasher h = hf.newHasher(); h.putInt(slots.size()); for (int i = 0; i < slots.size(); i++) { h.putInt(slots.get(i).size()); for (int j = 0; j < slots.size(); j++) { h.putBytes(slots.get(i).get(j).getLowerRange()); h.putBytes(slots.get(i).get(j).getUpperRange()); } } return h.hash().asInt(); }
public void testPutAfterHash() { Hasher sha1 = Hashing.sha1().newHasher(); assertEquals( "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12", sha1.putString("The quick brown fox jumps over the lazy dog", Charsets.UTF_8) .hash() .toString()); try { sha1.putInt(42); fail(); } catch (IllegalStateException expected) { } }