/// <summary> /// Visits the specified paths. /// </summary> /// <param name="paths">The paths.</param> /// <returns></returns> public PathTreeNode <P, V> Visit(P[] paths) { PathTreeNode <P, V> node; if ((paths == null) || (paths.Length <= 0)) { throw new PdfArgumentNullException("paths"); } P path = paths[0]; if (this.ContainsPath(path)) { node = this[path]; } else { node = new PathTreeNode <P, V> { parent = (PathTreeNode <P, V>) this }; this.subNodes.Add(path, node); } if (paths.Length == 1) { return(node); } P[] destinationArray = new P[paths.Length - 1]; Array.Copy(paths, 1, destinationArray, 0, destinationArray.Length); return(node.Visit(destinationArray)); }
/// <summary> /// Gets the path. /// </summary> /// <param name="node">The node.</param> /// <returns></returns> public P GetPath(PathTreeNode <P, V> node) { foreach (KeyValuePair <P, PathTreeNode <P, V> > pair in this.subNodes) { if (pair.Value == node) { return(pair.Key); } } throw new PdfInternalException("Can not get path from node"); }
/// <summary> /// Gets the path. /// </summary> /// <param name="node">The node.</param> /// <returns></returns> public P[] GetPath(PathTreeNode <P, V> node) { List <P> list = new List <P>(); for (PathTreeNode <P, V> node2 = node.Parent; node2 != null; node2 = node.Parent) { list.Insert(0, node2.GetPath(node)); node = node2; } return(list.ToArray()); }
/// <summary> /// Gets or sets the <see cref="T:Dt.Pdf.Utility.PathTreeNode`2" /> with the specified path. /// </summary> /// <value></value> public PathTreeNode <P, V> this[P path] { get { return(this.subNodes[path]); } set { if (this.ContainsPath(path)) { this.subNodes[path].parent = null; } if (value != null) { value.parent = (PathTreeNode <P, V>) this; } this.subNodes[path] = value; } }