diff --git a/java/APIGroupe/Makefile b/java/APIGroupe/Makefile index ca8bb68..30f58f2 100644 --- a/java/APIGroupe/Makefile +++ b/java/APIGroupe/Makefile @@ -86,6 +86,11 @@ ${BUILD}/MNP/AbstractGroupeFactoryNP.class : ${SRC}/MNP/AbstractGroupeFactoryNP. ${BUILD}/API/AbstractGroupeFactory.class ${JAVAC} ${JAVAC_OPTIONS} ${SRC}/MNP/AbstractGroupeFactoryNP.java +${BUILD}/MNP/AbstractChangementFactoryNP.class : ${SRC}/MNP/AbstractChangementFactoryNP.java \ + ${BUILD}/API/AbstractChangementFactory.class \ + ${BUILD}/API/Changement.class + ${JAVAC} ${JAVAC_OPTIONS} ${SRC}/MNP/AbstractChangementFactoryNP.java + ###... @@ -95,7 +100,8 @@ ${BUILD}/MNP/AbstractGroupeFactoryNP.class : ${SRC}/MNP/AbstractGroupeFactoryNP. ${BUILD}/MNP/EtudiantNP.class \ ${BUILD}/MNP/GroupeNP.class \ ${BUILD}/MNP/ChangementNP.class \ - ${BUILD}/MNP/AbstractGroupeFactoryNP.class + ${BUILD}/MNP/AbstractGroupeFactoryNP.class \ + ${BUILD}/MNP/AbstractChangementFactoryNP.class ${JAVAC} -Xlint:deprecation ${JAVAC_OPTIONS} ${SRC}/Test/TestTexteMNP.java # ## JARS ## diff --git a/java/APIGroupe/README.md b/java/APIGroupe/README.md index 22317a9..ff9eb95 100644 --- a/java/APIGroupe/README.md +++ b/java/APIGroupe/README.md @@ -1,6 +1,8 @@ # APIGroupes -Attention l'API n'est pas encore complète. +Attention l'API n'est pas encore complètement testée. + +Je viens d'ajouter des éléments pour les changements (modèles NP, changements mineurs dans l'API et exemples dans le fichier de test). API pour le projet IHM 2022-2023. diff --git a/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/API/AbstractChangementFactory.class b/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/API/AbstractChangementFactory.class new file mode 100644 index 0000000..68bcaf2 Binary files /dev/null and b/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/API/AbstractChangementFactory.class differ diff --git a/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/API/AbstractGroupeFactory.class b/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/API/AbstractGroupeFactory.class new file mode 100644 index 0000000..634d5e0 Binary files /dev/null and b/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/API/AbstractGroupeFactory.class differ diff --git a/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/API/Changement.class b/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/API/Changement.class new file mode 100644 index 0000000..bbd34c1 Binary files /dev/null and b/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/API/Changement.class differ diff --git a/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/API/Etudiant.class b/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/API/Etudiant.class new file mode 100644 index 0000000..a784b44 Binary files /dev/null and b/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/API/Etudiant.class differ diff --git a/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/API/Groupe.class b/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/API/Groupe.class new file mode 100644 index 0000000..7bcf3e0 Binary files /dev/null and b/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/API/Groupe.class differ diff --git a/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/API/MonPrint.class b/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/API/MonPrint.class new file mode 100644 index 0000000..43f1677 Binary files /dev/null and b/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/API/MonPrint.class differ diff --git a/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/API/TypeGroupe.class b/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/API/TypeGroupe.class new file mode 100644 index 0000000..948bd10 Binary files /dev/null and b/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/API/TypeGroupe.class differ diff --git a/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/MNP/AbstractChangementFactoryNP.class b/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/MNP/AbstractChangementFactoryNP.class new file mode 100644 index 0000000..db778bb Binary files /dev/null and b/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/MNP/AbstractChangementFactoryNP.class differ diff --git a/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/MNP/AbstractGroupeFactoryNP.class b/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/MNP/AbstractGroupeFactoryNP.class new file mode 100644 index 0000000..55683c4 Binary files /dev/null and b/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/MNP/AbstractGroupeFactoryNP.class differ diff --git a/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/MNP/ChangementNP.class b/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/MNP/ChangementNP.class new file mode 100644 index 0000000..10825aa Binary files /dev/null and b/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/MNP/ChangementNP.class differ diff --git a/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/MNP/EtudiantNP.class b/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/MNP/EtudiantNP.class new file mode 100644 index 0000000..7eddb62 Binary files /dev/null and b/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/MNP/EtudiantNP.class differ diff --git a/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/MNP/GroupeNP.class b/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/MNP/GroupeNP.class new file mode 100644 index 0000000..4df694e Binary files /dev/null and b/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/MNP/GroupeNP.class differ diff --git a/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/Test/TestTexteMNP.class b/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/Test/TestTexteMNP.class new file mode 100644 index 0000000..f68d60c Binary files /dev/null and b/java/APIGroupe/build/fr/iutfbleau/projetIHM2022FI2/Test/TestTexteMNP.class differ diff --git a/java/APIGroupe/src/fr/iutfbleau/projetIHM2022FI2/API/AbstractChangementFactory.java b/java/APIGroupe/src/fr/iutfbleau/projetIHM2022FI2/API/AbstractChangementFactory.java index 9c2c6b4..4acea36 100644 --- a/java/APIGroupe/src/fr/iutfbleau/projetIHM2022FI2/API/AbstractChangementFactory.java +++ b/java/APIGroupe/src/fr/iutfbleau/projetIHM2022FI2/API/AbstractChangementFactory.java @@ -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 dans la version beta. */ - public Iterator getAllChangements(); + public Set 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. * diff --git a/java/APIGroupe/src/fr/iutfbleau/projetIHM2022FI2/API/AbstractGroupeFactory.java b/java/APIGroupe/src/fr/iutfbleau/projetIHM2022FI2/API/AbstractGroupeFactory.java index 946dff7..63dc788 100644 --- a/java/APIGroupe/src/fr/iutfbleau/projetIHM2022FI2/API/AbstractGroupeFactory.java +++ b/java/APIGroupe/src/fr/iutfbleau/projetIHM2022FI2/API/AbstractGroupeFactory.java @@ -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. diff --git a/java/APIGroupe/src/fr/iutfbleau/projetIHM2022FI2/API/Changement.java b/java/APIGroupe/src/fr/iutfbleau/projetIHM2022FI2/API/Changement.java index 1b0d88d..9b8bab4 100644 --- a/java/APIGroupe/src/fr/iutfbleau/projetIHM2022FI2/API/Changement.java +++ b/java/APIGroupe/src/fr/iutfbleau/projetIHM2022FI2/API/Changement.java @@ -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(); } diff --git a/java/APIGroupe/src/fr/iutfbleau/projetIHM2022FI2/API/Groupe.java b/java/APIGroupe/src/fr/iutfbleau/projetIHM2022FI2/API/Groupe.java index cb397fa..0d24d4b 100644 --- a/java/APIGroupe/src/fr/iutfbleau/projetIHM2022FI2/API/Groupe.java +++ b/java/APIGroupe/src/fr/iutfbleau/projetIHM2022FI2/API/Groupe.java @@ -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"); diff --git a/java/APIGroupe/src/fr/iutfbleau/projetIHM2022FI2/MNP/AbstractChangementFactoryNP.java b/java/APIGroupe/src/fr/iutfbleau/projetIHM2022FI2/MNP/AbstractChangementFactoryNP.java new file mode 100644 index 0000000..a586c32 --- /dev/null +++ b/java/APIGroupe/src/fr/iutfbleau/projetIHM2022FI2/MNP/AbstractChangementFactoryNP.java @@ -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 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(); + } + + + /** + * 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 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 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); + } + +} diff --git a/java/APIGroupe/src/fr/iutfbleau/projetIHM2022FI2/MNP/AbstractGroupeFactoryNP.java b/java/APIGroupe/src/fr/iutfbleau/projetIHM2022FI2/MNP/AbstractGroupeFactoryNP.java index c86a834..4f3264e 100644 --- a/java/APIGroupe/src/fr/iutfbleau/projetIHM2022FI2/MNP/AbstractGroupeFactoryNP.java +++ b/java/APIGroupe/src/fr/iutfbleau/projetIHM2022FI2/MNP/AbstractGroupeFactoryNP.java @@ -28,20 +28,11 @@ public class AbstractGroupeFactoryNP implements AbstractGroupeFactory { this.brain=new HashMap(); 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 groupes = new ArrayList(n); for(int i = 0; i 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 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()); + } }