@@ -44,6 +44,16 @@ public class InclusionService implements InclusionConfigurer, IsIgnoredResolver
4444 private final Map <String , Inclusion > propertyNameInclusions = new HashMap <String , Inclusion >();
4545 private final ToInclude includeAndReturn = new ToIncludeAndReturnImpl ();
4646 private final ToExclude excludeAndReturn = new ToExcludeAndReturnImpl ();
47+ // Patched : Inclusion boolean properties
48+ private boolean categoryInclusion = false ;
49+ private boolean propertyNameInclusion = false ;
50+ private boolean nodePathInclusion = false ;
51+ private boolean typeInclusion = false ;
52+ // Patched : Exclusion boolean properties
53+ private boolean categoryExclusion = false ;
54+ private boolean nodePathExclusion = false ;
55+ private boolean propertyNameExclusion = false ;
56+ private boolean typeExclusion = false ;
4757
4858 public InclusionService (final CategoryResolver categoryResolver , final ObjectDifferBuilder rootConfiguration )
4959 {
@@ -60,26 +70,13 @@ public boolean isIgnored(final DiffNode node)
6070
6171 private boolean isIncluded (final DiffNode node )
6272 {
63- if (hasInclusions (INCLUDED ))
64- {
65- if (node .isRootNode ())
66- {
67- return true ;
68- }
69- else if (isIncludedByPath (node ))
70- {
71- return true ;
72- }
73- else if (isIncludedByCategory (node ))
74- {
73+ // Patched : Check if there are inclusions before browsing all included elements
74+ if (hasInclusions ()) {
75+ if (node .isRootNode ()) {
7576 return true ;
76- }
77- else if (isIncludedByType (node ))
78- {
77+ } else if (isIncludedByPath (node ) || isIncludedByCategory (node )) {
7978 return true ;
80- }
81- else if (isIncludedByPropertyName (node ))
82- {
79+ } else if (isIncludedByType (node ) || isIncludedByPropertyName (node )) {
8380 return true ;
8481 }
8582 return false ;
@@ -89,115 +86,105 @@ else if (isIncludedByPropertyName(node))
8986
9087 private boolean isExcluded (final DiffNode node )
9188 {
92- if (hasInclusions (EXCLUDED ))
93- {
94- if (isExcludedByPath (node ))
95- {
96- return true ;
97- }
98- else if (isExcludedByCategory (node ))
99- {
100- return true ;
101- }
102- else if (isExcludedByType (node ))
103- {
89+ // Patched : Check if there are exclusions before browsing all excluded elements
90+ if (hasExclusions ()) {
91+ if (isExcludedByPath (node ) || isExcludedByCategory (node )) {
10492 return true ;
105- }
106- else if (isExcludedByPropertyName (node ))
107- {
93+ } else if (isExcludedByType (node ) || isExcludedByPropertyName (node )) {
10894 return true ;
10995 }
11096 }
11197 return false ;
11298 }
11399
114- private boolean hasInclusions (final Inclusion inclusion )
115- {
116- if (nodeInclusions .containsValue (inclusion ))
117- {
118- return true ;
119- }
120- if (typeInclusions .containsValue (inclusion ))
121- {
122- return true ;
123- }
124- if (categoryInclusions .containsValue (inclusion ))
125- {
126- return true ;
127- }
128- if (propertyNameInclusions .containsValue (inclusion ))
129- {
130- return true ;
131- }
132- return false ;
100+ private boolean hasInclusions () {
101+ // Patched : Now return if inclusions have been configured
102+ return nodePathInclusion || categoryInclusion || typeInclusion || propertyNameInclusion ;
103+ }
104+
105+ private boolean hasExclusions () {
106+ // Patched (New method) : Now return if exclusions have been configured
107+ return nodePathExclusion || categoryExclusion || typeExclusion || propertyNameExclusion ;
133108 }
134109
135110 private boolean isIncludedByPath (final DiffNode node )
136111 {
137- return nodeInclusions .getNodeForPath (node .getPath ()).isIncluded ();
112+ // Patched : First check if nodePath inclusions have been configured
113+ if (nodePathInclusion && nodeInclusions .getNodeForPath (node .getPath ()).isIncluded ()) {
114+ return true ;
115+ }
116+ return false ;
138117 }
139118
140119 private boolean isIncludedByCategory (final DiffNode node )
141120 {
142- return hasCategoryWithInclusion (node , INCLUDED );
121+ // Patched : First check if category inclusions have been configured
122+ if (categoryInclusion && hasCategoryWithInclusion (node , INCLUDED )) {
123+ return true ;
124+ }
125+ return false ;
143126 }
144127
145128 private boolean isIncludedByType (final DiffNode node )
146129 {
147- if ( typeInclusions . get ( node . getValueType ()) == INCLUDED )
148- {
130+ // Patched : First check if type inclusions have been configured
131+ if ( typeInclusion && typeInclusions . get ( node . getValueType ()) == INCLUDED ) {
149132 return true ;
150133 }
151- // else if (node.getParentNode() != null && typeInclusions.get(node.getParentNode().getValueType()) == INCLUDED)
152- // {
153- // return true;
154- // }
155134 return false ;
156135 }
157136
158137 private boolean isIncludedByPropertyName (final DiffNode node )
159138 {
160- if ( isIncludedByOwnPropertyName ( node ))
161- {
162- return true ;
163- }
164- else if (isIncludedByParentPropertyName (node ))
165- {
166- return true ;
139+ // Patched : First check if property name inclusions have been configured
140+ if ( propertyNameInclusion ) {
141+ if ( isIncludedByOwnPropertyName ( node )) {
142+ return true ;
143+ } else if (isIncludedByParentPropertyName (node )) {
144+ return true ;
145+ }
167146 }
168147 return false ;
169148 }
170149
171150 private boolean isExcludedByPath (final DiffNode node )
172151 {
173- final InclusionNode valueNode = nodeInclusions .getNodeForPath (node .getPath ());
174- if (valueNode .isExcluded () && !valueNode .containsValue (INCLUDED ))
175- {
176- return true ;
152+ // Patched : First check if node path exclusions have been configured
153+ if (nodePathExclusion ) {
154+ final InclusionNode valueNode = nodeInclusions .getNodeForPath (node .getPath ());
155+ if (valueNode .isExcluded () && !valueNode .containsValue (INCLUDED )) {
156+ return true ;
157+ }
177158 }
178159 return false ;
179160 }
180161
181162 private boolean isExcludedByCategory (final DiffNode node )
182163 {
183- return hasCategoryWithInclusion (node , EXCLUDED );
164+ // Patched : First check if category exclusions have been configured
165+ if (categoryExclusion && hasCategoryWithInclusion (node , EXCLUDED )) {
166+ return true ;
167+ }
168+ return false ;
184169 }
185170
186171 private boolean isExcludedByType (final DiffNode node )
187172 {
188- if ( node . getValueType () != null )
189- {
173+ // Patched : First check if type exclusions have been configured
174+ if ( typeExclusion && node . getValueType () != null ) {
190175 return typeInclusions .get (node .getValueType ()) == EXCLUDED ;
191176 }
192177 return false ;
193178 }
194179
195180 private boolean isExcludedByPropertyName (final DiffNode node )
196181 {
197- final String propertyName = node .getPropertyName ();
198- if (propertyName != null )
199- {
200- return propertyNameInclusions .get (propertyName ) == EXCLUDED ;
182+ // Patched : First check if property name exclusions have been configured
183+ if (propertyNameExclusion ) {
184+ final String propertyName = node .getPropertyName ();
185+ if (propertyName != null ) {
186+ return propertyNameInclusions .get (propertyName ) == EXCLUDED ;
187+ }
201188 }
202189 return false ;
203190 }
@@ -261,24 +248,32 @@ public ObjectDifferBuilder and()
261248
262249 public ToExcludeAndReturn category (final String category )
263250 {
251+ // Patched : Indicates that there are category exclusions
252+ categoryExclusion = true ;
264253 categoryInclusions .put (category , EXCLUDED );
265254 return this ;
266255 }
267256
268257 public ToExcludeAndReturn type (final Class <?> type )
269258 {
259+ // Patched : Indicates that there are type exclusions
260+ typeExclusion = true ;
270261 typeInclusions .put (type , EXCLUDED );
271262 return this ;
272263 }
273264
274265 public ToExcludeAndReturn node (final NodePath nodePath )
275266 {
267+ // Patched : Indicates that there are nodePath exclusions
268+ nodePathExclusion = true ;
276269 nodeInclusions .getNodeForPath (nodePath ).setValue (EXCLUDED );
277270 return this ;
278271 }
279272
280273 public ToExcludeAndReturn propertyName (final String propertyName )
281274 {
275+ // Patched : Indicates that there are property name exclusions
276+ propertyNameExclusion = true ;
282277 propertyNameInclusions .put (propertyName , EXCLUDED );
283278 return this ;
284279 }
@@ -298,24 +293,32 @@ public ObjectDifferBuilder and()
298293
299294 public ToIncludeAndReturn category (final String category )
300295 {
296+ // Patched : Indicates that there are category inclusions
297+ categoryInclusion = true ;
301298 categoryInclusions .put (category , INCLUDED );
302299 return this ;
303300 }
304301
305302 public ToIncludeAndReturn type (final Class <?> type )
306303 {
304+ // Patched : Indicates that there are type inclusions
305+ typeInclusion = true ;
307306 typeInclusions .put (type , INCLUDED );
308307 return this ;
309308 }
310309
311310 public ToIncludeAndReturn node (final NodePath nodePath )
312311 {
312+ // Patched : Indicates that there are nodePath inclusions
313+ nodePathInclusion = true ;
313314 nodeInclusions .getNodeForPath (nodePath ).setValue (INCLUDED );
314315 return this ;
315316 }
316317
317318 public ToIncludeAndReturn propertyName (final String propertyName )
318319 {
320+ // Patched : Indicates that there are property name inclusions
321+ propertyNameInclusion = true ;
319322 propertyNameInclusions .put (propertyName , INCLUDED );
320323 return this ;
321324 }
@@ -325,4 +328,4 @@ public ToExclude exclude()
325328 return InclusionService .this .exclude ();
326329 }
327330 }
328- }
331+ }
0 commit comments