-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathclass_Collection.ahk
104 lines (89 loc) · 1.88 KB
/
class_Collection.ahk
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
100
101
102
103
104
#Include <Base>
/*
Basic Collection implementation
*/
class Collection
{
; Methoden Implementation
/*
Fügt ein Element der Collection hinzu
*/
Add(obj){
this.Insert(obj)
}
/*
Fügt eine Auflistung dieser Collection hinzu
*/
AddRange(objs){
if(IsObject(objs)){
for each, item in objs
this.Insert(item)
} else
throw Exceptions.ArgumentException("Must submit Array!")
}
Clear(){
this.Remove(this.MinIndex(), this.MaxIndex())
}
RemoveItem(item){
for k, e in this
if(e = item)
this.Remove(k)
}
/*
Returns the count of elements contained in this collection
*/
Count(){
return this.SetCapacity(0)
}
/*
* Returns true if this collection is empty
*/
IsEmpty(){
return this.Count() == 0
}
First(){
return this[this.MinIndex()]
}
Last(){
return this[this.MaxIndex()]
}
/*
Sortiert die Liste
*/
Sort(comparer=""){
if(IsFunc(comparer))
comparer := "F " comparer
for each, num in this
nums .= num "`n"
Sort, nums, % comparer
this.Clear()
Loop, parse, nums, `,
this.Add(A_LoopField)
}
ToString(){
str := ""
for k, v in this
{
valStr := ""
if(IsObject(v)){
valStr := "{" . typeof(v) . "}"
if(IsFunc(v.ToString)){
valStr .= " " . v.ToString()
}
}else{
valStr := "'" v "'"
}
str .= k ": " . valStr . "`n"
}
return str
}
/*
Konstruktor - erstellt eine neue, (leere) Collection
enum : Element die zubign vorhanden sein sollen
*/
__New(enum = 0){
if(IsObject(enum)){
this.AddRange(enum)
}
}
}