/// <summary> /// Merge data object with this list. /// Only objects that are not already in the list /// are added to the list. /// </summary> /// <param name='data'>The data to merge.</param> public void Merge(WebFactorTreeNode data) { if (data.IsNotNull() && _idHashTable[data.Id].IsNull()) { Add(data); } }
/// <summary> /// Add a factor tree node to the children /// of this factor tree node. /// </summary> /// <param name='factorTreeNode'>Factor tree node to add.</param> public void AddChild(WebFactorTreeNode factorTreeNode) { if (Children.IsNull()) { Children = new List <WebFactorTreeNode>(); } Children.Add(factorTreeNode); factorTreeNode.AddParent(this); }
/// <summary> /// Check if a factor tree node is among the /// parents to this factor tree node. /// </summary> /// <param name='factorTreeNode'>Factor tree node to search for.</param> /// <returns> /// True if the factor tree node is among the parents /// to this factor tree node. /// </returns> public Boolean HasParent(WebFactorTreeNode factorTreeNode) { if (factorTreeNode.Id == this.Id) { // This object is the search parent. return(true); } // Search among parents. foreach (WebFactorTreeNode parentFactorTreeNode in _parents) { if (parentFactorTreeNode.HasParent(factorTreeNode)) { return(true); } } return(false); }
/// <summary> /// Create a FactorInformation instance. /// </summary> /// <param name='dataReader'>An open data reader.</param> public FactorInformation(DataReader dataReader) { WebFactorTreeNode childTreeNode, factorTreeNode, parentTreeNode; // Get all factors and factor tree nodes. _factorTreeNodes = new WebFactorTreeNodeList(); _factors = new List <WebFactor>(); while (dataReader.Read()) { factorTreeNode = new WebFactorTreeNode(dataReader); _factorTreeNodes.Merge(factorTreeNode); _factors.Add(factorTreeNode.Factor); } // Get next result set. if (!dataReader.NextResultSet()) { throw new ApplicationException("No information about factors relations when getting factor tree"); } // Get factor relations and build factor trees. while (dataReader.Read()) { parentTreeNode = _factorTreeNodes.Get(dataReader.GetInt32(FactorTreeData.PARENT_FACTOR_ID)); childTreeNode = _factorTreeNodes.Get(dataReader.GetInt32(FactorTreeData.CHILD_FACTOR_ID)); parentTreeNode.AddChild(childTreeNode); } // Extract all factor tree nodes that // are not child tree nodes. _factorTrees = new List <WebFactorTreeNode>(); foreach (WebFactorTreeNode factorTree in _factorTreeNodes) { if (!factorTree.IsChild) { _factorTrees.Add(factorTree); } } }
/// <summary> /// Add a factor tree node to the parents /// of this factor tree node. /// </summary> /// <param name='factorTreeNode'>Factor tree node to add.</param> public void AddParent(WebFactorTreeNode factorTreeNode) { _parents.Add(factorTreeNode); }