/
TreeNodeModel.cs
99 lines (78 loc) · 2.4 KB
/
TreeNodeModel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FormulaBineFormata
{
public class TreeNodeModel<T>
where T : class
{
public float X { get; set; }
public int Y { get; set; }
public float Mod { get; set; }
public TreeNodeModel<T> Parent { get; set; }
public List<TreeNodeModel<T>> Children { get; set; }
public float Width { get; set; }
public int Height { get; set; }
public T Item { get; set; }
public TreeNodeModel(T item, TreeNodeModel<T> parent)
{
this.Item = item;
this.Parent = parent;
this.Children = new List<TreeNodeModel<T>>();
}
public bool IsLeaf()
{
return this.Children.Count == 0;
}
public bool IsLeftMost()
{
if (this.Parent == null)
return true;
return this.Parent.Children[0] == this;
}
public bool IsRightMost()
{
if (this.Parent == null)
return true;
return this.Parent.Children[this.Parent.Children.Count - 1] == this;
}
public TreeNodeModel<T> GetPreviousSibling()
{
if (this.Parent == null || this.IsLeftMost())
return null;
return this.Parent.Children[this.Parent.Children.IndexOf(this) - 1];
}
public TreeNodeModel<T> GetNextSibling()
{
if (this.Parent == null || this.IsRightMost())
return null;
return this.Parent.Children[this.Parent.Children.IndexOf(this) + 1];
}
public TreeNodeModel<T> GetLeftMostSibling()
{
if (this.Parent == null)
return null;
if (this.IsLeftMost())
return this;
return this.Parent.Children[0];
}
public TreeNodeModel<T> GetLeftMostChild()
{
if (this.Children.Count == 0)
return null;
return this.Children[0];
}
public TreeNodeModel<T> GetRightMostChild()
{
if (this.Children.Count == 0)
return null;
return this.Children[Children.Count - 1];
}
public override string ToString()
{
return Item.ToString();
}
}
}