Identity { public long computeHash(int seed, Set<String> hashAttributes, AttributesMap attributes) { final IdentityBuilder builder = IdentityBuilder.seed(seed); final Iterable<String> names = hashAttributes.isEmpty() ? attributes.keySet() : hashAttributes; for (String name : names) { final Class<?> type = attributes.getType(name); if (type == String.class) { builder.putString(attributes.getString(name)); } else if (type == Long.class) { builder.putLong(attributes.getNumber(name)); } else if (type == Boolean.class) { builder.putBoolean(attributes.getBoolean(name)); } } return builder.hash(); }  long computeHash(int seed, Set<String> hashAttributes, AttributesMap attributes); abstract AttributesMap computeAttributes(); static Set<String> getSupportedAttributes(Class<T> clazz);  }
@Test public void testComputeHashcodeOrderMatters() { final IdentityTest identity = new IdentityTest(); final AttributesMap map = AttributesMap.newBuilder().put("foo", "foo").put("bar", "bar").build(); final Set<String> fooBar = Sets.newLinkedHashSet(Lists.newArrayList("foo", "bar")); final Set<String> barFoo = Sets.newLinkedHashSet(Lists.newArrayList("bar", "foo")); final int seed = 0; assertEquals(identity.computeHash(seed, fooBar, map), identity.computeHash(seed, fooBar, map)); assertEquals(identity.computeHash(seed, barFoo, map), identity.computeHash(seed, barFoo, map)); assertNotEquals(identity.computeHash(seed, fooBar, map), identity.computeHash(seed, barFoo, map)); assertNotEquals(identity.computeHash(seed, barFoo, map), identity.computeHash(seed, fooBar, map)); }