-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathList.ts
103 lines (79 loc) · 2.25 KB
/
List.ts
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
export class List {
private listaGenerica: Array<any> = [];
private tipo: Object;
constructor(tipo) {
this.tipo = tipo;
}
public Add(item) {
this.listaGenerica.push(item);
}
private _single(lambda, tipo) {
let elemento = this.listaGenerica.filter(lambda)[0];
return elemento as typeof tipo;
}
public Single(lambda) {
return this._single(lambda, this.tipo);
}
public _singleOrDefault(lambda, tipo) {
if (this.listaGenerica.length > 0)
return this.listaGenerica.filter(lambda)[0] as typeof tipo;
else
return null;
}
public SingleOrDefault(lambda) {
return this._singleOrDefault(lambda, this.tipo);
}
public First(lambda) {
return this._single(lambda, this.tipo);
}
public FirstOrDefault(lambda) {
return this._singleOrDefault(lambda, this.tipo);
}
public _lastOrDefault(lambda, tipo) {
if (this.listaGenerica.length > 0)
return this.listaGenerica.filter(lambda)[this.listaGenerica.length - 1] as typeof tipo;
else
return null;
}
public LastOrDefault(lambda) {
return this._lastOrDefault(lambda, this.tipo);
}
public _last(lambda, tipo) {
if (this.listaGenerica.length > 0)
return this.listaGenerica.filter(lambda)[this.listaGenerica.length - 1] as typeof tipo;
}
public Last(lambda) {
return this._last(lambda, this.tipo);
}
public Select(lambdaElement) {
var listaAux: Array<any> = [];
this._where(item => (item.ativo), this.tipo).forEach(element => {
listaAux.push(element[lambdaElement]);
});
return listaAux;
}
private _where(lambda, tipo) {
if (this.listaGenerica.length > 0)
return this.listaGenerica.filter(lambda) as typeof tipo;
else
return null;
}
public Where(lambda) {
return this._where(lambda, this.tipo);
}
public IndexAt(item) {
return this.listaGenerica.indexOf(item);
}
public Contains(item) {
return this.listaGenerica.length > 0 && this.listaGenerica.filter(x => x == item)[0] != undefined;
}
public Clear() {
this.listaGenerica = [];
}
public Count() {
return this.listaGenerica.length;
}
public ToList() {
return this.listaGenerica;
}
}