public Long addChildElement ( Element childElement , ElementWriter elementWriter ) { synchronized ( lock ) { checkNotFrozen ( ) ; if ( childElements == null ) childElements = new ArrayList <> ( ) ; childElements . add ( childElement ) ; if ( elementWriters == null ) elementWriters = new HashMap <> ( ) ; IdGenerator idGenerator = idGenerators . get ( ) ; while ( true ) { Long elementKey = idGenerator . getNextId ( ) ; if ( ! elementWriters . containsKey ( elementKey ) ) { elementWriters . put ( elementKey , elementWriter ) ; return elementKey ; } else { // Reset generator when duplicate found (this should be extremely rare) idGenerator . reset ( ) ; } } } }
Adds a child element to this node .