1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-30 19:56:54 +00:00
Sonarr/NzbDrone.Common/Expansive/TreeNode.cs

85 lines
2 KiB
C#
Raw Normal View History

2013-04-16 00:07:58 +00:00
using System.Collections.Generic;
namespace NzbDrone.Common.Expansive
{
internal class TreeNode<T>
{
private List<T> _CallTree;
private TreeNode<T> _Parent;
public TreeNode(T Value)
{
this.Value = Value;
Parent = null;
Children = new TreeNodeList<T>(this);
_CallTree = new List<T>();
}
public TreeNode(T Value, TreeNode<T> Parent)
{
this.Value = Value;
this.Parent = Parent;
Children = new TreeNodeList<T>(this);
_CallTree = new List<T>();
}
public TreeNode<T> Parent
{
get { return _Parent; }
set
{
if (value == _Parent)
{
return;
}
if (_Parent != null)
{
_Parent.Children.Remove(this);
}
if (value != null && !value.Children.Contains(this))
{
value.Children.Add(this);
}
_Parent = value;
}
}
public TreeNode<T> Root
{
get
{
//return (Parent == null) ? this : Parent.Root;
TreeNode<T> node = this;
while (node.Parent != null)
{
node = node.Parent;
}
return node;
}
}
public TreeNodeList<T> Children { get; private set; }
public List<T> CallTree
{
get
{
_CallTree = new List<T>();
TreeNode<T> node = this;
while (node.Parent != null)
{
node = node.Parent;
_CallTree.Add(node.Value);
}
return _CallTree;
}
private set { _CallTree = value; }
}
public T Value { get; set; }
}
}