public Builder done ( ) { if ( done ) { return parent ; } this . tree . fragments = fragments . toArray ( new QueryFragment [ fragments . size ( ) ] ) ; if ( parent != null ) { parent . tree . subTrees . add ( this . tree ) ; parent . children . remove ( this ) ; } //done will remove the child from the children, so we'd get concurrent modification exceptions //avoid that stupidly by working on a copy of children new ArrayList <> ( children ) . forEach ( Query . Builder :: done ) ; done = true ; return parent ; }
Concludes the work on a branch and returns a builder of the parent node if any .