AttributeKey { @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } AttributeKey<?> other = (AttributeKey<?>) obj; return hashCode == other.hashCode; } AttributeKey(Class<T> attributeType, String attributeName); static AttributeKey<T> createKey(Class<T> attributeType, String attributeName); String getName(); Class<T> getType(); @Override int hashCode(); @Override boolean equals(Object obj);  }
@Test public void equalsSymmetric() throws Exception { AttributeKey<Number> key1 = new AttributeKey<Number>(Number.class, "keyName"); AttributeKey<Number> key2 = new AttributeKey<Number>(Number.class, "keyName"); assertThat(key1.equals(key2), is(true)); assertThat(key2.equals(key1), is(true)); }
@Test public void equalsWithDifferentTypes() throws Exception { AttributeKey<Number> key1 = new AttributeKey<Number>(Number.class, "keyName"); AttributeKey<Date> key2 = new AttributeKey<Date>(Date.class, "keyName"); assertThat(key1.equals(key2), is(false)); assertThat(key2.equals(key1), is(false)); }
@Test public void equalsWithDifferentName() throws Exception { AttributeKey<Number> key1 = new AttributeKey<Number>(Number.class, "key1"); AttributeKey<Number> key2 = new AttributeKey<Number>(Number.class, "key2"); assertThat(key1.equals(key2), is(false)); assertThat(key2.equals(key1), is(false)); }