-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCache.java
More file actions
44 lines (37 loc) · 1.1 KB
/
Copy pathCache.java
File metadata and controls
44 lines (37 loc) · 1.1 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
import java.util.ArrayList;
/**
* Created by Camille on 23/02/2017.
*/
public class Cache {
int id;
ArrayList<Integer> listOfVideo= new ArrayList<Integer>();
int availSpace;
int availSpaceDefault;
public Cache(int id, int a) {
this.id= id; availSpace= a;
availSpaceDefault = a;
// System.out.printf("Cache crée : id : %d , availSpace : %d \n", id, availSpace );
}
public boolean addVideo(Video v) {
// TODO check if already in
for (int i = 0; i < listOfVideo.size(); i++) {
if (listOfVideo.get(i)==v.id) return false;
}
listOfVideo.add(v.id);
availSpace-= v.size;
return true;
}
public void resetCacheServer(){
listOfVideo= new ArrayList<Integer>();
availSpace = availSpaceDefault;
}
public String output() {
StringBuffer bs= new StringBuffer();
bs.append(id).append(" ");
for (int i = 0; i < listOfVideo.size(); i++) {
bs.append(listOfVideo.get(i)).append(" ");
}
bs.append("\n");
return bs.toString();
}
}