2424import de .danielbechler .diff .selector .ElementSelector ;
2525import de .danielbechler .util .Assert ;
2626
27+ import java .util .Collection ;
2728import java .util .Collection ;
2829import java .util .HashMap ;
2930import java .util .LinkedList ;
@@ -49,6 +50,16 @@ public class InclusionService implements InclusionConfigurer, IsIgnoredResolver
4950 private final ToExclude excludeAndReturn = new ToExcludeAndReturnImpl ();
5051 private final TypePropertyConfigInclusionResolver typePropertyConfigInclusionResolver = new TypePropertyConfigInclusionResolver ();
5152 private final Collection <InclusionResolver > inclusionResolvers = new LinkedList <InclusionResolver >();
53+ // Patched : Inclusion boolean properties
54+ private boolean categoryInclusion = false ;
55+ private boolean propertyNameInclusion = false ;
56+ private boolean nodePathInclusion = false ;
57+ private boolean typeInclusion = false ;
58+ // Patched : Exclusion boolean properties
59+ private boolean categoryExclusion = false ;
60+ private boolean nodePathExclusion = false ;
61+ private boolean propertyNameExclusion = false ;
62+ private boolean typeExclusion = false ;
5263
5364 public InclusionService (final CategoryResolver categoryResolver , final ObjectDifferBuilder rootConfiguration )
5465 {
@@ -74,23 +85,16 @@ private boolean isExcluded(final DiffNode node)
7485 return true ;
7586 }
7687 }
77- if (isExcludedByPath (node ))
78- {
79- return true ;
80- }
81- else if (isExcludedByCategory (node ))
82- {
83- return true ;
84- }
85- else if (isExcludedByType (node ))
86- {
87- return true ;
88- }
89- else if (isExcludedByPropertyName (node ))
90- {
91- return true ;
88+ // Patched : Check if there are exclusions before browsing all excluded elements
89+ if (hasExclusions ()) {
90+ if (isExcludedByPath (node ) || isExcludedByCategory (node )) {
91+ return true ;
92+ } else if (isExcludedByType (node ) || isExcludedByPropertyName (node )) {
93+ return true ;
94+ }
9295 }
9396 return false ;
97+
9498 }
9599
96100 private boolean isIncluded (final DiffNode node )
@@ -105,113 +109,109 @@ private boolean isIncluded(final DiffNode node)
105109 {
106110 return true ;
107111 }
108- }
109- if (hasInclusions (INCLUDED , node ))
110- {
111- if (isIncludedByPath (node ))
112- {
113- return true ;
114- }
115- else if (isIncludedByCategory (node ))
116- {
112+ }
113+ // Patched : Check if there are inclusions before browsing all included elements
114+ if (hasInclusions ()) {
115+ if (node .isRootNode ()) {
117116 return true ;
118- }
119- else if (isIncludedByType (node ))
120- {
117+ } else if (isIncludedByPath (node ) || isIncludedByCategory (node )) {
121118 return true ;
122- }
123- else if (isIncludedByPropertyName (node ))
124- {
119+ } else if (isIncludedByType (node ) || isIncludedByPropertyName (node )) {
125120 return true ;
126121 }
127122 return false ;
128123 }
129124 return true ;
130125 }
131126
132- private boolean isExcludedByPath (final DiffNode node )
133- {
134- final InclusionNode valueNode = nodeInclusions .getNodeForPath (node .getPath ());
135- if (valueNode .isExcluded () && !valueNode .containsValue (INCLUDED ))
136- {
137- return true ;
138- }
139- return false ;
127+ private boolean hasInclusions () {
128+ // Patched : Now return if inclusions have been configured
129+ return nodePathInclusion || categoryInclusion || typeInclusion || propertyNameInclusion ;
140130 }
141-
142- private boolean isExcludedByCategory ( final DiffNode node )
143- {
144- return hasCategoryWithInclusion ( node , EXCLUDED ) ;
131+
132+ private boolean hasExclusions () {
133+ // Patched (New method) : Now return if exclusions have been configured
134+ return nodePathExclusion || categoryExclusion || typeExclusion || propertyNameExclusion ;
145135 }
146136
147- private boolean isExcludedByType (final DiffNode node )
137+ private boolean isIncludedByPath (final DiffNode node )
148138 {
149- if ( node . getValueType () != null )
150- {
151- return typeInclusions . get ( node . getValueType ()) == EXCLUDED ;
139+ // Patched : First check if nodePath inclusions have been configured
140+ if ( nodePathInclusion && nodeInclusions . getNodeForPath ( node . getPath ()). isIncluded ()) {
141+ return true ;
152142 }
153143 return false ;
154144 }
155145
156- private boolean isExcludedByPropertyName (final DiffNode node )
146+ private boolean isIncludedByCategory (final DiffNode node )
157147 {
158- final String propertyName = node .getPropertyName ();
159- if (propertyName != null && propertyNameInclusions .get (propertyName ) == EXCLUDED )
160- {
148+ // Patched : First check if category inclusions have been configured
149+ if (categoryInclusion && hasCategoryWithInclusion (node , INCLUDED )) {
161150 return true ;
162151 }
163152 return false ;
164153 }
165154
166- private boolean hasInclusions ( final Inclusion inclusion , final DiffNode node )
155+ private boolean isIncludedByType ( final DiffNode node )
167156 {
168- if (nodeInclusions .containsValue (inclusion ))
169- {
170- return true ;
171- }
172- if (typeInclusions .containsValue (inclusion ))
173- {
174- return true ;
175- }
176- if (categoryInclusions .containsValue (inclusion ))
177- {
178- return true ;
179- }
180- if (propertyNameInclusions .containsValue (inclusion ))
181- {
157+ // Patched : First check if type inclusions have been configured
158+ if (typeInclusion && typeInclusions .get (node .getValueType ()) == INCLUDED ) {
182159 return true ;
183160 }
184161 return false ;
185162 }
186163
187- private boolean isIncludedByPath (final DiffNode node )
164+ private boolean isIncludedByPropertyName (final DiffNode node )
188165 {
189- return nodeInclusions .getNodeForPath (node .getPath ()).isIncluded ();
166+ // Patched : First check if property name inclusions have been configured
167+ if (propertyNameInclusion ) {
168+ if (isIncludedByOwnPropertyName (node )) {
169+ return true ;
170+ } else if (isIncludedByParentPropertyName (node )) {
171+ return true ;
172+ }
173+ }
174+ return false ;
190175 }
191176
192- private boolean isIncludedByCategory (final DiffNode node )
177+ private boolean isExcludedByPath (final DiffNode node )
193178 {
194- return hasCategoryWithInclusion (node , INCLUDED );
179+ // Patched : First check if node path exclusions have been configured
180+ if (nodePathExclusion ) {
181+ final InclusionNode valueNode = nodeInclusions .getNodeForPath (node .getPath ());
182+ if (valueNode .isExcluded () && !valueNode .containsValue (INCLUDED )) {
183+ return true ;
184+ }
185+ }
186+ return false ;
195187 }
196188
197- private boolean isIncludedByType (final DiffNode node )
189+ private boolean isExcludedByCategory (final DiffNode node )
198190 {
199- if ( typeInclusions . get ( node . getValueType ()) == INCLUDED )
200- {
191+ // Patched : First check if category exclusions have been configured
192+ if ( categoryExclusion && hasCategoryWithInclusion ( node , EXCLUDED )) {
201193 return true ;
202194 }
203195 return false ;
204196 }
205197
206- private boolean isIncludedByPropertyName (final DiffNode node )
198+ private boolean isExcludedByType (final DiffNode node )
207199 {
208- if ( isIncludedByOwnPropertyName ( node ))
209- {
210- return true ;
200+ // Patched : First check if type exclusions have been configured
201+ if ( typeExclusion && node . getValueType () != null ) {
202+ return typeInclusions . get ( node . getValueType ()) == EXCLUDED ;
211203 }
212- else if (isIncludedByParentPropertyName (node ))
213- {
214- return true ;
204+ return false ;
205+ }
206+
207+ private boolean isExcludedByPropertyName (final DiffNode node )
208+ {
209+ // Patched : First check if property name exclusions have been configured
210+ if (propertyNameExclusion ) {
211+ final String propertyName = node .getPropertyName ();
212+ if (propertyName != null ) {
213+ return propertyNameInclusions .get (propertyName ) == EXCLUDED ;
214+ }
215215 }
216216 return false ;
217217 }
@@ -286,24 +286,32 @@ public ObjectDifferBuilder and()
286286
287287 public ToExcludeAndReturn category (final String category )
288288 {
289+ // Patched : Indicates that there are category exclusions
290+ categoryExclusion = true ;
289291 categoryInclusions .put (category , EXCLUDED );
290292 return this ;
291293 }
292294
293295 public ToExcludeAndReturn type (final Class <?> type )
294296 {
297+ // Patched : Indicates that there are type exclusions
298+ typeExclusion = true ;
295299 typeInclusions .put (type , EXCLUDED );
296300 return this ;
297301 }
298302
299303 public ToExcludeAndReturn node (final NodePath nodePath )
300304 {
305+ // Patched : Indicates that there are nodePath exclusions
306+ nodePathExclusion = true ;
301307 nodeInclusions .getNodeForPath (nodePath ).setValue (EXCLUDED );
302308 return this ;
303309 }
304310
305311 public ToExcludeAndReturn propertyName (final String propertyName )
306312 {
313+ // Patched : Indicates that there are property name exclusions
314+ propertyNameExclusion = true ;
307315 propertyNameInclusions .put (propertyName , EXCLUDED );
308316 return this ;
309317 }
@@ -335,25 +343,33 @@ public ObjectDifferBuilder and()
335343
336344 public ToIncludeAndReturn category (final String category )
337345 {
346+ // Patched : Indicates that there are category inclusions
347+ categoryInclusion = true ;
338348 categoryInclusions .put (category , INCLUDED );
339349 return this ;
340350 }
341351
342352 public ToIncludeAndReturn type (final Class <?> type )
343353 {
354+ // Patched : Indicates that there are type inclusions
355+ typeInclusion = true ;
344356 typeInclusions .put (type , INCLUDED );
345357 return this ;
346358 }
347359
348360 public ToIncludeAndReturn node (final NodePath nodePath )
349361 {
362+ // Patched : Indicates that there are nodePath inclusions
363+ nodePathInclusion = true ;
350364 nodeInclusions .getNodeForPath (nodePath ).setValue (INCLUDED );
351365 return this ;
352366 }
353367
354368 public ToIncludeAndReturn propertyName (final String propertyName )
355369 {
356370 Assert .hasText (propertyName , "propertyName" );
371+ // Patched : Indicates that there are property name inclusions
372+ propertyNameInclusion = true ;
357373 propertyNameInclusions .put (propertyName , INCLUDED );
358374 return this ;
359375 }
@@ -375,4 +391,4 @@ public ToExclude exclude()
375391 return InclusionService .this .exclude ();
376392 }
377393 }
378- }
394+ }
0 commit comments