Source:
<code>public void applyStyles(Object element, boolean applyStylesToChildNodes, boolean computeDefaultStyle) { Element elt = getElement(element); if (elt == null || !isVisible(elt)) { return; } CSSStyleDeclaration style = viewCSS.getComputedStyle(elt, null); if (computeDefaultStyle) { if (applyStylesToChildNodes) { this.computeDefaultStyle = computeDefaultStyle; } applyDefaultStyleDeclaration(element, false, style, null); } String[] pseudoInstances = getStaticPseudoInstances(elt); if (pseudoInstances != null && pseudoInstances.length > 0) { for (String pseudoInstance : pseudoInstances) { CSSStyleDeclaration styleWithPseudoInstance = viewCSS.getComputedStyle(elt, pseudoInstance); if (computeDefaultStyle) { applyDefaultStyleDeclaration(element, false, styleWithPseudoInstance, pseudoInstance); } if (styleWithPseudoInstance != null) { CSSRule parentRule = styleWithPseudoInstance.getParentRule(); if (parentRule instanceof ExtendedCSSRule) { applyConditionalPseudoStyle((ExtendedCSSRule) parentRule, pseudoInstance, element, styleWithPseudoInstance); } else { applyStyleDeclaration(elt, styleWithPseudoInstance, pseudoInstance); } } } } if (style != null) { applyStyleDeclaration(elt, style, null); } try { applyInlineStyle(elt, false); } catch (Exception e) { handleExceptions(e); } if (applyStylesToChildNodes) { NodeList nodes = elt instanceof ChildVisibilityAwareElement ? ((ChildVisibilityAwareElement) elt).getVisibleChildNodes() : elt.getChildNodes(); if (nodes != null) { <START> if (nodes instanceof IStreamingNodeList) { <END> ((IStreamingNodeList) nodes).stream().forEach(child -> { applyStyles(child, applyStylesToChildNodes); }); } else { int length = nodes.getLength(); for (int k = 0; k < length; k++) { applyStyles(nodes.item(k), applyStylesToChildNodes); } } onStylesAppliedToChildNodes(elt, nodes); } } }</code><technical_language>idea. I a helper method for this pattern? forEachNode(NodeList, Consumer)</technical_language>

Target:
public void applyStyles(Object element, boolean applyStylesToChildNodes, boolean computeDefaultStyle) { Element elt = getElement(element); if (elt == null || !isVisible(elt)) { return; } CSSStyleDeclaration style = viewCSS.getComputedStyle(elt, null); if (computeDefaultStyle) { if (applyStylesToChildNodes) { this.computeDefaultStyle = computeDefaultStyle; } applyDefaultStyleDeclaration(element, false, style, null); } String[] pseudoInstances = getStaticPseudoInstances(elt); if (pseudoInstances != null && pseudoInstances.length > 0) { for (String pseudoInstance : pseudoInstances) { CSSStyleDeclaration styleWithPseudoInstance = viewCSS.getComputedStyle(elt, pseudoInstance); if (computeDefaultStyle) { applyDefaultStyleDeclaration(element, false, styleWithPseudoInstance, pseudoInstance); } if (styleWithPseudoInstance != null) { CSSRule parentRule = styleWithPseudoInstance.getParentRule(); if (parentRule instanceof ExtendedCSSRule) { applyConditionalPseudoStyle((ExtendedCSSRule) parentRule, pseudoInstance, element, styleWithPseudoInstance); } else { applyStyleDeclaration(elt, styleWithPseudoInstance, pseudoInstance); } } } } if (style != null) { applyStyleDeclaration(elt, style, null); } try { applyInlineStyle(elt, false); } catch (Exception e) { handleExceptions(e); } if (applyStylesToChildNodes) { NodeList nodes = elt instanceof ChildVisibilityAwareElement ? ((ChildVisibilityAwareElement) elt).getVisibleChildNodes() : elt.getChildNodes(); if (nodes != null) { processNodeList(nodes, this::applyStyles, applyStylesToChildNodes); onStylesAppliedToChildNodes(elt, nodes); } } }