public Node addChild ( Node n ) { if ( ! this . children . containsKey ( n . getToken ( ) ) ) { this . children . put ( n . getToken ( ) , n ) ; n . setParent ( this ) ; return n ; } else { return ( Node ) this . children . get ( n . getToken ( ) ) ; } }
The method will check to see if a Node with the same string token already exists . If it doesn t it will add the token as a child and return the same node .