-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmdStats.java
More file actions
49 lines (45 loc) · 1.46 KB
/
cmdStats.java
File metadata and controls
49 lines (45 loc) · 1.46 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
/* cmdStats.java
*
* Created by William Tyas
* 11/21/17
*
* This command prints statistics about the specified tuples and the
* database.
*/
import java.util.*;
public class cmdStats extends base {
public cmdStats(Scanner line, Database db, LinkedList<String> errorsList) {
run(line, db, errorsList);
}
public void run(Scanner line, Database db, LinkedList<String> errorsList) {
printDatabaseStats(db);
while (line.hasNext()) {
String rName = nextSymbol(line);
int[] rIndex = findRelation(rName, db, true);
if (rIndex[0] == -1) {
System.out.println("*TEMP*");
} else if (rIndex[1] == 1) {
printStats(db.getRelations().get(rIndex[0]));
} else {
printStats(db.getTmpRelations().get(rIndex[0]));
}
System.out.println();
}
}
public void printStats(Relation r) {
System.out.println(r.getTitle());
System.out.println("Number of tuples: " + r.getTuples().size());
System.out.println("Number of attributes: " + r.getCategories().size());
System.out.println();
}
public void printDatabaseStats(Database db) {
System.out.println("STATISTICS");
System.out.println("==========");
int numRelations = db.getRelations().size();
int numTmpRelations = db.getTmpRelations().size();
System.out.println("Number of relations: " + numRelations);
System.out.println("Number of temporary relations: " + numTmpRelations);
System.out.println("Total number of relations: " + (numRelations + numTmpRelations));
System.out.println();
}
}