public Node addToken ( String token ) { Node newnode = new Node ( token ) ; // set the depth first newnode . setDepth ( depth + 1 ) ; // add the node as a child newnode = addChild ( newnode ) ; return newnode ; }
The method will create a new Node instance and try to add it as a child node . If an Node with the same string token exists the method will return the existing node instead .