55
66import de .danielbechler .diff .Configuration ;
77import de .danielbechler .diff .ObjectDifferFactory ;
8+ import de .danielbechler .diff .annotation .ObjectDiffMethodEqualsType ;
89import de .danielbechler .diff .annotation .ObjectDiffProperty ;
9- import de .danielbechler .diff .example .IgnoreExample .User ;
1010import de .danielbechler .diff .node .Node ;
1111import de .danielbechler .diff .path .PropertyPath ;
1212import de .danielbechler .diff .visitor .PrintingVisitor ;
@@ -18,17 +18,15 @@ private MethodEqualExample()
1818
1919 public static void main (final String [] args )
2020 {
21- List <Object > baseItems = new ArrayList <Object >();
22- baseItems .add ("baseitem" );
23- final EncompassingClass base = new EncompassingClass (baseItems );
24- List <Object > workingItems = new ArrayList <Object >();
25- workingItems .add ("workingitem" );
26- final EncompassingClass working = new EncompassingClass (workingItems );
21+ PropertyClass prop = new PropertyClass ("1" , "2" );
22+ final EncompassingClass base = new EncompassingClass (prop );
23+ PropertyClass prop2 = new PropertyClass ("1" , "3" );
24+ final EncompassingClass working = new EncompassingClass (prop2 );
2725
2826 final Configuration configuration = new Configuration ();
2927
30- // (Option 1) Causes the ObjectDiffer to use the method "size " on the 'items ' property of the root object
31- configuration .withMethodEqualsProperty (PropertyPath .buildWith ("items " ), "size " );
28+ // (Option 1) Causes the ObjectDiffer to compare using the method "getProp1 " on the 'prop ' property of the root object
29+ configuration .withMethodEqualsProperty (PropertyPath .buildWith ("prop " ), "getProp1 " );
3230
3331 final Node node = ObjectDifferFactory .getInstance (configuration ).compare (working , base );
3432
@@ -37,24 +35,42 @@ public static void main(final String[] args)
3735 // Output with ignore:
3836 // Property at path '/' has not changed
3937 // Output without ignore:
40- // Property at path '/items[workingitem]' has been added => [ workingitem ]
41- // Property at path '/items[baseitem]' with value [ baseitem ] has been removed
38+ // Property at path '/prop/prop2' has changed from [ 2 ] to [ 3 ]
4239 }
4340
4441 public static class EncompassingClass
4542 {
46- private final List < Object > items ;
43+ private final PropertyClass prop ;
4744
48- public EncompassingClass (final List < Object > items )
45+ public EncompassingClass (final PropertyClass prop )
4946 {
50- this .items = items ;
47+ this .prop = prop ;
5148 }
5249
53- /* (Option 2) This annotation causes the ObjectDiffer to always ignore this property */
54- @ ObjectDiffProperty (methodEqual = "size" )
55- public List <Object > getItems ()
50+ /* (Option 2) This annotation causes the ObjectDiffer to use getProp1 method to compare */
51+ //@ObjectDiffProperty(methodEqual = "getProp1")
52+ public PropertyClass getProp () {
53+ return prop ;
54+ }
55+ }
56+
57+ /* (Option 3) This annotation causes the ObjectDiffer to use getProp1 method to compare */
58+ //@ObjectDiffMethodEqualsType(method="getProp1")
59+ public static class PropertyClass
60+ {
61+ private String prop1 ;
62+ private String prop2 ;
63+
64+ public PropertyClass (String prop1 , String prop2 )
5665 {
57- return items ;
66+ this .prop1 = prop1 ;
67+ this .prop2 = prop2 ;
68+ }
69+ public String getProp1 () {
70+ return prop1 ;
71+ }
72+ public String getProp2 () {
73+ return prop2 ;
5874 }
5975 }
6076
0 commit comments