-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTraitement.java
87 lines (73 loc) · 2.25 KB
/
Traitement.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
import java.util.*;
/**
* Traitement modélise un traitement et ses traitements suivants (donc
* une chaîne de traitements).
*
* @author Xavier Crégut <Prenom.Nom@enseeiht.fr>
*/
abstract public class Traitement {
/** Les traitements suivants. */
private List<Traitement> suivants = new ArrayList<>();
/** Ajouter des traitements à la suite de celui-ci.
* @param suivants les traitements à ajouter
*/
final public Traitement ajouterSuivants(Traitement... suivants) throws CycleException {
for (Traitement s : suivants) {
if (this.suivants.contains(s))
throw new CycleException("Cycle infini dans la déclaration des traitements");
}
Collections.addAll(this.suivants, suivants);
return this;
}
@Override
public final String toString() {
return this.toString("");
}
/** Afficher ce traitement et les suivants sous forme d'un arbre horizontal.
* @param prefixe le préfixe à afficher après un retour à la ligne
*/
private String toString(String prefixe) {
String res = this.getClass().getName();
String complement = this.toStringComplement();
if (complement != null && complement.length() > 0) {
res += "(" + complement + ")";
}
if (this.suivants.size() <= 1) {
for (Traitement s : this.suivants) {
res += " --> " + s.toString(prefixe);
}
} else {
for (Traitement s : this.suivants) {
res += "\n" + prefixe + "\t" + "--> " + s.toString(prefixe + "\t");
}
}
return res;
}
/** Décrire les paramètres du traitement. */
protected String toStringComplement() {
return null;
}
public void traiter(Position position, double valeur) {
for (Traitement suivant : this.suivants) {
suivant.traiter(position, valeur);
}
}
final public void gererDebutLot(String nomLot) {
Objects.requireNonNull(nomLot, "nomLot doit être défini.");
this.gererDebutLotLocal(nomLot);
for (Traitement suivant : this.suivants) {
suivant.gererDebutLot(nomLot);
}
}
protected void gererDebutLotLocal(String nomLot) {
}
final public void gererFinLot(String nomLot) {
Objects.requireNonNull(nomLot, "nomLot doit être défini.");
this.gererFinLotLocal(nomLot);
for (Traitement suivant : this.suivants) {
suivant.gererFinLot(nomLot);
}
}
protected void gererFinLotLocal(String nomLot) {
}
}