/** * JDoublyLinkedList::createNode() * * @param mixed $value * @return */ public function createNode($value) { if (!isset($value)) { throw new Exception('A value is required to create a node'); } $node = new JNode($value); $uid = $node->getUid(); $this->_list[$uid] = $node; return $uid; }
/** * JTree::createNode() * * Create a node, store in hash table * return the reference uid * @param mixed $value * @param string $uid * @return string $uid */ public function createNode($value, $uid = null, $parentUid = null) { if (!isset($value)) { throw new Exception('A value is required to create a node'); } //check if this node is already ready //in which case it must up for modification if (isset($this->_list[$uid])) { $this->modifyNode($value, $uid, $parentUid); } else { //base node $node = new JNode($value, $uid, $parentUid); $uid = $node->getUid(); $this->_list[$uid] = $node; } //now to check if the parent node is ready //if not prepare one now. if (isset($parentUid) && !isset($this->_list[$parentUid])) { $parentNode = new JNode(null, $parentUid); $parentUid = $parentNode->getUid(); $this->_list[$parentUid] = $parentNode; } //this node now becomes the child of //the parent node. if (isset($parentUid) && isset($this->_list[$parentUid])) { $this->addChild($parentUid, $uid); } return $uid; }