@@ -77,8 +77,10 @@ public enum PrimitiveDefaultValueMode
7777 private final Collection <PropertyPath > includedProperties = new HashSet <PropertyPath >(10 );
7878 private final Collection <PropertyPath > excludedProperties = new HashSet <PropertyPath >(10 );
7979 private final Collection <PropertyPath > equalsOnlyProperties = new LinkedHashSet <PropertyPath >(10 );
80+ private final Collection <PropertyPathAndMethod > equalsOnlyValueProviderMethods = new LinkedHashSet <PropertyPathAndMethod >(10 );
8081 private final Collection <Class <?>> compareToOnlyTypes = new LinkedHashSet <Class <?>>(10 );
8182 private final Collection <Class <?>> equalsOnlyTypes = new LinkedHashSet <Class <?>>(10 );
83+ private final Collection <ClassAndMethod > equalsOnlyValueProviderTypes = new LinkedHashSet <ClassAndMethod >(10 );
8284 private boolean returnUnchangedNodes = false ;
8385 private boolean returnIgnoredNodes = false ;
8486 private boolean returnCircularNodes = true ;
@@ -124,7 +126,7 @@ public Configuration withoutProperty(final PropertyPath propertyPath)
124126 this .excludedProperties .add (propertyPath );
125127 return this ;
126128 }
127- 129+
128130 public Configuration withCompareToOnlyType (final Class <?> type )
129131 {
130132 this .compareToOnlyTypes .add (type );
@@ -143,12 +145,22 @@ public Configuration withEqualsOnlyProperty(final PropertyPath propertyPath)
143145 return this ;
144146 }
145147
148+ public Configuration withEqualsOnlyValueProviderMethod (final PropertyPath propertyPath , final String methodName ) {
149+ this .equalsOnlyValueProviderMethods .add (new PropertyPathAndMethod (propertyPath , methodName ));
150+ return this ;
151+ }
152+ 153+ public Configuration withEqualsOnlyValueProviderMethod (PropertyPathAndMethod propertyPathEqualsMethod ) {
154+ this .equalsOnlyValueProviderMethods .add (propertyPathEqualsMethod );
155+ return this ;
156+ }
157+ 146158 public Configuration withIgnoredNodes ()
147159 {
148160 this .returnIgnoredNodes = true ;
149161 return this ;
150162 }
151- 163+
152164 public Configuration withoutIgnoredNodes ()
153165 {
154166 this .returnIgnoredNodes = false ;
@@ -309,6 +321,57 @@ public boolean isEqualsOnly(final Node node)
309321 }
310322 return false ;
311323 }
324+ 325+ public boolean hasEqualsOnlyValueProviderMethod (Node node ){
326+ return getEqualsOnlyValueProviderMethod (node ) != null ;
327+ }
328+ 329+ public String getEqualsOnlyValueProviderMethod (Node node ){
330+ final Class <?> propertyType = node .getType ();
331+ if (propertyType != null )
332+ {
333+ ObjectDiffEqualsOnlyValueProvidedType annotation = propertyType .getAnnotation (ObjectDiffEqualsOnlyValueProvidedType .class );
334+ if (annotation != null )
335+ {
336+ return annotation .method ();
337+ }
338+ 339+ ClassAndMethod applicable = findEqualsOnlyValueProviderMethodForClass (propertyType );
340+ if (applicable != null )
341+ {
342+ return applicable .getMethod ();
343+ }
344+ }
345+ if (node .hasEqualsOnlyValueProviderMethod ())
346+ {
347+ return node .getEqualsOnlyValueProviderMethod ();
348+ }
349+ PropertyPathAndMethod applicable = findEqualsOnlyValueProviderMethodForPath (node .getPropertyPath ());
350+ if (applicable != null )
351+ {
352+ return applicable .getMethod ();
353+ }
354+ return null ;
355+ }
356+ 357+ private ClassAndMethod findEqualsOnlyValueProviderMethodForClass (Class <?> clazz ){
358+ for (ClassAndMethod propertyPathEqualsOnValueProviderType : equalsOnlyValueProviderTypes ){
359+ if (clazz .equals (propertyPathEqualsOnValueProviderType .getClazz ())){
360+ return propertyPathEqualsOnValueProviderType ;
361+ }
362+ }
363+ return null ;
364+ 365+ }
366+ 367+ private PropertyPathAndMethod findEqualsOnlyValueProviderMethodForPath (PropertyPath propertyPath ){
368+ for (PropertyPathAndMethod propertyPathEqualsOnValueProviderMethod : equalsOnlyValueProviderMethods ){
369+ if (propertyPath .equals (propertyPathEqualsOnValueProviderMethod .getPropertyPath ())){
370+ return propertyPathEqualsOnValueProviderMethod ;
371+ }
372+ }
373+ return null ;
374+ }
312375
313376 public boolean isReturnable (final Node node )
314377 {
@@ -347,4 +410,5 @@ else if (node.isRemoved())
347410 }
348411 return true ;
349412 }
413+ 350414}
0 commit comments