-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathTree.monkey2
More file actions
94 lines (62 loc) · 1.27 KB
/
Tree.monkey2
File metadata and controls
94 lines (62 loc) · 1.27 KB
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
Namespace ted2go
Class Tree
Class Node
Field Text:String
Field UserData:Variant
Property Children:Stack<Node>()
Return _children
End
Property NumChildren:Int()
Return Children?.Length
End
Property Parent:Node()
Return _parent
Setter( value:Node )
If _parent Then _parent-=Self
_parent=value
If _parent Then _parent+=Self
End
Property ParentsHierarchy:Stack<Node>()
Local result:=New Stack<Node>
Local p:=_parent
While p
result.Insert( 0,p )
p=p.Parent
Wend
Return result
End
Method New( text:String,parent:Node=Null,userData:Variant=Null )
Text=text
Parent=parent
UserData=userData
End
Method GetUserData<T>:T()
Return UserData ? Cast<T>( UserData ) Else Null
End
Operator +=( child:Node )
If Not _children Then _children=New Stack<Node>
_children.Add( child )
End
Operator -=( child:Node )
If Not _children Return
_children.Remove( child )
End
Method Clear()
_children?.Clear()
End
Private
Field _parent:Node
Field _children:Stack<Node>
End
Method New()
_root=New Node( "" )
End
Property RootNode:Node()
Return _root
End
Method Clear()
_root.Clear()
End
Private
Field _root:Node
End