-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathduvisitor.ts
More file actions
36 lines (32 loc) · 940 Bytes
/
duvisitor.ts
File metadata and controls
36 lines (32 loc) · 940 Bytes
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
import Node from './node'
import File from './file'
import Directory from './directory'
import Link from './link'
import IFileSystemVisitor from './ifilesystemvisitor';
class DuVisitor implements IFileSystemVisitor {
private nrFiles = 0
private nrDirectories = 0
private nrLinks = 0
private totalSize = 0
constructor(startingNode: Node) {
startingNode.acceptVisitor(this);
}
public ifFile(f: File): void {
this.nrFiles++;
this.totalSize += f.size();
}
public ifDirectory(d: Directory): void {
this.nrDirectories++;
d.getChildren().forEach((child) => child.acceptVisitor(this))
}
public ifLink(l: Link): void {
this.nrLinks++;
}
public report(): void {
console.log("files: " + this.nrFiles);
console.log("directories: " + this.nrDirectories);
console.log("links: " + this.nrLinks);
console.log("total size: " + this.totalSize);
}
}
export default DuVisitor