version beta
This commit is contained in:
@@ -10,16 +10,27 @@ public interface AbstractChangementFactory {
|
||||
|
||||
/**
|
||||
* permet de récupérer une usine abstraite pour les groupes qui fonctionne en tandem avec cette usine abstraite
|
||||
* @return cette usine abstraite
|
||||
* @return cette usine abstraite pour les groupes
|
||||
*/
|
||||
public AbstractGroupeFactory getGroupeFactory();
|
||||
|
||||
/**
|
||||
* permet de récupérer les changements
|
||||
* @return tous les changements en attente
|
||||
* @return l'ensemble de tous les changements en attente
|
||||
*
|
||||
* NB. Attention. C'était Iterator<Changement> dans la version beta.
|
||||
*/
|
||||
public Iterator<Changement> getAllChangements();
|
||||
public Set<Changement> getAllChangements();
|
||||
|
||||
/**
|
||||
* permet de mettre en oeuvre un changement connu de l'usine abstraite.
|
||||
* En cas de succès, le changement est oublié (détruit).
|
||||
*
|
||||
* @throws java.lang.NullPointerException si un argument est null
|
||||
* @throws java.lang.IllegalArgumentException si inconnu de l'usine abstraite
|
||||
*/
|
||||
public void applyChangement(Changement c);
|
||||
|
||||
/**
|
||||
* permet de supprimer un changement connu de l'usine abstraite.
|
||||
*
|
||||
|
@@ -13,6 +13,15 @@ public interface AbstractGroupeFactory {
|
||||
*/
|
||||
public Groupe getPromotion();
|
||||
|
||||
|
||||
/**
|
||||
* Test si le groupe g est connu de l'usine (connu maintenant).
|
||||
* Si la réponse est true, les méthodes avec ce groupe en paramètre devraient bien fonctionner.
|
||||
* Si la réponse est false, le comportement n'est pas garanti.
|
||||
*/
|
||||
public Boolean knows(Groupe g);
|
||||
|
||||
|
||||
/**
|
||||
* permet de supprimer un groupe connu de l'usine abstraite qui ne contient pas de groupes.
|
||||
* Pour détruire un groupe connu qui en contient d'autres il faut le faire récursivement.
|
||||
|
@@ -42,7 +42,7 @@ public interface Changement extends MonPrint {
|
||||
*/
|
||||
public default String monPrint() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Changement de " + this.getEtu().monPrint() + " depuis le groupe " + this.getA().getName() + " vers le groupe " + this.getA().getName());
|
||||
sb.append("Changement de " + this.getEtu().monPrint() + " depuis le groupe " + this.getA().getName() + " vers le groupe " + this.getB().getName());
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
@@ -110,7 +110,7 @@ public interface Groupe extends MonPrint {
|
||||
sb.append("\t _ "+ s.monPrint());
|
||||
sb.append("\n");
|
||||
}
|
||||
sb.append(" ** Sous Groupess **\n");
|
||||
sb.append(" ** Sous Groupes **\n");
|
||||
for (Groupe g: getSousGroupes()){
|
||||
sb.append("\t _ "+ g.getName() + " (" + g.getType() + ", capacité " + g.getMin() + " à " + g.getMax() +", id " + g.getId()+")");
|
||||
sb.append("\n");
|
||||
|
@@ -0,0 +1,104 @@
|
||||
package fr.iutfbleau.projetIHM2022FI2.MNP;
|
||||
import fr.iutfbleau.projetIHM2022FI2.API.*;
|
||||
import java.util.*;
|
||||
/**
|
||||
* Usine abstraite gérant l'ensemble des changements.
|
||||
*
|
||||
*/
|
||||
|
||||
public class AbstractChangementFactoryNP implements AbstractChangementFactory {
|
||||
|
||||
// l'usine à groupe travaillant en tandem avec cette usine.
|
||||
private AbstractGroupeFactory agf;
|
||||
|
||||
// On utilise une table de hachage pour retrouver facilement un changement (à partir de son id).
|
||||
// Si il y a beaucoup de changements c'est plus rapide que de parcourir toute une liste.
|
||||
private HashMap<Integer,Changement> brain;
|
||||
|
||||
public AbstractChangementFactoryNP(AbstractGroupeFactory agf){
|
||||
Objects.requireNonNull(agf,"On ne peut pas créer une usine à changement dont l'usine à groupe parternaire est null");
|
||||
this.agf=agf;
|
||||
this.brain=new HashMap<Integer,Changement>();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* permet de récupérer l'usine abstraite pour les groupes qui fonctionne en tandem avec cette usine abstraite
|
||||
* @return cette usine abstraite pour les groupes
|
||||
*/
|
||||
public AbstractGroupeFactory getGroupeFactory(){
|
||||
return this.agf;
|
||||
}
|
||||
|
||||
/**
|
||||
* permet de récupérer les changements
|
||||
* @return l'ensemble de tous les changements en attente
|
||||
*/
|
||||
public Set<Changement> getAllChangements(){
|
||||
// la méthode value() d'un hashmap retourne la collection des valeurs.
|
||||
// Il faut transformer la collection en Set.
|
||||
// Un constructeur de HashSet permet de faire cette opération.
|
||||
Set<Changement> out = new HashSet(this.brain.values());
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* permet de mettre en oeuvre un changement connu de l'usine abstraite.
|
||||
*
|
||||
* @throws java.lang.NullPointerException si un argument est null
|
||||
* @throws java.lang.IllegalStateException si le changement n'a pas de sens en l'état actuel (e.g. étudiant pas dans le groupe de départ a, groupe b inconnu, groupe a inconnu, etc).
|
||||
* @throws java.lang.IllegalArgumentException si inconnu de l'usine abstraite
|
||||
*/
|
||||
public void applyChangement(Changement c){
|
||||
Objects.requireNonNull(c,"On ne peut pas appliquer un changement qui est null");
|
||||
Etudiant e = c.getEtu();
|
||||
Groupe a = c.getA();
|
||||
Groupe b = c.getB();
|
||||
|
||||
if (!agf.knows(a)) throw new IllegalStateException("Le groupe de départ du changement est inconnu. Impossible à mettre en oeuvre.");
|
||||
|
||||
if (!agf.knows(b)) throw new IllegalStateException("Le groupe d'arrivée du changement est inconnu. Impossible à mettre en oeuvre.");
|
||||
// pas encore implanté.
|
||||
// if(!agf.getGroupesOfEtudiant(e).contains(a)) throw new IllegalStateException("Le groupe de départ ne contient pas l'étudiant. Impossible à mettre en oeuvre.");
|
||||
|
||||
agf.dropFromGroupe(a,e);
|
||||
agf.addToGroupe(b,e);
|
||||
// En cas de succès, on enlève le changement du cerveau
|
||||
this.brain.remove(Integer.valueOf(c.getId()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* permet de supprimer un changement connu de l'usine abstraite.
|
||||
*
|
||||
* @throws java.lang.NullPointerException si un argument est null
|
||||
* @throws java.lang.IllegalArgumentException si inconnu de l'usine abstraite
|
||||
*/
|
||||
public void deleteChangement(Changement c){
|
||||
Objects.requireNonNull(c,"On ne peut pas demander la suppression d'un changement qui est null");
|
||||
|
||||
this.brain.remove(Integer.valueOf(c.getId()));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* permet d'ajouter un nouveau changement.
|
||||
*
|
||||
* @param A groupe actuel
|
||||
* @param B groupe demandé
|
||||
* @param e étudiant concerné par le changement
|
||||
*
|
||||
* @throws java.lang.NullPointerException si un argument est null
|
||||
* @throws java.lang.IllegalArgumentException si les groupes ou l'étudiant ne sont pas connus de la factory partenaire, ou e n'appartient pas à A ou A et B ne sont pas frères dans l'arbre des groupes.
|
||||
*
|
||||
*/
|
||||
public void createChangement(Groupe A, Etudiant e, Groupe B){
|
||||
Objects.requireNonNull(A,"Le groupe d'origine ne peut pas être null");
|
||||
Objects.requireNonNull(B,"Le groupe d'arrivée ne peut pas être null");
|
||||
Objects.requireNonNull(e,"L'étudiant ne peut pas être null");
|
||||
|
||||
Changement c = new ChangementNP(A,e,B);
|
||||
this.brain.put(Integer.valueOf(c.getId()),c);
|
||||
}
|
||||
|
||||
}
|
@@ -28,20 +28,11 @@ public class AbstractGroupeFactoryNP implements AbstractGroupeFactory {
|
||||
this.brain=new HashMap<Integer,Groupe>();
|
||||
this.brain.put(Integer.valueOf(this.promo.getId()),this.promo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Test pltôt optimiste. Si la clé est identique alors on fait comme si c'était le bon groupe.
|
||||
* Test plutôt optimiste. Si la clé est identique alors on fait comme si c'était le bon groupe.
|
||||
*/
|
||||
private Boolean knows(Groupe g){
|
||||
public Boolean knows(Groupe g){
|
||||
return this.brain.containsKey(Integer.valueOf(g.getId()));
|
||||
}
|
||||
|
||||
@@ -140,13 +131,20 @@ public class AbstractGroupeFactoryNP implements AbstractGroupeFactory {
|
||||
// création des sous-groupes
|
||||
int min = 0;
|
||||
int max = ((int) Math.floor(pere.getSize()/n))+1;
|
||||
List<Groupe> groupes = new ArrayList<Groupe>(n);
|
||||
for(int i = 0; i<n; i++){
|
||||
Groupe g = new GroupeNP(copiePereRacinePartition,name+"_"+i,min,max);
|
||||
groupes.add(i,g);// ajout dans le tableau des groupes
|
||||
copiePereRacinePartition.addSousGroupe(g);
|
||||
this.brain.put(Integer.valueOf(g.getId()),g);
|
||||
}
|
||||
|
||||
|
||||
// Partage des étudiants (on ne prête pas attention aux min et max)
|
||||
int i=0;
|
||||
for (Etudiant s: pere.getEtudiants()){
|
||||
copiePereRacinePartition.addEtudiant(s);
|
||||
groupes.get(i).addEtudiant(s);
|
||||
i = (i+1) %n;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -179,7 +177,12 @@ public class AbstractGroupeFactoryNP implements AbstractGroupeFactory {
|
||||
* @throws java.lang.IllegalArgumentException la factory ne connaît pas g
|
||||
*/
|
||||
public void dropFromGroupe(Groupe g, Etudiant e){
|
||||
throw new UnsupportedOperationException("pas encore implanté");
|
||||
Objects.requireNonNull(g,"Le groupe ne peut pas être null");
|
||||
Objects.requireNonNull(e,"L'étudiant ne peut pas être null");
|
||||
if (!this.knows(g)){
|
||||
throw new IllegalArgumentException("Impossible d'ajouter l'étudiant car le est groupe inconnu");
|
||||
}
|
||||
g.removeEtudiant(e);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -10,6 +10,9 @@ import java.util.*;
|
||||
|
||||
public class ChangementNP implements Changement {
|
||||
|
||||
//auto-incrément des changements
|
||||
private static int nextId=0;
|
||||
|
||||
private int id;
|
||||
private Groupe a,b;
|
||||
private Etudiant e;
|
||||
@@ -18,8 +21,8 @@ public class ChangementNP implements Changement {
|
||||
Objects.requireNonNull(a,"On ne peut pas créer un changement avec un groupe à quitter null");
|
||||
Objects.requireNonNull(b,"On ne peut pas créer un changement avec un groupe à rejoindre null");
|
||||
Objects.requireNonNull(e,"On ne peut pas créer un changement concernant un étudiant null");
|
||||
// Nous n'utilisons dans l'immédiat pas le champs id qui vaut 0 pour tous les changements.
|
||||
this.id=0;
|
||||
|
||||
this.id=++this.nextId;
|
||||
this.a=a;
|
||||
this.b=b;
|
||||
this.e=e;
|
||||
@@ -46,7 +49,7 @@ public class ChangementNP implements Changement {
|
||||
* @return ce groupe.
|
||||
*/
|
||||
public Groupe getB(){
|
||||
return this.a;
|
||||
return this.b;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -97,6 +97,10 @@ public class TestTexteMNP{
|
||||
AbstractGroupeFactory agf = new AbstractGroupeFactoryNP("BUT2 FI", 15, 92);
|
||||
System.out.println("terminé.");
|
||||
|
||||
System.out.print("Création de l\'usine à changement");
|
||||
AbstractChangementFactory acf = new AbstractChangementFactoryNP(agf);
|
||||
System.out.println("terminé.");
|
||||
|
||||
System.out.print("Ajout des étudiants dans le groupe de la promotion racine");
|
||||
|
||||
agf.addToGroupe(agf.getPromotion(),e1);
|
||||
@@ -175,11 +179,57 @@ public class TestTexteMNP{
|
||||
|
||||
System.out.println("==========================");
|
||||
System.out.println("Partition du groupe racine en 3 groupes TD.");
|
||||
agf.createPartition(agf.getPromotion(), "TD",3);
|
||||
System.out.println(agf.getPromotion().monPrint());
|
||||
agf.createPartition(agf.getPromotion(), "TD",4);
|
||||
//System.out.println(agf.getPromotion().monPrint());
|
||||
|
||||
Groupe racineDeLaPartition = agf.getPromotion().getSousGroupes().iterator().next();
|
||||
System.out.println(racineDeLaPartition.monPrint());
|
||||
|
||||
System.out.println("== Cette version ajoute les étudiants automatiquement pour une partition ");
|
||||
for(Groupe g : racineDeLaPartition.getSousGroupes()){
|
||||
System.out.println(g.monPrint());
|
||||
}
|
||||
|
||||
System.out.println("==========================");
|
||||
System.out.println("Création d'un changement");
|
||||
Iterator<Groupe> itgr = racineDeLaPartition.getSousGroupes().iterator();
|
||||
Groupe A = itgr.next(); // premier sous-groupe
|
||||
Groupe B = itgr.next(); // second sous-groupe
|
||||
B = itgr.next(); // troisième sous-groupe
|
||||
Etudiant e = A.getEtudiants().iterator().next();// premier étudiant du premier sous-groupe.
|
||||
acf.createChangement(A,e,B);
|
||||
System.out.println("Récupération des changements (en fait un seul pour l'instant)");
|
||||
Iterator<Changement> itch = acf.getAllChangements().iterator();
|
||||
Changement c = itch.next();
|
||||
System.out.println(c.monPrint());
|
||||
System.out.println("Application du changement");
|
||||
acf.applyChangement(c);
|
||||
System.out.println("==========================");
|
||||
System.out.println("== nouveau contenu des groupes de la partition ");
|
||||
for(Groupe g : racineDeLaPartition.getSousGroupes()){
|
||||
System.out.println(g.monPrint());
|
||||
}
|
||||
|
||||
System.out.println("==========================");
|
||||
System.out.println("Création de 2 changements");
|
||||
itgr = racineDeLaPartition.getSousGroupes().iterator();
|
||||
A = itgr.next(); // premier sous-groupe
|
||||
B = itgr.next(); // second sous-groupe
|
||||
Etudiant etu1 = A.getEtudiants().iterator().next();// premier étudiant du premier sous-groupe.
|
||||
Etudiant etu2 = B.getEtudiants().iterator().next();// premier étudiant du premier sous-groupe.
|
||||
acf.createChangement(A,etu1,B);
|
||||
acf.createChangement(B,etu2,A);
|
||||
// Impression des changements.
|
||||
for (Changement cgt : acf.getAllChangements()){
|
||||
System.out.println(cgt.monPrint());
|
||||
}
|
||||
itch = acf.getAllChangements().iterator();
|
||||
c = itch.next();
|
||||
System.out.println("Suppression d'un changement. Il reste :");
|
||||
acf.deleteChangement(itch.next());
|
||||
for (Changement cgt : acf.getAllChangements()){
|
||||
System.out.println(cgt.monPrint());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user