44import java .util .Map ;
55import java .util .Optional ;
66import java .util .concurrent .ConcurrentSkipListMap ;
7+ import java .util .stream .Stream ;
78import org .gradle .api .Task ;
89import org .gradle .api .logging .Logger ;
910import org .gradle .api .logging .Logging ;
@@ -132,8 +133,7 @@ public void configure(final Task task) {
132133 // </attributes>
133134 // </classpathentry>
134135
135- rootNode .children ().stream () // loop over all children
136- .filter (i -> i instanceof Node ) // better safe than sorry
136+ children (rootNode ) // loop over all children
137137 .filter (i -> NAME_ITEM .equals (((Node )i ).name ())) // with name "classpathentry"
138138 .filter (i -> isKindOf ((Node )i , "lib" )) // kind of "lib"
139139 .filter (i -> getGradleScope ((Node )i ).contains ("main" )) // appropriate gradle scope
@@ -169,8 +169,7 @@ public void configure(final Task task) {
169169 // </attributes>
170170 // </classpathentry>
171171
172- rootNode .children ().stream () // loop over all children
173- .filter (i -> i instanceof Node ) // better safe than sorry
172+ children (rootNode ) // loop over all children
174173 .filter (i -> NAME_ITEM .equals (((Node )i ).name ())) // with name "classpathentry"
175174 .filter (i -> "test" .equals (getGradleScope ((Node )i ))) // appropriate gradle scope
176175 .filter (i -> hasNoAttributeTest ((Node )i )) // without "test" information
@@ -193,8 +192,7 @@ public void configure(final Task task) {
193192 * XML-content to be improved
194193 */
195194 /* package */ void putJreOnModulePath (final Node rootNode ) {
196- rootNode .children ().stream () // loop over all children
197- .filter (i -> i instanceof Node ) // better safe than sorry
195+ children (rootNode ) // loop over all children
198196 .filter (i -> NAME_ITEM .equals (((Node )i ).name ())) // with name "classpathentry"
199197 .filter (i -> isJre ((Node )i )) // indicating JRE
200198 .filter (i -> hasNoAttributeModule ((Node )i )) // without "module" information
@@ -225,8 +223,7 @@ public void configure(final Task task) {
225223
226224 // ... Note 1: In real usage (i.e. no test scenario) item has name "classpathentry".
227225
228- final Optional <Node > oChild = item .children ().stream () // loop over all children
229- .filter (c -> c instanceof Node ) // better safe than sorry
226+ final Optional <Node > oChild = children (item ) // loop over all children
230227 .filter (c -> NAME_CHILD .equals (((Node )c ).name ())) // with name "attributes"
231228 .findFirst (); // first child named "attributes"
232229
@@ -267,8 +264,7 @@ public void configure(final Task task) {
267264 /* package */ Optional <Node > getAttributeNamed (final Node child , final String name ) {
268265 // ... Note 1: In real usage (i.e. no test scenario) node has name "attributes".
269266
270- return child .children ().stream () // loop over all children
271- .filter (g -> g instanceof Node ) // better safe than sorry
267+ return children (child ) // loop over all children
272268 .filter (g -> NAME_GRAND .equals (((Node )g ).name ())) // nodes with name "attribute"
273269 .filter (g -> name .equals (((Node )g ).attribute ("name" ))) // nodes with appropriate attribute
274270 .findFirst ();
@@ -287,8 +283,7 @@ public void configure(final Task task) {
287283 /* package */ boolean hasNoAttributeModule (final Node item ) {
288284 // ... Note 1: In real usage (i.e. no test scenario) item has name "classpathentry".
289285
290- return item .children ().stream () // loop over all children
291- .filter (c -> c instanceof Node ) // better safe than sorry
286+ return children (item ) // loop over all children
292287 .filter (c -> NAME_CHILD .equals (((Node )c ).name ())) // child named "attributes"
293288 .filter (c -> hasAttributeNamed ((Node )c , "module" )) // grand-child with attribute "module"
294289 .findFirst ()
@@ -308,8 +303,7 @@ public void configure(final Task task) {
308303 /* package */ boolean hasNoAttributeTest (final Node item ) {
309304 // ... Note 1: In real usage (i.e. no test scenario) item has name "classpathentry".
310305
311- return item .children ().stream () // loop over all children
312- .filter (c -> c instanceof Node ) // better safe than sorry
306+ return children (item ) // loop over all children
313307 .filter (c -> NAME_CHILD .equals (((Node )c ).name ())) // child named "attributes"
314308 .filter (c -> hasAttributeNamed ((Node )c , "test" )) // grand-child with attribute "test"
315309 .findFirst ()
@@ -437,8 +431,7 @@ public void run() {
437431 map .put ("value" , "true" );
438432
439433 // --- find first child named "attributes"
440- item .children ().stream () // loop over all children
441- .filter (c -> c instanceof Node ) // better safe than sorry
434+ children (item ) // loop over all children
442435 .filter (c -> NAME_CHILD .equals (((Node )c ).name ())) // nodes with name "attributes"
443436 .findFirst ()
444437 .ifPresentOrElse (
@@ -452,4 +445,11 @@ public void run() {
452445 new AddAttribute (item , map )
453446 ); // end ifPresentOrElse(...)
454447 } // end method */
448+
449+ @ SuppressWarnings ("unchecked" )
450+ private static Stream <Node > children (final Node item ) {
451+ return item .children ().stream ()
452+ .filter (c -> c instanceof Node )
453+ .map (Node .class ::cast );
454+ }
455455} // end class
0 commit comments