Add equals and hashCode to UnwrappedMongoPersistentProperty.

Fixes #3683
Original Pull Request: #3684
This commit is contained in:
Gatto
2021-06-23 21:07:29 -03:00
committed by Christoph Strobl
parent c70c29b2c7
commit 85a30ec915
2 changed files with 64 additions and 0 deletions

View File

@@ -15,8 +15,11 @@
*/
package org.springframework.data.mongodb.core.mapping;
import java.util.Objects;
/**
* @author Christoph Strobl
* @author Rogério Meneguelli Gatto
* @since 3.2
*/
class UnwrapEntityContext {
@@ -30,4 +33,34 @@ class UnwrapEntityContext {
public MongoPersistentProperty getProperty() {
return property;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
return Objects.hash(property);
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
UnwrapEntityContext other = (UnwrapEntityContext) obj;
return Objects.equals(property, other.property);
}
}

View File

@@ -18,6 +18,7 @@ package org.springframework.data.mongodb.core.mapping;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Objects;
import org.springframework.data.mapping.Association;
import org.springframework.data.mapping.PersistentEntity;
@@ -29,6 +30,7 @@ import org.springframework.lang.Nullable;
* Unwrapped variant of {@link MongoPersistentProperty}.
*
* @author Christoph Strobl
* @author Rogério Meneguelli Gatto
* @since 3.2
* @see Unwrapped
*/
@@ -321,4 +323,33 @@ class UnwrappedMongoPersistentProperty implements MongoPersistentProperty {
return delegate.getAccessorForOwner(owner);
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
return Objects.hash(delegate, context);
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
UnwrappedMongoPersistentProperty other = (UnwrappedMongoPersistentProperty) obj;
return Objects.equals(delegate, other.delegate) && Objects.equals(context, other.context);
}
}