Skip to content

Commit 85a30ec

Browse files
Gattochristophstrobl
Gatto
authored andcommitted
Add equals and hashCode to UnwrappedMongoPersistentProperty.
Fixes #3683 Original Pull Request: #3684
1 parent c70c29b commit 85a30ec

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/UnwrapEntityContext.java

+33
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
*/
1616
package org.springframework.data.mongodb.core.mapping;
1717

18+
import java.util.Objects;
19+
1820
/**
1921
* @author Christoph Strobl
22+
* @author Rogério Meneguelli Gatto
2023
* @since 3.2
2124
*/
2225
class UnwrapEntityContext {
@@ -30,4 +33,34 @@ public UnwrapEntityContext(MongoPersistentProperty property) {
3033
public MongoPersistentProperty getProperty() {
3134
return property;
3235
}
36+
37+
/*
38+
* (non-Javadoc)
39+
*
40+
* @see java.lang.Object#hashCode()
41+
*/
42+
@Override
43+
public int hashCode() {
44+
return Objects.hash(property);
45+
}
46+
47+
/*
48+
* (non-Javadoc)
49+
*
50+
* @see java.lang.Object#equals(java.lang.Object)
51+
*/
52+
@Override
53+
public boolean equals(Object obj) {
54+
if (this == obj) {
55+
return true;
56+
}
57+
58+
if (obj == null || getClass() != obj.getClass()) {
59+
return false;
60+
}
61+
62+
UnwrapEntityContext other = (UnwrapEntityContext) obj;
63+
64+
return Objects.equals(property, other.property);
65+
}
3366
}

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/UnwrappedMongoPersistentProperty.java

+31
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.lang.annotation.Annotation;
1919
import java.lang.reflect.Field;
2020
import java.lang.reflect.Method;
21+
import java.util.Objects;
2122

2223
import org.springframework.data.mapping.Association;
2324
import org.springframework.data.mapping.PersistentEntity;
@@ -29,6 +30,7 @@
2930
* Unwrapped variant of {@link MongoPersistentProperty}.
3031
*
3132
* @author Christoph Strobl
33+
* @author Rogério Meneguelli Gatto
3234
* @since 3.2
3335
* @see Unwrapped
3436
*/
@@ -321,4 +323,33 @@ public <T> PersistentPropertyAccessor<T> getAccessorForOwner(T owner) {
321323
return delegate.getAccessorForOwner(owner);
322324
}
323325

326+
/*
327+
* (non-Javadoc)
328+
*
329+
* @see java.lang.Object#hashCode()
330+
*/
331+
@Override
332+
public int hashCode() {
333+
return Objects.hash(delegate, context);
334+
}
335+
336+
/*
337+
* (non-Javadoc)
338+
*
339+
* @see java.lang.Object#equals(java.lang.Object)
340+
*/
341+
@Override
342+
public boolean equals(Object obj) {
343+
if (this == obj) {
344+
return true;
345+
}
346+
347+
if (obj == null || getClass() != obj.getClass()) {
348+
return false;
349+
}
350+
351+
UnwrappedMongoPersistentProperty other = (UnwrappedMongoPersistentProperty) obj;
352+
353+
return Objects.equals(delegate, other.delegate) && Objects.equals(context, other.context);
354+
}
324355
}

0 commit comments

Comments
 (0)