public B end(){
  assertCurrent();
  if (level == 0) {
    throw new IllegalStateException(logId() + "Unbalanced element hierarchy. Elements stack: " + dumpElements());
  }
  List<ElementInfo> children=new ArrayList<>();
  while (elements.peek().level == level) {
    children.add(elements.pop());
  }
  Collections.reverse(children);
  if (!elements.peek().container) {
    throw new IllegalStateException(logId() + "Closing element " + elements.peek().element+ " is no container");
  }
  Element closingElement=elements.peek().element;
  for (  ElementInfo child : children) {
    closingElement.appendChild(child.element);
  }
  level--;
  return that();
}

public B end ( ) { assertCurrent ( ) ; if ( level == 0 ) { throw new IllegalStateException ( logId ( ) + "Unbalanced element hierarchy. Elements stack: " + dumpElements ( ) ) ; } List < ElementInfo > children = new ArrayList < > ( ) ; while ( elements . peek ( ) . level == level ) { children . add ( elements . pop ( ) ) ; } Collections . reverse ( children ) ; if ( ! elements . peek ( ) . container ) { throw new IllegalStateException ( logId ( ) + "Closing element " + elements . peek ( ) . element + " is no container" ) ; } Element closingElement = elements . peek ( ) . element ; for ( ElementInfo child : children ) { closingElement . appendChild ( child . element ) ; } level -- ; return that ( ) ; }
closes the current container element .
