Element (@NotNull HtmlChunk chunk) { if (myChildren.isEmpty()) { return new Element(myTagName, myAttributes, Collections.singletonList(chunk)); } List<HtmlChunk> newChildren = new ArrayList<>(myChildren.size() + 1); newChildren.addAll(myChildren); newChildren.add(chunk); return new Element(myTagName, myAttributes, newChildren); }