AbstractHtmlRepository { protected static Stream<AbstractHtml> getAllNestedChildrenIncludingParent( final boolean parallel, final AbstractHtml... parents) { final Builder<AbstractHtml> builder = Stream.builder(); AbstractHtml.loopThroughAllNestedChildren(child -> { builder.add(child); return true; }, true, parents); if (parallel) { return builder.build().parallel(); } return builder.build(); }    }
@SuppressWarnings("serial") @Test public void testGetAllNestedChildrenIncludingParent() { final Html html = new Html(null) {{ new Body(this) {{ new Div(this, new Id("one")) {{ new Span(this, new Id("two")) {{ new H1(this, new Id("three")); new H2(this, new Id("three")); new NoTag(this, "something"); }}; new H3(this, new Name("name1")); }}; }}; }}; { final Set<AbstractHtml> set =AbstractHtmlRepository.getAllNestedChildrenIncludingParent(false, html).collect(Collectors.toSet()); assertEquals(8, set.size()); } { final Set<AbstractHtml> set =AbstractHtmlRepository.getAllNestedChildrenIncludingParent(true, html).collect(Collectors.toSet()); assertEquals(8, set.size()); } }