-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathiterator.ats
More file actions
60 lines (49 loc) · 1.19 KB
/
iterator.ats
File metadata and controls
60 lines (49 loc) · 1.19 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
import { Logger } from '../logger';
export class Aggregate {
constructor() {
this.items = [];
}
get Count() {
return this.items.length;
}
}
//Abstract class
export class Iterator {
firstObject():any {
throw new Error("Abstract method!");
}
nextObject():any {
throw new Error("Abstract method!");
}
currentObject():any {
throw new Error("Abstract method!");
}
isDone():boolean {
throw new Error("Abstract method!");
}
}
//Concrete of Iterator
export class ConcreteIterator extends Iterator {
constructor(aggregate:Aggregate) {
this._aggregate = aggregate;
this._items = this._aggregate.items;
this.index = 0;
}
firstObject():any {
return this._items[0];
}
nextObject():any {
var retVal = null;
if (this.index < (this._aggregate.Count - 1))
retVal = this._items[++this.index];
else
retVal = "There is no more item in the list!";
return retVal;
}
isDone():boolean {
return this.index >= (this._aggregate.Count - 1);
}
currentObject() {
return this._items[this.index];
}
}