DATACMNS-121 - Implement equals(…) and hashCode() of AbstractPersistentProperty.
Implemented equals(…) and hashCode() methods based on the field backing the property.
This commit is contained in:
@@ -202,4 +202,32 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>
|
||||
public Class<?> getMapValueType() {
|
||||
return isMap() ? information.getMapValueType().getType() : null;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(obj instanceof AbstractPersistentProperty)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AbstractPersistentProperty<?> that = (AbstractPersistentProperty<?>) obj;
|
||||
return this.field.equals(that.field);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.field.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +78,34 @@ public class AbstractPersistentPropertyUnitTests {
|
||||
assertThat(property.isEntity(), is(false));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-121
|
||||
*/
|
||||
@Test
|
||||
public void considersPropertiesEqualIfFieldEquals() {
|
||||
|
||||
Field first = ReflectionUtils.findField(FirstConcrete.class, "genericField");
|
||||
Field second = ReflectionUtils.findField(SecondConcrete.class, "genericField");
|
||||
|
||||
SamplePersistentProperty firstProperty = new SamplePersistentProperty(first, null, entity, typeHolder);
|
||||
SamplePersistentProperty secondProperty = new SamplePersistentProperty(second, null, entity, typeHolder);
|
||||
|
||||
assertThat(firstProperty, is(secondProperty));
|
||||
assertThat(firstProperty.hashCode(), is(secondProperty.hashCode()));
|
||||
}
|
||||
|
||||
class Generic<T> {
|
||||
T genericField;
|
||||
}
|
||||
|
||||
class FirstConcrete extends Generic<String> {
|
||||
|
||||
}
|
||||
|
||||
class SecondConcrete extends Generic<Integer> {
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
class TestClassSet extends TreeSet<Object> {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user