-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSalleDAttenteAvecPrioVersionBoris.java
More file actions
94 lines (75 loc) · 1.79 KB
/
Copy pathSalleDAttenteAvecPrioVersionBoris.java
File metadata and controls
94 lines (75 loc) · 1.79 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
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
package tpSalleDAttente;
import java.util.ArrayList;
import java.util.HashMap;
public class SalleDAttenteAvecPrioVersionBoris<TC extends AvecPrio> implements SalleDAttente<TC>{
private int capaciteMax, maxPrio;
private HashMap<Integer, ArrayList<TC>> salle;
//constructeur
/**
*
* @param taille taille maximale de la salle d'attente
* @param Prio niveau de priorité maximum (donc prio +1 niveaux de prios car ça commence à 0)
*/
public SalleDAttenteAvecPrioVersionBoris(int taille, int Prio) {
capaciteMax = taille;
maxPrio = Prio;
salle = new HashMap<Integer, ArrayList<TC>>();
// map initialisation
for (int i=0; i < maxPrio; i++) {
salle.put(i,new ArrayList<TC>());
}
}
@Override
public int getCapacite() {
return capaciteMax;
}
@Override
public int getNbClients() {
// TODO Auto-generated method stub
int nbClient = 0;
for (ArrayList<TC> prio: salle.values()) {
nbClient += prio.size();
}
return nbClient;
}
@Override
public boolean estVide() {
// TODO Auto-generated method stub
return getNbClients() == 0;
}
@Override
public boolean estPleine() {
// TODO Auto-generated method stub
return salle.size()==capaciteMax;
}
@Override
public TC getProchain() {
if (!estVide()) {
for (int i = maxPrio; i <= 0; i--) {
if (salle.get(i).size() != 0) {
return salle.get(i).get(0);
}
}
}
return null;
}
@Override
public void sortir() {
if (!estVide()) {
TC next = getProchain();
salle.get(next.getPrio()).remove(next);
}
}
@Override
public void entrer(TC client) {
if (!estPleine()) {
if (client.getPrio() > maxPrio) {
salle.get(maxPrio).add(client);
}
else if (client.getPrio() < 0) {
salle.get(0).add(client);
}
else {salle.get(client.getPrio()).add(client);}
}
}
}