Skip to content

Commit 6644ac6

Browse files
Gattochristophstrobl
Gatto
authored andcommitted
Add equals and hashCode to UnwrappedMongoPersistentProperty.
Fixes #3683 Original Pull Request: #3684
1 parent 708def0 commit 6644ac6

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-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

+32
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
*/
@@ -304,4 +306,34 @@ public Class<?> getAssociationTargetType() {
304306
public <T> PersistentPropertyAccessor<T> getAccessorForOwner(T owner) {
305307
return delegate.getAccessorForOwner(owner);
306308
}
309+
310+
/*
311+
* (non-Javadoc)
312+
*
313+
* @see java.lang.Object#hashCode()
314+
*/
315+
@Override
316+
public int hashCode() {
317+
return Objects.hash(delegate, context);
318+
}
319+
320+
/*
321+
* (non-Javadoc)
322+
*
323+
* @see java.lang.Object#equals(java.lang.Object)
324+
*/
325+
@Override
326+
public boolean equals(Object obj) {
327+
if (this == obj) {
328+
return true;
329+
}
330+
331+
if (obj == null || getClass() != obj.getClass()) {
332+
return false;
333+
}
334+
335+
UnwrappedMongoPersistentProperty other = (UnwrappedMongoPersistentProperty) obj;
336+
337+
return Objects.equals(delegate, other.delegate) && Objects.equals(context, other.context);
338+
}
307339
}

0 commit comments

Comments
 (0)