-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test.java
137 lines (118 loc) · 3.79 KB
/
Test.java
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package Projeto;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class Test {
private final static int numberOfCountries = 50;
private final static String bftxt = "bloomFilter.txt";
private final static String userstxt = "usersList.txt";
private static List<User> users;
public static void main (String[] args) throws ClassNotFoundException, IOException {
do {
//Initialize the Bloom Filter
File file = new File(bftxt);
BloomFilter bloomFilter;
if (file.exists() && !file.isDirectory()) {
bloomFilter = IO.readBF(bftxt);
} else {
bloomFilter = new BloomFilter(numberOfCountries, 0.01);
}
User user = null;
boolean logged = false;
//Reads the users list from last session
do {
file = new File(userstxt);
if (file.exists() && !file.isDirectory()) {
users = IO.readScanner(userstxt);
//Login and Register menu
int mainMenuAns = 0;
do {
mainMenuAns = IO.loginOrRegister();
switch(mainMenuAns) {
case 1:
user = IO.login(users);
if (!(user == null)) {
logged = true;
}
break;
case 2: users = IO.register(users);
break;
case 3: System.exit(1);
break;
}
} while(mainMenuAns!=3 && !logged);
} else {
users = new ArrayList<User>();
int mainMenuAns = 0;
logged = false;
do {
mainMenuAns = IO.registerOnly();
switch(mainMenuAns) {
case 2: users = IO.register(users);
break;
case 3: System.exit(1);
break;
}
} while(mainMenuAns!=3 && users.isEmpty());
}
} while(!logged);
//Logged in
IO.portugalAirport();
int ans = 0;
do {
ans = IO.userMenu(user);
switch(ans) {
case 1:
Countries destination = IO.getDestination(); //get valid country by Enum Countries
user.getContEst().add(destination); //increment country value in User's StochasticCounter
bloomFilter.insert(destination); //increment country value in Bloom Filter
IO.writeScanner(userstxt,users); //update usersList.txt after a new trip
IO.writeBF(bftxt, bloomFilter.getMap(), bloomFilter.getVector()); //update bloomFilter.txt after a new trip
IO.countryAirport(destination);
break;
case 2:
user.getContEst().getCount();
break;
case 3:
bloomFilter.stats();
break;
case 4:
break;
}
} while (ans != 4);
} while (true);
/* Testes
BloomFilter.insert("Espanha");
BloomFilter.insert("França");
BloomFilter.insert("Reino Unido");
BloomFilter.insert("Reino Unido");
BloomFilter.insert("Alemanha");
BloomFilter.insert("Grécia");
BloomFilter.insert("Itália");
BloomFilter.insert("Áustria");
BloomFilter.insert("Portugaa");
BloomFilter.insert("Portugll");
BloomFilter.insert("Portugla");
BloomFilter.isMember("França"); //True
BloomFilter.isMember("Portugal"); //False
BloomFilter.isMember("Alemanha"); //True
BloomFilter.isMember("Reino Unido"); //True
System.out.println();
BloomFilter.delete("França");
BloomFilter.delete("Reino Unido");
BloomFilter.isMember("França"); //False
BloomFilter.isMember("Portugal"); //False
BloomFilter.isMember("Alemanha"); //True
BloomFilter.isMember("Reino Unido"); //True
BloomFilter.insert("Espanha");
BloomFilter.insert("Espanha");
BloomFilter.insert("Espanha");
System.out.println();
System.out.println(BloomFilter.count("França")); //0
System.out.println(BloomFilter.count("Espanha")); //4
System.out.println(BloomFilter.count("Reino Unido")); //1
*/
}
}