-
Notifications
You must be signed in to change notification settings - Fork 0
/
Database.java
65 lines (48 loc) · 1.38 KB
/
Database.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
/* Le Hénaff Pablo ; Basudan Hossam*/
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.LinkedBlockingDeque;
public class Database {
private int databaseSequenceNumber = 0;
//changed linkedBlockingQueue to synchronizedList which is a synchronized variant of arrayList
// one caution each time we iterate on this kind list we need to synchronize
// I use it to keep the order of received messages
public List<String> stringQueue;
Database(int size) {
stringQueue = Collections.synchronizedList(new ArrayList<String>(size));
// for(int i = 0 ; i<size ; i++){
// stringQueue.add("");
// }
}
public int getDatabaseSequenceNumber() {
return databaseSequenceNumber;
}
public void update(String str) {
stringQueue.add(str);
databaseSequenceNumber++;
}
public void update() {
databaseSequenceNumber++;
}
@Override
public String toString() {
return "Database{" +
"databaseSequenceNumber=" + databaseSequenceNumber +
", stringQueue=" + stringQueue +
'}';
}
public int size() {
return stringQueue.size();
}
public void setDatabaseSequenceNumber(int databaseSequenceNumber){
this.databaseSequenceNumber=databaseSequenceNumber;
}
public String toStringofStringQueue(){
String res = "";
for(String str : stringQueue){
res+="*****"+str+"\n";
}
return res;
}
}