public class EqualsHashCodeResetter<T>
extends java.lang.Object
Instances of this class are used to reset overwritten Object.equals(Object)
and Object.hashCode()
methods of the wrapped child element to the
default Java implementation with referenced based equality.
A possible use case of this class is for instance the usage in Collection
like Map
s. Imagine the following scenario: A Map<Customer, ...>
maps
Customer
instances to something. Each customer has a unique ID and Object.equals(Object)
and Object.hashCode()
is overwritten to compare instances by their unique ID.
If now a clone of a Customer
instance exists the Map
will return the value object
for the original Customer
instance. The Map
can not separate between original and clone.
If instead a Map<EqualsHashCodeResetter<Customer>, ...>
is used original and clone are different
because the default Java implementation with referenced based equality is used.
Modifier and Type | Field and Description |
---|---|
private T |
wrappedElement
The wrapped elements on that
equals(Object) and
hashCode() is reset to default Java implementation. |
Constructor and Description |
---|
EqualsHashCodeResetter(T wrappedElement)
Constructor
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object obj)
Overwritten to restore default Java implementation with reference based equality.
|
T |
getWrappedElement()
Returns the wrapped elements on that
equals(Object) and
hashCode() is reset to default Java implementation. |
int |
hashCode()
Overwritten to restore default Java implementation with reference based equality.
|
private T wrappedElement
equals(Object)
and
hashCode()
is reset to default Java implementation.public EqualsHashCodeResetter(T wrappedElement)
wrappedElement
- the wrapped elements on that equals(Object)
and hashCode()
is reset to default Java implementation.public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public T getWrappedElement()
equals(Object)
and
hashCode()
is reset to default Java implementation.