diff --git a/Makefile b/Makefile index d7320ea..30f58f2 100644 --- a/Makefile +++ b/Makefile @@ -7,9 +7,9 @@ JAR = jar EXEC_JAR = ${JAVA} -jar # CHEMINS RELATIFS -SRC = src/fr/iutfbleau/projetIHM2021FI2 -BUILD = build/fr/iutfbleau/projetIHM2021FI2 -DOC = doc/fr/iutfbleau/projetIHM2021FI2 +SRC = src/fr/iutfbleau/projetIHM2022FI2 +BUILD = build/fr/iutfbleau/projetIHM2022FI2 +DOC = doc/fr/iutfbleau/projetIHM2022FI2 # CHOIX NOMS JAR_MNP = test-mnp.jar @@ -23,7 +23,7 @@ run : ${JAR_MNP} # AUTRE BUTS doc : - javadoc -d doc src/fr/iutfbleau/projetIHM2021FI2/API/*.java src/fr/iutfbleau/projetIHM2021FI2/MNP/*.java + javadoc -d doc src/fr/iutfbleau/projetIHM2022FI2/API/*.java src/fr/iutfbleau/projetIHM2022FI2/MNP/*.java clean : rm -rf ${BUILD}/* *.jar @@ -35,75 +35,77 @@ clean : ${BUILD}/API/MonPrint.class : ${SRC}/API/MonPrint.java ${JAVAC} ${JAVAC_OPTIONS} ${SRC}/API/MonPrint.java -${BUILD}/API/TypeChambre.class : ${SRC}/API/TypeChambre.java - ${JAVAC} ${JAVAC_OPTIONS} ${SRC}/API/TypeChambre.java +${BUILD}/API/TypeGroupe.class : ${SRC}/API/TypeGroupe.java + ${JAVAC} ${JAVAC_OPTIONS} ${SRC}/API/TypeGroupe.java -${BUILD}/API/Chambre.class : ${SRC}/API/Chambre.java \ - ${BUILD}/API/TypeChambre.class\ +${BUILD}/API/Groupe.class : ${SRC}/API/Groupe.java \ + ${BUILD}/API/TypeGroupe.class\ ${BUILD}/API/MonPrint.class - ${JAVAC} ${JAVAC_OPTIONS} ${SRC}/API/Chambre.java + ${JAVAC} ${JAVAC_OPTIONS} ${SRC}/API/Groupe.java -${BUILD}/API/Client.class : ${SRC}/API/Client.java \ +${BUILD}/API/Etudiant.class : ${SRC}/API/Etudiant.java \ ${BUILD}/API/MonPrint.class - ${JAVAC} ${JAVAC_OPTIONS} ${SRC}/API/Client.java + ${JAVAC} ${JAVAC_OPTIONS} ${SRC}/API/Etudiant.java -${BUILD}/API/Prereservation.class : ${SRC}/API/Prereservation.java \ - ${BUILD}/API/TypeChambre.class \ - ${BUILD}/API/Client.class - ${JAVAC} ${JAVAC_OPTIONS} ${SRC}/API/Prereservation.java +${BUILD}/API/Changement.class : ${SRC}/API/Changement.java \ + ${BUILD}/API/Etudiant.class \ + ${BUILD}/API/Groupe.class + ${JAVAC} ${JAVAC_OPTIONS} ${SRC}/API/Changement.java -${BUILD}/API/Reservation.class : ${SRC}/API/Reservation.java \ - ${BUILD}/API/Chambre.class \ - ${BUILD}/API/Prereservation.class - ${JAVAC} ${JAVAC_OPTIONS} ${SRC}/API/Reservation.java +${BUILD}/API/AbstractGroupeFactory.class : ${SRC}/API/AbstractGroupeFactory.java \ + ${BUILD}/API/Groupe.class \ + ${BUILD}/API/Etudiant.class + ${JAVAC} ${JAVAC_OPTIONS} ${SRC}/API/AbstractGroupeFactory.java -${BUILD}/API/PrereservationFactory.class : ${SRC}/API/PrereservationFactory.java \ - ${BUILD}/API/Prereservation.class - ${JAVAC} ${JAVAC_OPTIONS} ${SRC}/API/PrereservationFactory.java - -${BUILD}/API/ReservationFactory.class : ${SRC}/API/ReservationFactory.java \ - ${BUILD}/API/Reservation.class - ${JAVAC} ${JAVAC_OPTIONS} ${SRC}/API/ReservationFactory.java +${BUILD}/API/AbstractChangementFactory.class : ${SRC}/API/AbstractChangementFactory.java \ + ${BUILD}/API/AbstractGroupeFactory.class \ + ${BUILD}/API/Changement.class + ${JAVAC} ${JAVAC_OPTIONS} ${SRC}/API/AbstractChangementFactory.java ## MNP ## -${BUILD}/MNP/ClientNP.class : ${SRC}/MNP/ClientNP.java \ - ${BUILD}/API/Client.class - ${JAVAC} ${JAVAC_OPTIONS} ${SRC}/MNP/ClientNP.java +${BUILD}/MNP/EtudiantNP.class : ${SRC}/MNP/EtudiantNP.java \ + ${BUILD}/API/Etudiant.class + ${JAVAC} ${JAVAC_OPTIONS} ${SRC}/MNP/EtudiantNP.java -${BUILD}/MNP/ChambreNP.class : ${SRC}/MNP/ChambreNP.java \ - ${BUILD}/API/Chambre.class - ${JAVAC} ${JAVAC_OPTIONS} ${SRC}/MNP/ChambreNP.java -${BUILD}/MNP/PrereservationNP.class : ${SRC}/MNP/PrereservationNP.java \ - ${BUILD}/MNP/ClientNP.class \ - ${BUILD}/API/Prereservation.class - ${JAVAC} ${JAVAC_OPTIONS} ${SRC}/MNP/PrereservationNP.java +${BUILD}/MNP/GroupeNP.class : ${SRC}/MNP/GroupeNP.java \ + ${BUILD}/API/Groupe.class \ + ${BUILD}/API/TypeGroupe.class \ + ${BUILD}/API/Etudiant.class + ${JAVAC} ${JAVAC_OPTIONS} ${SRC}/MNP/GroupeNP.java -${BUILD}/MNP/ReservationNP.class : ${SRC}/MNP/ReservationNP.java \ - ${BUILD}/API/Reservation.class - ${JAVAC} ${JAVAC_OPTIONS} ${SRC}/MNP/ReservationNP.java -${BUILD}/MNP/PrereservationFactoryNP.class : ${SRC}/MNP/PrereservationFactoryNP.java \ - ${BUILD}/API/PrereservationFactory.class - ${JAVAC} ${JAVAC_OPTIONS} ${SRC}/MNP/PrereservationFactoryNP.java +${BUILD}/MNP/ChangementNP.class : ${BUILD}/API/Changement.class \ + ${SRC}/MNP/ChangementNP.java \ + ${BUILD}/API/Groupe.class \ + ${BUILD}/API/Etudiant.class + ${JAVAC} ${JAVAC_OPTIONS} ${SRC}/MNP/ChangementNP.java -${BUILD}/MNP/ReservationFactoryNP.class : ${SRC}/MNP/ReservationFactoryNP.java \ - ${BUILD}/MNP/ChambreNP.class \ - ${BUILD}/MNP/ReservationNP.class \ - ${BUILD}/API/ReservationFactory.class - ${JAVAC} ${JAVAC_OPTIONS} ${SRC}/MNP/ReservationFactoryNP.java +${BUILD}/MNP/AbstractGroupeFactoryNP.class : ${SRC}/MNP/AbstractGroupeFactoryNP.java \ + ${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 + + +###... ## TEST ## ${BUILD}/Test/TestTexteMNP.class : ${SRC}/Test/TestTexteMNP.java \ - ${BUILD}/MNP/PrereservationNP.class \ - ${BUILD}/MNP/PrereservationFactoryNP.class \ - ${BUILD}/MNP/ReservationFactoryNP.class + ${BUILD}/MNP/EtudiantNP.class \ + ${BUILD}/MNP/GroupeNP.class \ + ${BUILD}/MNP/ChangementNP.class \ + ${BUILD}/MNP/AbstractGroupeFactoryNP.class \ + ${BUILD}/MNP/AbstractChangementFactoryNP.class ${JAVAC} -Xlint:deprecation ${JAVAC_OPTIONS} ${SRC}/Test/TestTexteMNP.java # ## JARS ## ${JAR_MNP} : ${BUILD}/Test/TestTexteMNP.class - ${JAR} cvfe ${JAR_MNP} fr.iutfbleau.projetIHM2021FI2.Test.TestTexteMNP -C build fr + ${JAR} cvfe ${JAR_MNP} fr.iutfbleau.projetIHM2022FI2.Test.TestTexteMNP -C build fr diff --git a/README.md b/README.md index b869ea5..ff9eb95 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,10 @@ -# APIHotel +# APIGroupes -API pour le projet IHM 2021-2022. +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. Vous avez un makefile qui permet de générer la javadoc en faisant. $ make doc diff --git a/build/fr/iutfbleau/projetIHM2022FI2/API/AbstractChangementFactory.class b/build/fr/iutfbleau/projetIHM2022FI2/API/AbstractChangementFactory.class new file mode 100644 index 0000000..68bcaf2 Binary files /dev/null and b/build/fr/iutfbleau/projetIHM2022FI2/API/AbstractChangementFactory.class differ diff --git a/build/fr/iutfbleau/projetIHM2022FI2/API/AbstractGroupeFactory.class b/build/fr/iutfbleau/projetIHM2022FI2/API/AbstractGroupeFactory.class new file mode 100644 index 0000000..634d5e0 Binary files /dev/null and b/build/fr/iutfbleau/projetIHM2022FI2/API/AbstractGroupeFactory.class differ diff --git a/build/fr/iutfbleau/projetIHM2022FI2/API/Changement.class b/build/fr/iutfbleau/projetIHM2022FI2/API/Changement.class new file mode 100644 index 0000000..bbd34c1 Binary files /dev/null and b/build/fr/iutfbleau/projetIHM2022FI2/API/Changement.class differ diff --git a/build/fr/iutfbleau/projetIHM2022FI2/API/Etudiant.class b/build/fr/iutfbleau/projetIHM2022FI2/API/Etudiant.class new file mode 100644 index 0000000..a784b44 Binary files /dev/null and b/build/fr/iutfbleau/projetIHM2022FI2/API/Etudiant.class differ diff --git a/build/fr/iutfbleau/projetIHM2022FI2/API/Groupe.class b/build/fr/iutfbleau/projetIHM2022FI2/API/Groupe.class new file mode 100644 index 0000000..7bcf3e0 Binary files /dev/null and b/build/fr/iutfbleau/projetIHM2022FI2/API/Groupe.class differ diff --git a/build/fr/iutfbleau/projetIHM2022FI2/API/MonPrint.class b/build/fr/iutfbleau/projetIHM2022FI2/API/MonPrint.class new file mode 100644 index 0000000..43f1677 Binary files /dev/null and b/build/fr/iutfbleau/projetIHM2022FI2/API/MonPrint.class differ diff --git a/build/fr/iutfbleau/projetIHM2022FI2/API/TypeGroupe.class b/build/fr/iutfbleau/projetIHM2022FI2/API/TypeGroupe.class new file mode 100644 index 0000000..948bd10 Binary files /dev/null and b/build/fr/iutfbleau/projetIHM2022FI2/API/TypeGroupe.class differ diff --git a/build/fr/iutfbleau/projetIHM2022FI2/MNP/AbstractChangementFactoryNP.class b/build/fr/iutfbleau/projetIHM2022FI2/MNP/AbstractChangementFactoryNP.class new file mode 100644 index 0000000..db778bb Binary files /dev/null and b/build/fr/iutfbleau/projetIHM2022FI2/MNP/AbstractChangementFactoryNP.class differ diff --git a/build/fr/iutfbleau/projetIHM2022FI2/MNP/AbstractGroupeFactoryNP.class b/build/fr/iutfbleau/projetIHM2022FI2/MNP/AbstractGroupeFactoryNP.class new file mode 100644 index 0000000..55683c4 Binary files /dev/null and b/build/fr/iutfbleau/projetIHM2022FI2/MNP/AbstractGroupeFactoryNP.class differ diff --git a/build/fr/iutfbleau/projetIHM2022FI2/MNP/ChangementNP.class b/build/fr/iutfbleau/projetIHM2022FI2/MNP/ChangementNP.class new file mode 100644 index 0000000..10825aa Binary files /dev/null and b/build/fr/iutfbleau/projetIHM2022FI2/MNP/ChangementNP.class differ diff --git a/build/fr/iutfbleau/projetIHM2022FI2/MNP/EtudiantNP.class b/build/fr/iutfbleau/projetIHM2022FI2/MNP/EtudiantNP.class new file mode 100644 index 0000000..7eddb62 Binary files /dev/null and b/build/fr/iutfbleau/projetIHM2022FI2/MNP/EtudiantNP.class differ diff --git a/build/fr/iutfbleau/projetIHM2022FI2/MNP/GroupeNP.class b/build/fr/iutfbleau/projetIHM2022FI2/MNP/GroupeNP.class new file mode 100644 index 0000000..4df694e Binary files /dev/null and b/build/fr/iutfbleau/projetIHM2022FI2/MNP/GroupeNP.class differ diff --git a/build/fr/iutfbleau/projetIHM2022FI2/Test/TestTexteMNP.class b/build/fr/iutfbleau/projetIHM2022FI2/Test/TestTexteMNP.class new file mode 100644 index 0000000..f68d60c Binary files /dev/null and b/build/fr/iutfbleau/projetIHM2022FI2/Test/TestTexteMNP.class differ diff --git a/src/fr/iutfbleau/projetIHM2022FI2/API/AbstractChangementFactory.java b/src/fr/iutfbleau/projetIHM2022FI2/API/AbstractChangementFactory.java new file mode 100644 index 0000000..4acea36 --- /dev/null +++ b/src/fr/iutfbleau/projetIHM2022FI2/API/AbstractChangementFactory.java @@ -0,0 +1,55 @@ +package fr.iutfbleau.projetIHM2022FI2.API; +import java.util.*; +/** + * Usine abstraite gérant l'ensemble des changements. + * + * + */ + +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 pour les groupes + */ + public AbstractGroupeFactory getGroupeFactory(); + + /** + * permet de récupérer les changements + * @return l'ensemble de tous les changements en attente + * + * NB. Attention. C'était Iterator dans la version beta. + */ + 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. + * + * @throws java.lang.NullPointerException si un argument est null + * @throws java.lang.IllegalArgumentException si inconnu de l'usine abstraite + */ + public void deleteChangement(Changement c); + + /** + * 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); + +} diff --git a/src/fr/iutfbleau/projetIHM2022FI2/API/AbstractChangementFactory.java~ b/src/fr/iutfbleau/projetIHM2022FI2/API/AbstractChangementFactory.java~ new file mode 100644 index 0000000..9c2c6b4 --- /dev/null +++ b/src/fr/iutfbleau/projetIHM2022FI2/API/AbstractChangementFactory.java~ @@ -0,0 +1,44 @@ +package fr.iutfbleau.projetIHM2022FI2.API; +import java.util.*; +/** + * Usine abstraite gérant l'ensemble des changements. + * + * + */ + +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 + */ + public AbstractGroupeFactory getGroupeFactory(); + + /** + * permet de récupérer les changements + * @return tous les changements en attente + */ + public Iterator getAllChangements(); + + /** + * 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); + + /** + * 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); + +} diff --git a/src/fr/iutfbleau/projetIHM2022FI2/API/AbstractGroupeFactory.java b/src/fr/iutfbleau/projetIHM2022FI2/API/AbstractGroupeFactory.java new file mode 100644 index 0000000..63dc788 --- /dev/null +++ b/src/fr/iutfbleau/projetIHM2022FI2/API/AbstractGroupeFactory.java @@ -0,0 +1,115 @@ +package fr.iutfbleau.projetIHM2022FI2.API; +import java.util.*; +/** + * Usine abstraite gérant l'ensemble des groupes. + * + */ + +public interface AbstractGroupeFactory { + + /** + * permet de récupérer le Groupe qui contient les étudiants de toute la promotion + * @return la promo. + */ + 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. + * + * @throws java.lang.NullPointerException si un argument est null + * @throws java.lang.IllegalStateException si le groupe contient des groupes + * @throws java.lang.IllegalArgumentException si le groupe n'est pas connu de l'usine abstraite ou bien si le groupe est celui de toute la promotion (renvoyé par getPromotion) + */ + public void deleteGroupe(Groupe g); + + /** + * permet d'ajouter un groupe vide de type FREE comme sous-groupe d'un groupe donné. + * @param pere le groupe père du groupe à créer + * @param name le nom du groupe à créer + * @param min,max bornes indicatives sur la taille du groupe à créer + * + * @throws java.lang.NullPointerException si un argument est null + * @throws java.lang.IllegalArgumentException si le groupe pere est de type PARTITION + * ou si il n'y a pas 0 < min <= max + */ + public void createGroupe(Groupe pere, String name, int min, int max); + + /** + * permet de créer une partition automatiquement sous un groupe donné. + * + * @param pere le groupe père du groupe à partitionner + * @param name le nom des groupe à créer (on ajoutera à la suite un numéro ou une lettre pour distinguer chaque groupe) + * @param n le nombre de partitions + * @throws java.lang.NullPointerException si un argument est null + * @throws java.lang.IllegalArgumentException si le groupe pere est de type PARTITION + * ou n négatif ou nul + * + * NB. doit créer une "copie" de pere + * sous pere de type Partition et ajouter sous ce groupe, n groupes de type "FREE". + * les valeurs min et max de ces n groupes sont + * min = 0 et + * max = partie entière de N/n plus 1, où N est le nombre max du groupe pere. + */ + public void createPartition(Groupe pere, String name, int n); + + /** + * permet d'ajouter un étudiant à un groupe. + * + * @param g le groupe dans lequel il faut ajouter l'étudiant + * @param e l'étudiant à ajouter + * + * @throws java.lang.NullPointerException si un argument est null + * @throws java.lang.IllegalArgumentException la factory ne connaît pas g + * @throws java.lang.IllegalStateException le père de g ne contient pas e + */ + public void addToGroupe(Groupe g, Etudiant e); + + /** + * permet d'enlever un étudiant d'un groupe. + * + * @param g le groupe dans lequel il faut enlever l'étudiant + * @param e l'étudiant à enlever + * + * @throws java.lang.NullPointerException si un argument est null + * @throws java.lang.IllegalStateException g ne contient pas e + * @throws java.lang.IllegalArgumentException la factory ne connaît pas g + */ + public void dropFromGroupe(Groupe g, Etudiant e); + + /** + * permet de retrouver un étudiant à partir d'un String. + * + * NB. dans une version simple il doit s'agir du nom exact. + * dans une version un peu plus complexe, il s'agit des premières lettres du nom + * dans une version avancée, on peut autoriser une expression régulière plus ou moins complexe qui est générée si la première recherche n'a pas renvoyé de candidat. + * + * @param String nomEtu le nom approximmatif de l'étudiant + * @return Set l'ensemble des étudiants connus de la factory ayant un nom "proche" de ce string au sens de la remarque ci-dessus. + * + * @throws java.lang.NullPointerException si le String est null. + */ + public Set getEtudiants(String nomEtu); + + /** + * permet de retrouver les groupes d'un étudiant. + * + * @param Etu un étudiant + * @return Etudiant l'étudiant connu de la factory ayant cet identifiant + * + * @throws java.lang.NullPointerException si le String est null. + */ + public Set getGroupesOfEtudiant(Etudiant etu); + + + +} diff --git a/src/fr/iutfbleau/projetIHM2022FI2/API/AbstractGroupeFactory.java~ b/src/fr/iutfbleau/projetIHM2022FI2/API/AbstractGroupeFactory.java~ new file mode 100644 index 0000000..946dff7 --- /dev/null +++ b/src/fr/iutfbleau/projetIHM2022FI2/API/AbstractGroupeFactory.java~ @@ -0,0 +1,106 @@ +package fr.iutfbleau.projetIHM2022FI2.API; +import java.util.*; +/** + * Usine abstraite gérant l'ensemble des groupes. + * + */ + +public interface AbstractGroupeFactory { + + /** + * permet de récupérer le Groupe qui contient les étudiants de toute la promotion + * @return la promo. + */ + public Groupe getPromotion(); + + /** + * 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. + * + * @throws java.lang.NullPointerException si un argument est null + * @throws java.lang.IllegalStateException si le groupe contient des groupes + * @throws java.lang.IllegalArgumentException si le groupe n'est pas connu de l'usine abstraite ou bien si le groupe est celui de toute la promotion (renvoyé par getPromotion) + */ + public void deleteGroupe(Groupe g); + + /** + * permet d'ajouter un groupe vide de type FREE comme sous-groupe d'un groupe donné. + * @param pere le groupe père du groupe à créer + * @param name le nom du groupe à créer + * @param min,max bornes indicatives sur la taille du groupe à créer + * + * @throws java.lang.NullPointerException si un argument est null + * @throws java.lang.IllegalArgumentException si le groupe pere est de type PARTITION + * ou si il n'y a pas 0 < min <= max + */ + public void createGroupe(Groupe pere, String name, int min, int max); + + /** + * permet de créer une partition automatiquement sous un groupe donné. + * + * @param pere le groupe père du groupe à partitionner + * @param name le nom des groupe à créer (on ajoutera à la suite un numéro ou une lettre pour distinguer chaque groupe) + * @param n le nombre de partitions + * @throws java.lang.NullPointerException si un argument est null + * @throws java.lang.IllegalArgumentException si le groupe pere est de type PARTITION + * ou n négatif ou nul + * + * NB. doit créer une "copie" de pere + * sous pere de type Partition et ajouter sous ce groupe, n groupes de type "FREE". + * les valeurs min et max de ces n groupes sont + * min = 0 et + * max = partie entière de N/n plus 1, où N est le nombre max du groupe pere. + */ + public void createPartition(Groupe pere, String name, int n); + + /** + * permet d'ajouter un étudiant à un groupe. + * + * @param g le groupe dans lequel il faut ajouter l'étudiant + * @param e l'étudiant à ajouter + * + * @throws java.lang.NullPointerException si un argument est null + * @throws java.lang.IllegalArgumentException la factory ne connaît pas g + * @throws java.lang.IllegalStateException le père de g ne contient pas e + */ + public void addToGroupe(Groupe g, Etudiant e); + + /** + * permet d'enlever un étudiant d'un groupe. + * + * @param g le groupe dans lequel il faut enlever l'étudiant + * @param e l'étudiant à enlever + * + * @throws java.lang.NullPointerException si un argument est null + * @throws java.lang.IllegalStateException g ne contient pas e + * @throws java.lang.IllegalArgumentException la factory ne connaît pas g + */ + public void dropFromGroupe(Groupe g, Etudiant e); + + /** + * permet de retrouver un étudiant à partir d'un String. + * + * NB. dans une version simple il doit s'agir du nom exact. + * dans une version un peu plus complexe, il s'agit des premières lettres du nom + * dans une version avancée, on peut autoriser une expression régulière plus ou moins complexe qui est générée si la première recherche n'a pas renvoyé de candidat. + * + * @param String nomEtu le nom approximmatif de l'étudiant + * @return Set l'ensemble des étudiants connus de la factory ayant un nom "proche" de ce string au sens de la remarque ci-dessus. + * + * @throws java.lang.NullPointerException si le String est null. + */ + public Set getEtudiants(String nomEtu); + + /** + * permet de retrouver les groupes d'un étudiant. + * + * @param Etu un étudiant + * @return Etudiant l'étudiant connu de la factory ayant cet identifiant + * + * @throws java.lang.NullPointerException si le String est null. + */ + public Set getGroupesOfEtudiant(Etudiant etu); + + + +} diff --git a/src/fr/iutfbleau/projetIHM2022FI2/API/Changement.java b/src/fr/iutfbleau/projetIHM2022FI2/API/Changement.java new file mode 100644 index 0000000..9b8bab4 --- /dev/null +++ b/src/fr/iutfbleau/projetIHM2022FI2/API/Changement.java @@ -0,0 +1,49 @@ +package fr.iutfbleau.projetIHM2022FI2.API; +import java.util.*; +/** + * Une demande de changement de groupe + * concerne un étudiant, qui est dans un groupe A et veut aller dans un groupe B. + * + */ + +public interface Changement extends MonPrint { + + /** + * permet de récupérer l'identifiant du changement (référence interne sans intérêt irl). + * @return l'identifiant. + */ + public int getId(); + + /** + * permet de récupérer le groupe de depart + * @return ce groupe. + */ + public Groupe getA(); + + /** + * permet de récupérer le groupe d'arrivée + * @return ce groupe. + */ + public Groupe getB(); + + /** + * permet de récupérer l'étudiant demandant le changement + * @return cet étudiant + */ + public Etudiant getEtu(); + + + /** + * @see MonPrint + * NB. On n'utilise le mécanisme des méthodes par défaut pour donner du code dans une interface. C'est un petit peu laid et à contre-emploi mais pratique ici. + * + * NB2. On ne peut pas utiliser le toString de Objects + * https://stackoverflow.com/questions/24016962/java8-why-is-it-forbidden-to-define-a-default-method-for-a-method-from-java-lan + */ + 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.getB().getName()); + return sb.toString(); + } + +} diff --git a/src/fr/iutfbleau/projetIHM2022FI2/API/Changement.java~ b/src/fr/iutfbleau/projetIHM2022FI2/API/Changement.java~ new file mode 100644 index 0000000..1b0d88d --- /dev/null +++ b/src/fr/iutfbleau/projetIHM2022FI2/API/Changement.java~ @@ -0,0 +1,49 @@ +package fr.iutfbleau.projetIHM2022FI2.API; +import java.util.*; +/** + * Une demande de changement de groupe + * concerne un étudiant, qui est dans un groupe A et veut aller dans un groupe B. + * + */ + +public interface Changement extends MonPrint { + + /** + * permet de récupérer l'identifiant du changement (référence interne sans intérêt irl). + * @return l'identifiant. + */ + public int getId(); + + /** + * permet de récupérer le groupe de depart + * @return ce groupe. + */ + public Groupe getA(); + + /** + * permet de récupérer le groupe d'arrivée + * @return ce groupe. + */ + public Groupe getB(); + + /** + * permet de récupérer l'étudiant demandant le changement + * @return cet étudiant + */ + public Etudiant getEtu(); + + + /** + * @see MonPrint + * NB. On n'utilise le mécanisme des méthodes par défaut pour donner du code dans une interface. C'est un petit peu laid et à contre-emploi mais pratique ici. + * + * NB2. On ne peut pas utiliser le toString de Objects + * https://stackoverflow.com/questions/24016962/java8-why-is-it-forbidden-to-define-a-default-method-for-a-method-from-java-lan + */ + 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()); + return sb.toString(); + } + +} diff --git a/src/fr/iutfbleau/projetIHM2022FI2/API/Etudiant.java b/src/fr/iutfbleau/projetIHM2022FI2/API/Etudiant.java new file mode 100644 index 0000000..a31828b --- /dev/null +++ b/src/fr/iutfbleau/projetIHM2022FI2/API/Etudiant.java @@ -0,0 +1,33 @@ +package fr.iutfbleau.projetIHM2022FI2.API; +/** + * Un étudiant + */ + +public interface Etudiant extends MonPrint{ + + /** + * permet de récupérer l'identifiant de l'étudiant. + * @return l'identifiant. + */ + public int getId(); + + /** + * permet de récupérer + * @return le nom de l'étudiant. + */ + public String getNom(); + + /** + * permet de récupérer + * @return le prénom de l'étudiant + */ + public String getPrenom(); + + /** + * @see MonPrint + * NB. On n'utilise le mécanisme des méthodes par défaut pour donner du code dans une interface. C'est un petit peu laid et à contre-emploi mais pratique ici. + */ + public default String monPrint() { + return String.format("Nom " + getNom() + " Prenom " + getPrenom() + " (id="+getId()+")"); + } +} diff --git a/src/fr/iutfbleau/projetIHM2022FI2/API/Etudiant.java~ b/src/fr/iutfbleau/projetIHM2022FI2/API/Etudiant.java~ new file mode 100644 index 0000000..e7334a6 --- /dev/null +++ b/src/fr/iutfbleau/projetIHM2022FI2/API/Etudiant.java~ @@ -0,0 +1,33 @@ +package fr.iutfbleau.projetIHM2022FI2.API; +/** + * Un étudiant + */ + +public interface Etudiant extends MonPrint{ + + /** + * permet de récupérer l'identifiant de l'étudiant (qu'on suppose être le même pour les différents systèmes, internes et externes à l'hôtel). + * @return l'identifiant. + */ + public int getId(); + + /** + * permet de récupérer + * @return le nom de l'étudiant. + */ + public String getNom(); + + /** + * permet de récupérer + * @return le prénom de l'étudiant + */ + public String getPrenom(); + + /** + * @see MonPrint + * NB. On n'utilise le mécanisme des méthodes par défaut pour donner du code dans une interface. C'est un petit peu laid et à contre-emploi mais pratique ici. + */ + public default String monPrint() { + return String.format("Nom " + getNom() + " Prenom " + getPrenom() + " (id="+getId()+")"); + } +} diff --git a/src/fr/iutfbleau/projetIHM2022FI2/API/Groupe.java b/src/fr/iutfbleau/projetIHM2022FI2/API/Groupe.java new file mode 100644 index 0000000..0d24d4b --- /dev/null +++ b/src/fr/iutfbleau/projetIHM2022FI2/API/Groupe.java @@ -0,0 +1,121 @@ +package fr.iutfbleau.projetIHM2022FI2.API; +import java.util.*; +/** + * Un groupe + */ + +public interface Groupe extends MonPrint { + /** + * Ajoute un étudiant. Se comporte comme add de l'interface Set. + * + * @return true iff e est ajouté + */ + public boolean addEtudiant(Etudiant e); + + /** + * Enlève un étudiant. Se comporte comme remove de l'interface Set. + * + * @return true iff e est enlevé + */ + boolean removeEtudiant(Etudiant e); + + /** + * Ajoute un sous-groupe. Se comporte comme add de l'interface Set. + * vérifie que le groupe passé en argument a bien renseigné this comme son père. + * + * @return true iff g est ajouté + */ + public boolean addSousGroupe(Groupe g); + + /** + * Enlève un groupe. Se comporte comme remove de l'interface Set. + * + * @return true iff e est enlevé + */ + public boolean removeSousGroupe(Groupe g); + + /** + * permet de récupérer l'identifiant d'un groupe (référence interne sans intérêt irl). + * @return l'identifiant. + */ + public int getId(); + + /** + * permet de récupérer le nom d'un groupe (utile irl). + * @return le nom. + */ + public String getName(); + + /** + * permet de récupérer le nombre minimum d'étudiants souhaités dans le groupe. + * @return le minimum souhaité + */ + public int getMin(); + + /** + * permet de récupérer le nombre maximum d'étudiants souhaités dans un groupe. + * @return le maximum souhaité + */ + public int getMax(); + + /** + * permet de récupérer le nombre d'étudiants dans ce groupe. + * @return le nombre de places prises (pas forcément limité entre Min et Max, mais c'est le but) + */ + public int getSize(); + + /** + * permet de récupérer la nature du groupe + * @return le type du groupe + */ + public TypeGroupe getType(); + + /** + * permet de récupérer le groupe père + * un groupe racine devrait retourner lui-même + * + * @return le père + */ + public Groupe getPointPoint(); + + /** + * Potentiellement "vide" + * @return l'ensemble des sous-groupes. + */ + public Set getSousGroupes(); + + /** + * Potentiellement "vide" + * @return l'ensemble des étudiants. + */ + public Set getEtudiants(); + + /** + * @see MonPrint + * NB. On n'utilise le mécanisme des méthodes par défaut pour donner du code dans une interface. C'est un petit peu laid et à contre-emploi mais pratique ici. + * + * NB2. On ne peut pas utiliser le toString de Objects + * https://stackoverflow.com/questions/24016962/java8-why-is-it-forbidden-to-define-a-default-method-for-a-method-from-java-lan + */ + public default String monPrint() { + StringBuilder sb = new StringBuilder(); + sb.append("Groupe " + getName() + " (" + getType() + ", capacité " + getMin() + " à " + getMax() +", id " + getId()+")"); + sb.append("\n"); + // NB. getEtudiants() retourne un Set qui étend Iterable + // On peut utiliser les mécanismes de boucle "moderne" de puis la version 8 + // pour se faciliter la vie quand le traitement est assez simple + // voir https://docs.oracle.com/javase/8/docs/technotes/guides/language/foreach.html + sb.append(" ** Étudiants **\n"); + for (Etudiant s: getEtudiants()){ + sb.append("\t _ "+ s.monPrint()); + sb.append("\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"); + } + return sb.toString(); + } + +} diff --git a/src/fr/iutfbleau/projetIHM2022FI2/API/Groupe.java~ b/src/fr/iutfbleau/projetIHM2022FI2/API/Groupe.java~ new file mode 100644 index 0000000..cb397fa --- /dev/null +++ b/src/fr/iutfbleau/projetIHM2022FI2/API/Groupe.java~ @@ -0,0 +1,121 @@ +package fr.iutfbleau.projetIHM2022FI2.API; +import java.util.*; +/** + * Un groupe + */ + +public interface Groupe extends MonPrint { + /** + * Ajoute un étudiant. Se comporte comme add de l'interface Set. + * + * @return true iff e est ajouté + */ + public boolean addEtudiant(Etudiant e); + + /** + * Enlève un étudiant. Se comporte comme remove de l'interface Set. + * + * @return true iff e est enlevé + */ + boolean removeEtudiant(Etudiant e); + + /** + * Ajoute un sous-groupe. Se comporte comme add de l'interface Set. + * vérifie que le groupe passé en argument a bien renseigné this comme son père. + * + * @return true iff g est ajouté + */ + public boolean addSousGroupe(Groupe g); + + /** + * Enlève un groupe. Se comporte comme remove de l'interface Set. + * + * @return true iff e est enlevé + */ + public boolean removeSousGroupe(Groupe g); + + /** + * permet de récupérer l'identifiant d'un groupe (référence interne sans intérêt irl). + * @return l'identifiant. + */ + public int getId(); + + /** + * permet de récupérer le nom d'un groupe (utile irl). + * @return le nom. + */ + public String getName(); + + /** + * permet de récupérer le nombre minimum d'étudiants souhaités dans le groupe. + * @return le minimum souhaité + */ + public int getMin(); + + /** + * permet de récupérer le nombre maximum d'étudiants souhaités dans un groupe. + * @return le maximum souhaité + */ + public int getMax(); + + /** + * permet de récupérer le nombre d'étudiants dans ce groupe. + * @return le nombre de places prises (pas forcément limité entre Min et Max, mais c'est le but) + */ + public int getSize(); + + /** + * permet de récupérer la nature du groupe + * @return le type du groupe + */ + public TypeGroupe getType(); + + /** + * permet de récupérer le groupe père + * un groupe racine devrait retourner lui-même + * + * @return le père + */ + public Groupe getPointPoint(); + + /** + * Potentiellement "vide" + * @return l'ensemble des sous-groupes. + */ + public Set getSousGroupes(); + + /** + * Potentiellement "vide" + * @return l'ensemble des étudiants. + */ + public Set getEtudiants(); + + /** + * @see MonPrint + * NB. On n'utilise le mécanisme des méthodes par défaut pour donner du code dans une interface. C'est un petit peu laid et à contre-emploi mais pratique ici. + * + * NB2. On ne peut pas utiliser le toString de Objects + * https://stackoverflow.com/questions/24016962/java8-why-is-it-forbidden-to-define-a-default-method-for-a-method-from-java-lan + */ + public default String monPrint() { + StringBuilder sb = new StringBuilder(); + sb.append("Groupe " + getName() + " (" + getType() + ", capacité " + getMin() + " à " + getMax() +", id " + getId()+")"); + sb.append("\n"); + // NB. getEtudiants() retourne un Set qui étend Iterable + // On peut utiliser les mécanismes de boucle "moderne" de puis la version 8 + // pour se faciliter la vie quand le traitement est assez simple + // voir https://docs.oracle.com/javase/8/docs/technotes/guides/language/foreach.html + sb.append(" ** Étudiants **\n"); + for (Etudiant s: getEtudiants()){ + sb.append("\t _ "+ s.monPrint()); + sb.append("\n"); + } + sb.append(" ** Sous Groupess **\n"); + for (Groupe g: getSousGroupes()){ + sb.append("\t _ "+ g.getName() + " (" + g.getType() + ", capacité " + g.getMin() + " à " + g.getMax() +", id " + g.getId()+")"); + sb.append("\n"); + } + return sb.toString(); + } + +} diff --git a/src/fr/iutfbleau/projetIHM2022FI2/API/MonPrint.java b/src/fr/iutfbleau/projetIHM2022FI2/API/MonPrint.java new file mode 100644 index 0000000..7f8d663 --- /dev/null +++ b/src/fr/iutfbleau/projetIHM2022FI2/API/MonPrint.java @@ -0,0 +1,12 @@ +package fr.iutfbleau.projetIHM2022FI2.API; +/** + * Toutes nos interfaces vont étendre cette interface. + */ +public interface MonPrint { + + /** + * Fonctionne comme ToPrint() sauf car une interface n'a pas le droit de faire un override sur ToPrint(). + * Toutes nos interfaces vont étendre cette interface. + */ + public String monPrint(); +} diff --git a/src/fr/iutfbleau/projetIHM2022FI2/API/MonPrint.java~ b/src/fr/iutfbleau/projetIHM2022FI2/API/MonPrint.java~ new file mode 100644 index 0000000..e5fafae --- /dev/null +++ b/src/fr/iutfbleau/projetIHM2022FI2/API/MonPrint.java~ @@ -0,0 +1,7 @@ +public interface MonPrint{ + + /** + * Fonctionne comme ToPrint() sauf car une interface n'a pas le droit de faire un override sur ToPrint(); + */ + public String monPrint(); +} diff --git a/src/fr/iutfbleau/projetIHM2022FI2/API/TypeGroupe.java b/src/fr/iutfbleau/projetIHM2022FI2/API/TypeGroupe.java new file mode 100644 index 0000000..b9d9080 --- /dev/null +++ b/src/fr/iutfbleau/projetIHM2022FI2/API/TypeGroupe.java @@ -0,0 +1,10 @@ +package fr.iutfbleau.projetIHM2022FI2.API; +public enum TypeGroupe { + ROOT ("Tous les étudiants"), PARTITION ("partition"), FREE ("libre") ; + + private final String name; + + private TypeGroupe(String s) { + name = s; + } +} diff --git a/src/fr/iutfbleau/projetIHM2022FI2/API/TypeGroupe.java~ b/src/fr/iutfbleau/projetIHM2022FI2/API/TypeGroupe.java~ new file mode 100644 index 0000000..902843e --- /dev/null +++ b/src/fr/iutfbleau/projetIHM2022FI2/API/TypeGroupe.java~ @@ -0,0 +1,10 @@ +package fr.iutfbleau.projetIHM2022FI2.API; +public enum TypeGroupe { + ROOT ("Tous les étudiants"), PARTITION ("partitionable"), FREE ("libre") ; + + private final String name; + + private TypeGroupe(String s) { + name = s; + } +} diff --git a/src/fr/iutfbleau/projetIHM2022FI2/MNP/AbstractChangementFactoryNP.java b/src/fr/iutfbleau/projetIHM2022FI2/MNP/AbstractChangementFactoryNP.java new file mode 100644 index 0000000..a586c32 --- /dev/null +++ b/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/src/fr/iutfbleau/projetIHM2022FI2/MNP/AbstractChangementFactoryNP.java~ b/src/fr/iutfbleau/projetIHM2022FI2/MNP/AbstractChangementFactoryNP.java~ new file mode 100644 index 0000000..7e73e9e --- /dev/null +++ b/src/fr/iutfbleau/projetIHM2022FI2/MNP/AbstractChangementFactoryNP.java~ @@ -0,0 +1,101 @@ +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){ + throw new UnsupportedOperationException("pas encore implanté"); + } + + /** + * 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/src/fr/iutfbleau/projetIHM2022FI2/MNP/AbstractGroupFactoryNP.java~ b/src/fr/iutfbleau/projetIHM2022FI2/MNP/AbstractGroupFactoryNP.java~ new file mode 100644 index 0000000..f1dbec9 --- /dev/null +++ b/src/fr/iutfbleau/projetIHM2022FI2/MNP/AbstractGroupFactoryNP.java~ @@ -0,0 +1,106 @@ +package fr.iutfbleau.projetIHM2022FI2.API; +import java.util.*; +/** + * Usine abstraite gérant l'ensemble des groupes. + * + */ + +public interface AbstractGroupeFactory { + + /** + * permet de récupérer le Groupe qui contient les étudiants de toute la promotion + * @return la promo. + */ + public Groupe getPromotion(); + + /** + * 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. + * + * @throws java.lang.NullPointerException si un argument est null + * @throws java.lang.IllegalStateException si le groupe contient des groupes + * @throws java.lang.IllegalArgumentException si le groupe n'est pas connu de l'usine abstraite ou bien si le groupe est celui de toute la promotion (renvoyé par getPromotion) + */ + public void deleteGroupe(Groupe g); + + /** + * permet d'ajouter un groupe vide de type FREE comme sous-groupe d'un groupe donné. + * @param pere le groupe père du groupe à créer + * @param name le nom du groupe à créer + * @param min,max bornes indicatives sur la taille du groupe à créer + * + * @throws java.lang.NullPointerException si un argument est null + * @throws java.lang.IllegalArgumentException si le groupe pere est de type PARTITION + * ou si il n'y a pas 0 < min <= max + */ + public void createGroupe(Groupe pere, String name, int min, int max); + + /** + * permet de créer une partition automatiquement sous un groupe donné. + * + * @param pere le groupe père du groupe à partitionner + * @param name le nom des groupe à créer (on ajoutera à la suite un numéro ou une lettre pour distinguer chaque groupe) + * @param n le nombre de partitions + * @throws java.lang.NullPointerException si un argument est null + * @throws java.lang.IllegalArgumentException si le groupe pere est de type PARTITION + * ou n négatif ou nul + * + * NB. doit créer une "copie" de pere + * sous pere de type Partition et ajouter sous ce groupe, n groupes de type "FREE". + * les valeurs min et max de ces n groupes sont + * min = 0 et + * max = partie entière de N/n plus 1, où N est le nombre max du groupe pere. + */ + public void createPartition(Groupe pere, String name, int n); + + /** + * permet d'ajouter un étudiant à un groupe. + * + * @param g le groupe dans lequel il faut ajouter l'étudiant + * @param e l'étudiant à ajouter + * + * @throws java.lang.NullPointerException si un argument est null + * @throws java.lang.IllegalArgumentException la factory ne connaît pas g + * @throws java.lang.IllegalStateException le père de g ne contient pas e + */ + public void addToGroupe(Groupe g, Etudiant e); + + /** + * permet d'enlever un étudiant d'un groupe. + * + * @param g le groupe dans lequel il faut enlever l'étudiant + * @param e l'étudiant à enlever + * + * @throws java.lang.NullPointerException si un argument est null + * @throws java.lang.IllegalStateException g ne contient pas e + * @throws java.lang.IllegalArgumentException la factory ne connaît pas g + */ + public void dropFromGroupe(Groupe g, Etudiant e); + + /** + * permet de retrouver un étudiant à partir d'un String. + * + * NB. dans une version simple il doit s'agir du nom exact. + * dans une version un peu plus complexe, il s'agit des premières lettres du nom + * dans une version avancée, on peut autoriser une expression régulière plus ou moins complexe qui est générée si la première recherche n'a pas renvoyé de candidat. + * + * @param String nomEtu le nom approximmatif de l'étudiant + * @return Set l'ensemble des étudiants connus de la factory ayant un nom "proche" de ce string au sens de la remarque ci-dessus. + * + * @throws java.lang.NullPointerException si le String est null. + */ + public Set getEtudiantFromId(String nomEtu); + + /** + * permet de retrouver les groupes d'un étudiant. + * + * @param Etu un étudiant + * @return Etudiant l'étudiant connu de la factory ayant cet identifiant + * + * @throws java.lang.NullPointerException si le String est null. + */ + public Set getGroupesOfEtudiant(Etudiant etu); + + + +} diff --git a/src/fr/iutfbleau/projetIHM2022FI2/MNP/AbstractGroupeFactoryNP.java b/src/fr/iutfbleau/projetIHM2022FI2/MNP/AbstractGroupeFactoryNP.java new file mode 100644 index 0000000..4f3264e --- /dev/null +++ b/src/fr/iutfbleau/projetIHM2022FI2/MNP/AbstractGroupeFactoryNP.java @@ -0,0 +1,225 @@ +package fr.iutfbleau.projetIHM2022FI2.MNP; +import fr.iutfbleau.projetIHM2022FI2.API.*; +import java.util.*; +/** + * Usine abstraite gérant l'ensemble des groupes. + * + */ + +public class AbstractGroupeFactoryNP implements AbstractGroupeFactory { + + // la racine (promotion) + private Groupe promo; + + // On utilise une table de hachage pour retrouver facilement un groupe (à partir de son id). + // Si il y a beaucoup de groupes c'est plus rapide que de parcourir toute une liste. + private HashMap brain; + + + + + /** + * Le constructeur fabrique le groupe promotion vide. + * Il faut ensuite y ajouter les étudiants. + */ + public AbstractGroupeFactoryNP(String name, int min, int max){ + Objects.requireNonNull(name,"On ne peut pas créer une promotion dont le nom est null"); + this.promo=new GroupeNP(name,min,max); + this.brain=new HashMap(); + this.brain.put(Integer.valueOf(this.promo.getId()),this.promo); + } + + /** + * Test plutôt optimiste. Si la clé est identique alors on fait comme si c'était le bon groupe. + */ + public Boolean knows(Groupe g){ + return this.brain.containsKey(Integer.valueOf(g.getId())); + } + + + + /** + * permet de récupérer le Groupe qui contient les étudiants de toute la promotion + * @return la promo. + */ + public Groupe getPromotion(){ + return this.promo; + } + + /** + * 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. + * + * @throws java.lang.NullPointerException si un argument est null + * @throws java.lang.IllegalStateException si le groupe contient des groupes + * @throws java.lang.IllegalArgumentException si le groupe n'est pas connu de l'usine abstraite ou bien si le groupe est celui de toute la promotion (renvoyé par getPromotion) + */ + public void deleteGroupe(Groupe g){ + Objects.requireNonNull(g,"On ne peut pas enlever un groupe null car null n'est pas un groupe autorisé"); + if (!this.knows(g)){ + throw new IllegalArgumentException("Impossible d'enlever un groupe inconnu"); + } + if (this.getPromotion().equals(g)){ + throw new IllegalArgumentException("Impossible de détruire le groupe de toute la promotion"); + } + if (g.getSize()>0){ + throw new IllegalStateException("Impossible de détruire un groupe contenant un groupe"); + } + g.getPointPoint().removeSousGroupe(g); + this.brain.remove(Integer.valueOf(g.getId())); + } + + /** + * permet d'ajouter un groupe vide de type FREE comme sous-groupe d'un groupe donné. + * @param pere le groupe père du groupe à créer + * @param name le nom du groupe à créer + * @param min,max bornes indicatives sur la taille du groupe à créer + * + * @throws java.lang.NullPointerException si un argument est null + * @throws java.lang.IllegalArgumentException si le groupe pere est de type PARTITION + * ou si il n'y a pas 0 < min <= max + */ + public void createGroupe(Groupe pere, String name, int min, int max){ + Objects.requireNonNull(pere,"Le groupe pere ne peut pas être null"); + Objects.requireNonNull(name,"Le nouveau groupe ne peut pas avoir null comme nom"); + if (!this.knows(pere)){ + throw new IllegalArgumentException("Interdit d'ajouter un fils à un groupe inconnu"); + } + if (pere.getType().equals(TypeGroupe.PARTITION)){ + throw new IllegalArgumentException("Impossible d'ajouter un groupe à une parition. Il faut utiliser createPartition pour créer une partition"); + } + if ( min <= 0 || max < min){ + throw new IllegalArgumentException("Il faut que 0 < min <= max"); + } + Groupe g = new GroupeNP(pere,name,min,max); + pere.addSousGroupe(g); + this.brain.put(Integer.valueOf(g.getId()),g); + } + + /** + * permet de créer une partition automatiquement sous un groupe donné. + * + * @param pere le groupe père du groupe à partitionner + * @param name le nom des groupe à créer (on ajoute à la suite un numéro de 1 à n pour distinguer chaque groupe formant la partition) + * @param n le nombre de partitions + * @throws java.lang.NullPointerException si un argument est null + * @throws java.lang.IllegalArgumentException si le groupe pere est de type PARTITION + * ou n négatif ou nul + * + * NB. doit créer une "copie" de pere + * sous pere de type Partition et ajouter sous ce groupe, n groupes de type "FREE". + * les valeurs min et max de ces n groupes sont + * min = 0 et + * max = partie entière de N/n plus 1, où N est le nombre max du groupe pere. + */ + public void createPartition(Groupe pere, String name, int n){ + Objects.requireNonNull(pere,"Le groupe pere ne peut pas être null"); + Objects.requireNonNull(name,"Le nouveau groupe ne peut pas avoir null comme nom"); + if (!this.knows(pere)){ + throw new IllegalArgumentException("Impossible de partitionner ce groupe inconnu"); + } + if (pere.getType().equals(TypeGroupe.PARTITION)){ + throw new IllegalArgumentException("Impossible de créer une partition à ce niveau. Il faut soit repartitionner le groupe au dessus, soit partitionner une partition en dessous."); + } + if ( n <= 0){ + throw new IllegalArgumentException("Le nombre de partitions doit être strictement positif"); + } + //Création de la racine de la partition. + Groupe copiePereRacinePartition = new GroupeNP(pere); + pere.addSousGroupe(copiePereRacinePartition); + this.brain.put(Integer.valueOf(copiePereRacinePartition.getId()),copiePereRacinePartition); + // 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 l'ensemble des étudiants connus de la factory ayant un nom "proche" de ce string au sens de la remarque ci-dessus. + * + * @throws java.lang.NullPointerException si le String est null. + */ + public Set getEtudiants(String nomEtu){ + // on cherche bêtement dans la promo. + Set out = new LinkedHashSet(); + for (Etudiant e : getPromotion().getEtudiants()){ + if (e.getNom().equals(nomEtu)){ + out.add(e); + break; + } + } + return out; + } + + /** + * permet de retrouver les groupes d'un étudiant. + * + * @param Etu un étudiant + * @return Etudiant l'étudiant connu de la factory ayant cet identifiant + * + * @throws java.lang.NullPointerException si le String est null. + */ + public Set getGroupesOfEtudiant(Etudiant etu){ + throw new UnsupportedOperationException("pas encore implanté"); + } + + +} diff --git a/src/fr/iutfbleau/projetIHM2022FI2/MNP/AbstractGroupeFactoryNP.java~ b/src/fr/iutfbleau/projetIHM2022FI2/MNP/AbstractGroupeFactoryNP.java~ new file mode 100644 index 0000000..c86a834 --- /dev/null +++ b/src/fr/iutfbleau/projetIHM2022FI2/MNP/AbstractGroupeFactoryNP.java~ @@ -0,0 +1,222 @@ +package fr.iutfbleau.projetIHM2022FI2.MNP; +import fr.iutfbleau.projetIHM2022FI2.API.*; +import java.util.*; +/** + * Usine abstraite gérant l'ensemble des groupes. + * + */ + +public class AbstractGroupeFactoryNP implements AbstractGroupeFactory { + + // la racine (promotion) + private Groupe promo; + + // On utilise une table de hachage pour retrouver facilement un groupe (à partir de son id). + // Si il y a beaucoup de groupes c'est plus rapide que de parcourir toute une liste. + private HashMap brain; + + + + + /** + * Le constructeur fabrique le groupe promotion vide. + * Il faut ensuite y ajouter les étudiants. + */ + public AbstractGroupeFactoryNP(String name, int min, int max){ + Objects.requireNonNull(name,"On ne peut pas créer une promotion dont le nom est null"); + this.promo=new GroupeNP(name,min,max); + 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. + */ + private Boolean knows(Groupe g){ + return this.brain.containsKey(Integer.valueOf(g.getId())); + } + + + + /** + * permet de récupérer le Groupe qui contient les étudiants de toute la promotion + * @return la promo. + */ + public Groupe getPromotion(){ + return this.promo; + } + + /** + * 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. + * + * @throws java.lang.NullPointerException si un argument est null + * @throws java.lang.IllegalStateException si le groupe contient des groupes + * @throws java.lang.IllegalArgumentException si le groupe n'est pas connu de l'usine abstraite ou bien si le groupe est celui de toute la promotion (renvoyé par getPromotion) + */ + public void deleteGroupe(Groupe g){ + Objects.requireNonNull(g,"On ne peut pas enlever un groupe null car null n'est pas un groupe autorisé"); + if (!this.knows(g)){ + throw new IllegalArgumentException("Impossible d'enlever un groupe inconnu"); + } + if (this.getPromotion().equals(g)){ + throw new IllegalArgumentException("Impossible de détruire le groupe de toute la promotion"); + } + if (g.getSize()>0){ + throw new IllegalStateException("Impossible de détruire un groupe contenant un groupe"); + } + g.getPointPoint().removeSousGroupe(g); + this.brain.remove(Integer.valueOf(g.getId())); + } + + /** + * permet d'ajouter un groupe vide de type FREE comme sous-groupe d'un groupe donné. + * @param pere le groupe père du groupe à créer + * @param name le nom du groupe à créer + * @param min,max bornes indicatives sur la taille du groupe à créer + * + * @throws java.lang.NullPointerException si un argument est null + * @throws java.lang.IllegalArgumentException si le groupe pere est de type PARTITION + * ou si il n'y a pas 0 < min <= max + */ + public void createGroupe(Groupe pere, String name, int min, int max){ + Objects.requireNonNull(pere,"Le groupe pere ne peut pas être null"); + Objects.requireNonNull(name,"Le nouveau groupe ne peut pas avoir null comme nom"); + if (!this.knows(pere)){ + throw new IllegalArgumentException("Interdit d'ajouter un fils à un groupe inconnu"); + } + if (pere.getType().equals(TypeGroupe.PARTITION)){ + throw new IllegalArgumentException("Impossible d'ajouter un groupe à une parition. Il faut utiliser createPartition pour créer une partition"); + } + if ( min <= 0 || max < min){ + throw new IllegalArgumentException("Il faut que 0 < min <= max"); + } + Groupe g = new GroupeNP(pere,name,min,max); + pere.addSousGroupe(g); + this.brain.put(Integer.valueOf(g.getId()),g); + } + + /** + * permet de créer une partition automatiquement sous un groupe donné. + * + * @param pere le groupe père du groupe à partitionner + * @param name le nom des groupe à créer (on ajoute à la suite un numéro de 1 à n pour distinguer chaque groupe formant la partition) + * @param n le nombre de partitions + * @throws java.lang.NullPointerException si un argument est null + * @throws java.lang.IllegalArgumentException si le groupe pere est de type PARTITION + * ou n négatif ou nul + * + * NB. doit créer une "copie" de pere + * sous pere de type Partition et ajouter sous ce groupe, n groupes de type "FREE". + * les valeurs min et max de ces n groupes sont + * min = 0 et + * max = partie entière de N/n plus 1, où N est le nombre max du groupe pere. + */ + public void createPartition(Groupe pere, String name, int n){ + Objects.requireNonNull(pere,"Le groupe pere ne peut pas être null"); + Objects.requireNonNull(name,"Le nouveau groupe ne peut pas avoir null comme nom"); + if (!this.knows(pere)){ + throw new IllegalArgumentException("Impossible de partitionner ce groupe inconnu"); + } + if (pere.getType().equals(TypeGroupe.PARTITION)){ + throw new IllegalArgumentException("Impossible de créer une partition à ce niveau. Il faut soit repartitionner le groupe au dessus, soit partitionner une partition en dessous."); + } + if ( n <= 0){ + throw new IllegalArgumentException("Le nombre de partitions doit être strictement positif"); + } + //Création de la racine de la partition. + Groupe copiePereRacinePartition = new GroupeNP(pere); + pere.addSousGroupe(copiePereRacinePartition); + this.brain.put(Integer.valueOf(copiePereRacinePartition.getId()),copiePereRacinePartition); + // création des sous-groupes + int min = 0; + int max = ((int) Math.floor(pere.getSize()/n))+1; + for(int i = 0; i l'ensemble des étudiants connus de la factory ayant un nom "proche" de ce string au sens de la remarque ci-dessus. + * + * @throws java.lang.NullPointerException si le String est null. + */ + public Set getEtudiants(String nomEtu){ + // on cherche bêtement dans la promo. + Set out = new LinkedHashSet(); + for (Etudiant e : getPromotion().getEtudiants()){ + if (e.getNom().equals(nomEtu)){ + out.add(e); + break; + } + } + return out; + } + + /** + * permet de retrouver les groupes d'un étudiant. + * + * @param Etu un étudiant + * @return Etudiant l'étudiant connu de la factory ayant cet identifiant + * + * @throws java.lang.NullPointerException si le String est null. + */ + public Set getGroupesOfEtudiant(Etudiant etu){ + throw new UnsupportedOperationException("pas encore implanté"); + } + + +} diff --git a/src/fr/iutfbleau/projetIHM2022FI2/MNP/ChangementNP.java b/src/fr/iutfbleau/projetIHM2022FI2/MNP/ChangementNP.java new file mode 100644 index 0000000..cb9f56f --- /dev/null +++ b/src/fr/iutfbleau/projetIHM2022FI2/MNP/ChangementNP.java @@ -0,0 +1,63 @@ +package fr.iutfbleau.projetIHM2022FI2.MNP; +import fr.iutfbleau.projetIHM2022FI2.API.*; +import java.util.*; +/** + * Une demande de changement de groupe + * concerne un étudiant, qui est dans un groupe A et veut aller dans un groupe B. + * + * Implémentation non persistante fournie avec l'API. + */ + +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; + + public ChangementNP(Groupe a, Etudiant e, Groupe b){ + 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"); + + this.id=++this.nextId; + this.a=a; + this.b=b; + this.e=e; + } + + /** + * permet de récupérer l'identifiant du changement (référence interne sans intérêt irl). + * @return l'identifiant. + */ + public int getId(){ + return this.id; + } + + /** + * permet de récupérer le groupe de depart + * @return ce groupe. + */ + public Groupe getA(){ + return this.a; + } + + /** + * permet de récupérer le groupe d'arrivée + * @return ce groupe. + */ + public Groupe getB(){ + return this.b; + } + + /** + * permet de récupérer l'étudiant demandant le changement + * @return cet étudiant + */ + public Etudiant getEtu(){ + return this.e; + } + +} diff --git a/src/fr/iutfbleau/projetIHM2022FI2/MNP/ChangementNP.java~ b/src/fr/iutfbleau/projetIHM2022FI2/MNP/ChangementNP.java~ new file mode 100644 index 0000000..ba98b21 --- /dev/null +++ b/src/fr/iutfbleau/projetIHM2022FI2/MNP/ChangementNP.java~ @@ -0,0 +1,60 @@ +package fr.iutfbleau.projetIHM2022FI2.MNP; +import fr.iutfbleau.projetIHM2022FI2.API.*; +import java.util.*; +/** + * Une demande de changement de groupe + * concerne un étudiant, qui est dans un groupe A et veut aller dans un groupe B. + * + * Implémentation non persistante fournie avec l'API. + */ + +public class ChangementNP implements Changement { + + private int id; + private Groupe a,b; + private Etudiant e; + + public ChangementNP(Groupe a, Etudiant e, Groupe b){ + 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.a=a; + this.b=b; + this.e=e; + } + + /** + * permet de récupérer l'identifiant du changement (référence interne sans intérêt irl). + * @return l'identifiant. + */ + public int getId(){ + return this.id; + } + + /** + * permet de récupérer le groupe de depart + * @return ce groupe. + */ + public Groupe getA(){ + return this.a; + } + + /** + * permet de récupérer le groupe d'arrivée + * @return ce groupe. + */ + public Groupe getB(){ + return this.a; + } + + /** + * permet de récupérer l'étudiant demandant le changement + * @return cet étudiant + */ + public Etudiant getEtu(){ + return this.e; + } + +} diff --git a/src/fr/iutfbleau/projetIHM2022FI2/MNP/EtudiantNP.java b/src/fr/iutfbleau/projetIHM2022FI2/MNP/EtudiantNP.java new file mode 100644 index 0000000..4d9df60 --- /dev/null +++ b/src/fr/iutfbleau/projetIHM2022FI2/MNP/EtudiantNP.java @@ -0,0 +1,51 @@ +package fr.iutfbleau.projetIHM2022FI2.MNP; +import fr.iutfbleau.projetIHM2022FI2.API.*; +import java.util.*; +/** + * Un étudiant + */ + +public class EtudiantNP implements Etudiant{ + + private static int nextId=0; + private int id; + private String nom, prenom; + + /** + * Constructeur. + */ + public EtudiantNP(String nom, String prenom){ + Objects.requireNonNull(nom,"On ne peut pas créer un étudiant avec un nom null"); + Objects.requireNonNull(prenom,"On ne peut pas créer un étudiant avec un nom null"); + // auto incrément de l'id + this.id=++this.nextId; + this.nom=nom; + this.prenom=prenom; + } + + /** + * permet de récupérer l'identifiant de l'étudiant. + * @return l'identifiant. + */ + public int getId(){ + return this.id; + } + + /** + * permet de récupérer + * @return le nom de l'étudiant. + */ + public String getNom(){ + return this.nom; + } + + /** + * permet de récupérer + * @return le prénom de l'étudiant + */ + public String getPrenom(){ + return this.prenom; + } + + +} diff --git a/src/fr/iutfbleau/projetIHM2022FI2/MNP/EtudiantNP.java~ b/src/fr/iutfbleau/projetIHM2022FI2/MNP/EtudiantNP.java~ new file mode 100644 index 0000000..2b6d0b9 --- /dev/null +++ b/src/fr/iutfbleau/projetIHM2022FI2/MNP/EtudiantNP.java~ @@ -0,0 +1,51 @@ +package fr.iutfbleau.projetIHM2022FI2.MNP; +import fr.iutfbleau.projetIHM2022FI2.API.*; +import java.util.*; +/** + * Un étudiant + */ + +public class EtudiantNP implements Etudiant{ + + private static nextId=0; + private int id; + private String nom, prenom; + + /** + * Constructeur. + */ + public EtudiantNP(String nom, String prenom){ + Objects.requireNonNull(nom,"On ne peut pas créer un étudiant avec un nom null"); + Objects.requireNonNull(prenom,"On ne peut pas créer un étudiant avec un nom null"); + // auto incrément de l'id + this.id=++this.nextId; + this.nom=nom; + this.prenom=prenom; + } + + /** + * permet de récupérer l'identifiant de l'étudiant. + * @return l'identifiant. + */ + public int getId(){ + return this.id; + } + + /** + * permet de récupérer + * @return le nom de l'étudiant. + */ + public String getNom(){ + return this.nom; + } + + /** + * permet de récupérer + * @return le prénom de l'étudiant + */ + public String getPrenom(){ + return this.prenom; + } + + +} diff --git a/src/fr/iutfbleau/projetIHM2022FI2/MNP/GroupeNP.java b/src/fr/iutfbleau/projetIHM2022FI2/MNP/GroupeNP.java new file mode 100644 index 0000000..cefd3c7 --- /dev/null +++ b/src/fr/iutfbleau/projetIHM2022FI2/MNP/GroupeNP.java @@ -0,0 +1,192 @@ +package fr.iutfbleau.projetIHM2022FI2.MNP; +import fr.iutfbleau.projetIHM2022FI2.API.*; +import java.util.*; +/** + * Un groupe + */ + +public class GroupeNP implements Groupe { + + //auto-incrément des groupes. (NB. inutile, mais ça fair un exemple d'attribut statique). + private static int nextId=0; + // attributs naturels induits par getter de l'interface Groupe + private int id; + private String name; + private int min,max; + private TypeGroupe type; + private Groupe pointPoint; + // On utilise une interface set pour les sous-groupes et pour les membres (ce sont bien des ensembles en pratique). + private Set sousGroupes; + private Set membresDuGroupe; + + /** + * Nouveau groupe vide de type ROOT sans étudiants, sans sous-Groupe + */ + public GroupeNP(String name, int min, int max){ + Objects.requireNonNull(name,"On ne peut pas créer un groupe dont le nom est null"); + this.id=++this.nextId; + this.name=name; + this.min=min; + this.max=max; + this.type=TypeGroupe.ROOT; + this.pointPoint=this; + this.sousGroupes=new LinkedHashSet(); + this.membresDuGroupe=new LinkedHashSet(); + } + + /** + * Nouveau groupe vide de type FREE sans étudiants, sans sous-Groupe + */ + public GroupeNP(Groupe pere, String name, int min, int max){ + Objects.requireNonNull(pere,"On ne peut pas créer un groupe dont le père est null"); + Objects.requireNonNull(name,"On ne peut pas créer un groupe dont le nom est null"); + this.id=++this.nextId; + this.name=name; + this.min=min; + this.max=max; + this.type=TypeGroupe.FREE; + this.pointPoint=pere; + this.sousGroupes=new LinkedHashSet(); + this.membresDuGroupe=new LinkedHashSet(); + } + + /** + * Nouveau groupe de type PARTITION dupliquant le groupe passé en paramètre (pour servir de racine à une partition de ce groupe de type FREE passé en paramètre). + * + */ + public GroupeNP(Groupe pere){ + Objects.requireNonNull(pere,"On ne peut pas créer un groupe dont le père est null"); + this.id=++this.nextId; + this.name=pere.getName()+"_PARTITION_"+ this.id; + this.min=pere.getMin(); + this.max=pere.getMax(); + this.type=TypeGroupe.PARTITION; + this.pointPoint=pere; + this.sousGroupes= new LinkedHashSet(); + this.membresDuGroupe= pere.getEtudiants(); + } + + /** + * Ajoute un étudiant. Se comporte comme add de l'interface Set. + * + * @return true iff e est ajouté + */ + public boolean addEtudiant(Etudiant e){ + Objects.requireNonNull(e,"On ne peut pas ajouter un Étudiant qui est null"); + return this.membresDuGroupe.add(e); + } + + /** + * Enlève un étudiant. Se comporte comme remove de l'interface Set. + * + * @return true iff e est enlevé + */ + public boolean removeEtudiant(Etudiant e){ + Objects.requireNonNull(e,"On ne peut pas enlever un Étudiant qui est null"); + return this.membresDuGroupe.remove(e); + } + + /** + * Ajoute un sous-groupe. Se comporte comme add de l'interface Set. + * vérifie que le groupe passé en argument a bien renseigné this comme son père. + * + * @return true iff g est ajouté + */ + public boolean addSousGroupe(Groupe g){ + Objects.requireNonNull(g,"On ne peut pas ajouter un sous-groupe qui est null"); + if (this.equals(g.getPointPoint())) + return this.sousGroupes.add(g); + else throw new IllegalArgumentException("on ne peut pas ajouter un sous-groupe ont le père n'est pas this"); + } + + /** + * Enlève un groupe. Se comporte comme remove de l'interface Set. + * + * @return true iff e est enlevé + */ + public boolean removeSousGroupe(Groupe g){ + Objects.requireNonNull(g,"On ne peut pas enlever un Étudiant qui est null"); + return this.sousGroupes.remove(g); + } + + + /** + * permet de récupérer l'identifiant d'un groupe (référence interne sans intérêt irl). + * @return l'identifiant. + */ + public int getId(){ + return this.id; + } + + /** + * permet de récupérer le nom d'un groupe (utile irl). + * @return le nom. + */ + public String getName(){ + return this.name; + } + + /** + * permet de récupérer le nombre minimum d'étudiants souhaités dans le groupe. + * @return le minimum souhaité + */ + public int getMin(){ + return this.min; + } + + /** + * permet de récupérer le nombre maximum d'étudiants souhaités dans un groupe. + * @return le maximum souhaité + */ + public int getMax(){ + return this.max; + } + + /** + * permet de récupérer le nombre d'étudiants dans ce groupe. + * @return le nombre de places prises (pas forcément limité entre Min et Max, mais c'est le but) + */ + public int getSize(){ + return this.membresDuGroupe.size(); + } + + /** + * permet de récupérer la nature du groupe + * @return le type du groupe + */ + public TypeGroupe getType(){ + return type; + } + + /** + * permet de récupérer le groupe père + * un groupe racine devrait retourner lui-même + * + * @return le père + */ + public Groupe getPointPoint(){ + return this.pointPoint; + } + + /** + * Potentiellement "vide" + * Attention nous renvoyons l'ensemble sans le copier + * + * @return l'ensemble des sous-groupes. + */ + public Set getSousGroupes(){ + return this.sousGroupes; + } + + /** + * Potentiellement "vide" + * Attention nous renvoyons l'ensemble sans le copier + * + * @return l'ensemble des étudiants. + */ + public Set getEtudiants(){ + return this.membresDuGroupe; + } + + +} diff --git a/src/fr/iutfbleau/projetIHM2022FI2/MNP/GroupeNP.java~ b/src/fr/iutfbleau/projetIHM2022FI2/MNP/GroupeNP.java~ new file mode 100644 index 0000000..e34daba --- /dev/null +++ b/src/fr/iutfbleau/projetIHM2022FI2/MNP/GroupeNP.java~ @@ -0,0 +1,199 @@ +package fr.iutfbleau.projetIHM2022FI2.MNP; +import fr.iutfbleau.projetIHM2022FI2.API.*; +import java.util.*; +/** + * Un groupe + */ + +public class GroupeNP extends Groupe { + + //auto-incrément des groupes. (NB. inutile, mais ça fair un exemple d'attribut statique). + private static nextId=0; + // attributs naturels induits par getter de l'interface Groupe + private int id; + private String name; + private int min,max; + private TypeGroupe type; + private Groupe pointPoint; + // On utilise une interface set pour les sous-groupes et pour les membres (ce sont bien des ensembles en pratique). + private Set sousGroupes; + private Set membresDuGroupe; + + // les méthodes de l'interface groupe sont en fin de fichier. + // On commence par les get/set additionnels, puis les constructeurs. + + /** + * Réfléchir à donner droit dans paquet. + * @return le set des étudiants (attention ce n'est pas une copie, tout changement impacte le groupe). + */ + public Set getSetEtudiants(){ + return this.membresDuGroupe; + } + + /** + * Ajoute un étudiant. Se comporte comme add de l'interface Set. + * + * @return true iff e est ajouté + */ + package boolean addEtudiant(Etudiant e){ + Objects.requireNonNull(e,"On ne peut pas ajouter un Étudiant qui est null"); + return this.membresDuGroupe.add(e); + } + + /** + * Enlève un étudiant. Se comporte comme remove de l'interface Set. + * + * @return true iff e est enlevé + */ + package boolean removeEtudiant(Etudiant e){ + Objects.requireNonNull(e,"On ne peut pas enlever un Étudiant qui est null"); + return this.membresDuGroupe.remove(e); + } + + /** + * Ajoute un sous-groupe. Se comporte comme add de l'interface Set. + * vérifie que le groupe passé en argument a bien renseigné this comme son père. + * + * @return true iff g est ajouté + */ + package boolean addSousGroupe(Groupe g){ + Objects.requireNonNull(g,"On ne peut pas ajouter un sous-groupe qui est null"); + if (this.equals(g.getpointPoint())) + return this.sousGroupes.add(g); + else throw new IllegalArgumentException("on ne peut pas ajouter un sous-groupe ont le père n'est pas this"); + } + + /** + * Enlève un groupe. Se comporte comme remove de l'interface Set. + * + * @return true iff e est enlevé + */ + package boolean removeSousGroupe(Groupe g){ + Objects.requireNonNull(e,"On ne peut pas enlever un Étudiant qui est null"); + return this.souGroupes.remove(g); + } + + + /** + * Nouveau groupe vide de type PROMOTION sans étudiants, sans sous-Groupe + */ + public GroupeNP(String name, int min, int max){ + Objects.requireNonNull(name,"On ne peut pas créer un groupe dont le nom est null"); + this.id=++this.nextId; + this.name=name; + this.min=min; + this.max=max; + this.type=TypeGroupe.FREE; + this.pointPoint=this; + this.sousGroupes=new LinkedHashSet(); + this.membresDugroupe=new LinkedHashSet(); + } + + /** + * Nouveau groupe vide de type FREE sans étudiants, sans sous-Groupe + */ + public GroupeNP(Groupe pere, String name, int min, int max){ + Objects.requireNonNull(pere,"On ne peut pas créer un groupe dont le père est null"); + Objects.requireNonNull(name,"On ne peut pas créer un groupe dont le nom est null"); + this.id=++this.nextId; + this.name=name; + this.min=min; + this.max=max; + this.type=TypeGroupe.FREE; + this.pointPoint=pere; + this.sousGroupes=new LinkedHashSet(); + this.membresDugroupe=new LinkedHashSet(); + } + + /** + * Nouveau groupe de type PARTITION dupliquant le groupe passé en paramètre (pour servir de racine à une partition de ce groupe de type FREE passé en paramètre). + * + */ + public GroupeNP(Groupe pere){ + Objects.requireNonNull(pere,"On ne peut pas créer un groupe dont le père est null"); + this.id=++this.nextId; + this.name=pere.getName()+"_PARTITION_"+ this.id; + this.min=pere.getMin(); + this.max=pere.getMax(); + this.type=TypeGroupe.PARTITION; + this.pointPoint=pere; + this.sousGroupes= new LinkedHashSet(); + this.membresDugroupe= this.pere.getSetEtudiants(); + } + + /** + * permet de récupérer l'identifiant d'un groupe (référence interne sans intérêt irl). + * @return l'identifiant. + */ + public int getId(){ + return this.id; + } + + /** + * permet de récupérer le nom d'un groupe (utile irl). + * @return le nom. + */ + public String getName(){ + return this.name; + } + + /** + * permet de récupérer le nombre minimum d'étudiants souhaités dans le groupe. + * @return le minimum souhaité + */ + public int getMin(){ + return this.min; + } + + /** + * permet de récupérer le nombre maximum d'étudiants souhaités dans un groupe. + * @return le maximum souhaité + */ + public int getMax(){ + return this.max; + } + + /** + * permet de récupérer le nombre d'étudiants dans ce groupe. + * @return le nombre de places prises (pas forcément limité entre Min et Max, mais c'est le but) + */ + public int getSize(){ + return this.membresDuGroupe.size(); + } + + /** + * permet de récupérer la nature du groupe + * @return le type du groupe + */ + public TypeGroupe getType(){ + return type; + } + + /** + * permet de récupérer le groupe père + * un groupe racine devrait retourner lui-même + * + * @return le père + */ + public Groupe getPointPoint(){ + return this.pointPoint; + } + + /** + * Potentiellement "vide" + * @return un itérateur sur sous-groupes. + */ + public Iterator getSousGroupes(){ + return this.sousGroupes.iterator(); + } + + /** + * Potentiellement "vide" + * @return un itérateur sur les étudiants. + */ + public Iterator getEtudiants(){ + return this.membresDuGroupe.iterator(); + } + + +} diff --git a/src/fr/iutfbleau/projetIHM2022FI2/MNP/ReservationFactoryNP.java~ b/src/fr/iutfbleau/projetIHM2022FI2/MNP/ReservationFactoryNP.java~ new file mode 100644 index 0000000..a4a4d99 --- /dev/null +++ b/src/fr/iutfbleau/projetIHM2022FI2/MNP/ReservationFactoryNP.java~ @@ -0,0 +1,164 @@ +package fr.iutfbleau.projetIHM2021FI2.MNP; +import fr.iutfbleau.projetIHM2021FI2.API.*; +import java.time.LocalDate; +import java.util.*; +import java.util.function.Predicate; +/** + * Usine non persistante stockant les réservations dans une structure de données permettant de simuler un ensemble. + * + * + */ +public interface ReservationFactory{ + + /** + * Recherche une chambre adéquate à partir de + * @param p une préréservation + * @return la chambre + * @throws NullPointerException si un argument est null + * @throws IllegalStateException si une chambre correspondant à cette Préréservation n'existe pas. + * + * Ne devrait pas retourner un objet null. + */ + public Chambre getChambre(Prereservation p); + + /** + * Recherche toutes les chambres adéquates à partir de + * @param p une préréservation + * @return les chambres (set de chambre) + * @throws NullPointerException si un argument est null + * @throws IllegalStateException si une chambre correspondant à cette Préréservation n'existe pas. + * + * Ne devrait pas retourner un objet null. + */ + public Set getChambres(Prereservation p); + + /** + * Fabrique (ajoute) une réservation + * @param p une préréservation + * @param c une chambre (normalement libre et adaptée à la préréservation) + * @return la réservation + * @throws NullPointerException si un argument est null + * @throws IllegalArgumentException si la chambre ne correspondant pas au type de chambre de la préréservation. + * @throws IllegalStateException si la chambre n'est pas disponible. + * + * Ne devrait pas retourner un objet null. + */ + public Reservation createReservation(Prereservation p, Chambre c); + + /** + * Cherche les réservations + * @param d une date + * @return la ou les réservation(s) à cette date sous forme d'un ensemble + * @throws NullPointerException si un argument est null + * + * Ne devrait pas retourner un objet null, par contre peut être un ensemble qui est vide. + */ + public Set getReservation(LocalDate d); + + /** + * Cherche le nombre de chambres disponibles pour une date (réservées ou non). + * @param d une date + * @return un entier + * @throws NullPointerException si un argument est null + * + * Ne devrait pas retourner un entier négatif. + */ + public int getDisponibles(LocalDate d); + + /** + * Cherche les réservations + * @param d une date + * @param t un type de chambre + * @return la ou les réservation(s) pour ce type de chambre à cette date sous forme d'un ensemble + * @throws NullPointerException si un argument est null + * + * Ne devrait pas retourner un objet null, par contre peut être un ensemble qui est vide. + */ + public Set getReservation(LocalDate d, TypeChambre t); + + /** + * Cherche le nombre de chambres disponibles d'un certain type pour une date (réservées ou non). + * @param d une date + * @param t un type de chambre + * @return un entier + * @throws NullPointerException si un argument est null + * + * Ne devrait pas retourner un entier négatif. + */ + public int getDisponibles(LocalDate d, TypeChambre t); + + /** + * Cherche la proportion de chambres disponibles pour une date (réservées sur réservables). + * @param d une date + * @return un entier entre 0 et 100 + * @throws NullPointerException si un argument est null + */ + public int getRatio(LocalDate d); + + /** + * Cherche la proportion de chambres disponibles d'un certain type pour une date (réservées sur réservables). + * @param d une date + * @param t un type de chambre + * @return un entier entre 0 et 100 + * @throws NullPointerException si un argument est null + */ + public int getRatio(LocalDate d, TypeChambre t); + + /** + * Cherche le nombre moyen de chambres disponibles entre deux date (réservées ou non), arrondies à l'entier inférieur. + * @param d1 une date + * @param d2 une date + * @return un entier + * @throws NullPointerException si un argument est null + * @throws IllegalArgumentException si l'ordre temporel d1 avant d2 n'est pas respecté. + * + * Ne devrait pas retourner un entier négatif. + */ + public int getDisponibles(LocalDate d1, LocalDate d2); + + /** + * Cherche les réservations + * @param d1 une date + * @param d2 une date + * @param t un type de chambre + * @return la ou les réservation(s) pour ce type de chambre entre les dates sous forme d'un ensemble + * @throws NullPointerException si un argument est null + * @throws IllegalArgumentException si l'ordre temporel d1 avant d2 n'est pas respecté. + * + * Ne devrait pas retourner un objet null, par contre peut être un ensemble qui est vide. + */ + public Set getReservation(LocalDate d1, LocalDate d2, TypeChambre t); + + /** + * Cherche le nombre moyen de chambres disponibles d'un certain type entre deux date (réservées ou non), arrondies à l'entier inférieur. + * @param d1 une date + * @param d2 une date + * @param t un type de chambre + * @return un entier + * @throws NullPointerException si un argument est null + * @throws IllegalArgumentException si l'ordre temporel d1 avant d2 n'est pas respecté. + * + * Ne devrait pas retourner un entier négatif. + */ + public int getDisponibles(LocalDate d1, LocalDate d2, TypeChambre t); + + /** + * Cherche la proportion moyenne de chambres disponibles pour une date (réservées sur réservables). + * @param d1 une date + * @param d2 une date + * @return un entier entre 0 et 100 + * @throws NullPointerException si un argument est null + */ + public int getRatio(LocalDate d1, LocalDate d2); + + /** + * Cherche la proportion moyenne de chambres disponibles d'un certain type pour une date (réservées sur réservables). + * @param d1 une date + * @param d2 une date + * @param t un type de chambre + * @return un entier entre 0 et 100 + * @throws NullPointerException si un argument est null + */ + public int getRatio(LocalDate d1, LocalDate d2, TypeChambre t); + +} diff --git a/src/fr/iutfbleau/projetIHM2022FI2/Test/TestTexteMNP.java b/src/fr/iutfbleau/projetIHM2022FI2/Test/TestTexteMNP.java new file mode 100644 index 0000000..15f8436 --- /dev/null +++ b/src/fr/iutfbleau/projetIHM2022FI2/Test/TestTexteMNP.java @@ -0,0 +1,236 @@ +package fr.iutfbleau.projetIHM2022FI2.Test; +import fr.iutfbleau.projetIHM2022FI2.API.*; +import fr.iutfbleau.projetIHM2022FI2.MNP.*; +import java.util.*; +//import java.util.Random; + +public class TestTexteMNP{ + + + public static void main(String[] args) { + // morceaux de modèle + + // Notez que à gauche d'une déclaration on utilise une interface et à droite une version concrète. + // Il faut que votre vue se calque sur le fonctionnemment de ce main et ne fasse pas d'hypothèse sur l'implémentation concrète de l'interface. + // i.e. entre les versions non persistantes (qui terminent par NP) et votre implémentation éventuelle persistante, le seul changement de comportement devrait être la persistance. + // + + System.out.println("Test de l\'API"); + System.out.print("Création des étudiants"); + + Etudiant e1=new EtudiantNP("césar","lycurgus"); + Etudiant e2=new EtudiantNP("denis","uranus"); + Etudiant e3=new EtudiantNP("marcel","castor"); + Etudiant e4=new EtudiantNP("marin","eurydice"); + Etudiant e5=new EtudiantNP("constantin","akoni"); + Etudiant e6=new EtudiantNP("donat","anakoni"); + Etudiant e7=new EtudiantNP("alexandre","apikalia"); + Etudiant e8=new EtudiantNP("andré","ekewaka"); + Etudiant e9=new EtudiantNP("renard","elikapeka"); + Etudiant e10=new EtudiantNP("achille","haukea"); + + System.out.print("."); + + Etudiant e11=new EtudiantNP("agathe","iakopa"); + Etudiant e12=new EtudiantNP("sabine","spartacus"); + Etudiant e13=new EtudiantNP("michel","caligula"); + Etudiant e14=new EtudiantNP("marthe","alaric"); + Etudiant e15=new EtudiantNP("juliane","hannibal"); + Etudiant e16=new EtudiantNP("anne","juvenal"); + Etudiant e17=new EtudiantNP("sophie","bede"); + Etudiant e18=new EtudiantNP("louis","hamilcar"); + Etudiant e19=new EtudiantNP("diane","ladislas"); + Etudiant e20=new EtudiantNP("christine","mahatma"); + + System.out.print("."); + + Etudiant e21=new EtudiantNP("francine","napoleon"); + Etudiant e22=new EtudiantNP("louise","lalita"); + Etudiant e23=new EtudiantNP("chantal","laxman"); + Etudiant e24=new EtudiantNP("giselle","laxmi"); + Etudiant e25=new EtudiantNP("caroline","leela"); + Etudiant e26=new EtudiantNP("claude","lila"); + Etudiant e27=new EtudiantNP("pauline","lilavati"); + Etudiant e28=new EtudiantNP("avril","lochan"); + Etudiant e29=new EtudiantNP("jacqueline","madhav"); + Etudiant e30=new EtudiantNP("denise","turlough"); + + System.out.print("."); + + Etudiant e31=new EtudiantNP("gabrielle","uaithne"); + Etudiant e32=new EtudiantNP("julie","uilleag"); + Etudiant e33=new EtudiantNP("madeleine","uilliam"); + Etudiant e34=new EtudiantNP("charlotte","uinseann"); + Etudiant e35=new EtudiantNP("bertrand","ulick"); + Etudiant e36=new EtudiantNP("lucile","ultan"); + Etudiant e37=new EtudiantNP("nicole","firdaus"); + Etudiant e38=new EtudiantNP("blanche","yasmin"); + Etudiant e39=new EtudiantNP("jeanine","javed"); + Etudiant e40=new EtudiantNP("roxane","naveed"); + + System.out.print("."); + + Etudiant e41=new EtudiantNP("adeline","shahnaz"); + Etudiant e42=new EtudiantNP("dion","ardashir"); + Etudiant e43=new EtudiantNP("liane","atefeh"); + Etudiant e44=new EtudiantNP("myriam","luigina"); + Etudiant e45=new EtudiantNP("danielle","luigino"); + Etudiant e46=new EtudiantNP("arlette","maddalena"); + Etudiant e47=new EtudiantNP("michelle","manfredo"); + Etudiant e48=new EtudiantNP("justine","manlio"); + Etudiant e49=new EtudiantNP("natalie","marcellino"); + Etudiant e50=new EtudiantNP("aline","mariangela"); + + System.out.print("."); + + Etudiant e51=new EtudiantNP("prosper","marzio"); + Etudiant e52=new EtudiantNP("mirabelle","massimiliano"); + Etudiant e53=new EtudiantNP("carine","matteo"); + Etudiant e54=new EtudiantNP("jeannine","melchiorre"); + Etudiant e55=new EtudiantNP("dianne","micaela"); + Etudiant e56=new EtudiantNP("evette","michela"); + Etudiant e57=new EtudiantNP("gisselle","michelangela"); + + System.out.println("terminé."); + + System.out.print("Création de l\'usine à groupe"); + 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); + agf.addToGroupe(agf.getPromotion(),e2); + agf.addToGroupe(agf.getPromotion(),e3); + agf.addToGroupe(agf.getPromotion(),e4); + agf.addToGroupe(agf.getPromotion(),e5); + agf.addToGroupe(agf.getPromotion(),e6); + agf.addToGroupe(agf.getPromotion(),e7); + agf.addToGroupe(agf.getPromotion(),e8); + agf.addToGroupe(agf.getPromotion(),e9); + agf.addToGroupe(agf.getPromotion(),e10); + + System.out.print("."); + + agf.addToGroupe(agf.getPromotion(),e11); + agf.addToGroupe(agf.getPromotion(),e12); + agf.addToGroupe(agf.getPromotion(),e13); + agf.addToGroupe(agf.getPromotion(),e14); + agf.addToGroupe(agf.getPromotion(),e15); + agf.addToGroupe(agf.getPromotion(),e16); + agf.addToGroupe(agf.getPromotion(),e17); + agf.addToGroupe(agf.getPromotion(),e18); + agf.addToGroupe(agf.getPromotion(),e19); + agf.addToGroupe(agf.getPromotion(),e20); + + System.out.print("."); + + agf.addToGroupe(agf.getPromotion(),e21); + agf.addToGroupe(agf.getPromotion(),e22); + agf.addToGroupe(agf.getPromotion(),e23); + agf.addToGroupe(agf.getPromotion(),e24); + agf.addToGroupe(agf.getPromotion(),e25); + agf.addToGroupe(agf.getPromotion(),e26); + agf.addToGroupe(agf.getPromotion(),e27); + agf.addToGroupe(agf.getPromotion(),e28); + agf.addToGroupe(agf.getPromotion(),e29); + agf.addToGroupe(agf.getPromotion(),e30); + agf.addToGroupe(agf.getPromotion(),e31); + agf.addToGroupe(agf.getPromotion(),e32); + agf.addToGroupe(agf.getPromotion(),e33); + agf.addToGroupe(agf.getPromotion(),e34); + agf.addToGroupe(agf.getPromotion(),e35); + agf.addToGroupe(agf.getPromotion(),e36); + agf.addToGroupe(agf.getPromotion(),e37); + agf.addToGroupe(agf.getPromotion(),e38); + agf.addToGroupe(agf.getPromotion(),e39); + + System.out.print("."); + + agf.addToGroupe(agf.getPromotion(),e40); + agf.addToGroupe(agf.getPromotion(),e41); + agf.addToGroupe(agf.getPromotion(),e42); + agf.addToGroupe(agf.getPromotion(),e43); + agf.addToGroupe(agf.getPromotion(),e44); + agf.addToGroupe(agf.getPromotion(),e45); + agf.addToGroupe(agf.getPromotion(),e46); + agf.addToGroupe(agf.getPromotion(),e47); + agf.addToGroupe(agf.getPromotion(),e48); + agf.addToGroupe(agf.getPromotion(),e49); + agf.addToGroupe(agf.getPromotion(),e50); + agf.addToGroupe(agf.getPromotion(),e51); + agf.addToGroupe(agf.getPromotion(),e52); + agf.addToGroupe(agf.getPromotion(),e53); + agf.addToGroupe(agf.getPromotion(),e54); + agf.addToGroupe(agf.getPromotion(),e55); + agf.addToGroupe(agf.getPromotion(),e56); + agf.addToGroupe(agf.getPromotion(),e57); + System.out.println("terminé."); + + System.out.println("Initialisation complète."); + + System.out.println("=========================="); + System.out.println("Le groupe promotion"); + System.out.println(agf.getPromotion().monPrint()); + + System.out.println("=========================="); + System.out.println("Partition du groupe racine en 3 groupes TD."); + 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 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()); + } + } + + +} diff --git a/src/fr/iutfbleau/projetIHM2022FI2/Test/TestTexteMNP.java~ b/src/fr/iutfbleau/projetIHM2022FI2/Test/TestTexteMNP.java~ new file mode 100644 index 0000000..d48a176 --- /dev/null +++ b/src/fr/iutfbleau/projetIHM2022FI2/Test/TestTexteMNP.java~ @@ -0,0 +1,218 @@ +package fr.iutfbleau.projetIHM2022FI2.Test; +import fr.iutfbleau.projetIHM2022FI2.API.*; +import fr.iutfbleau.projetIHM2022FI2.MNP.*; +import java.util.*; +//import java.util.Random; + +public class TestTexteMNP{ + + + public static void main(String[] args) { + // morceaux de modèle + + // Notez que à gauche d'une déclaration on utilise une interface et à droite une version concrète. + // Il faut que votre vue se calque sur le fonctionnemment de ce main et ne fasse pas d'hypothèse sur l'implémentation concrète de l'interface. + // i.e. entre les versions non persistantes (qui terminent par NP) et votre implémentation éventuelle persistante, le seul changement de comportement devrait être la persistance. + // + + System.out.println("Test de l\'API"); + System.out.print("Création des étudiants"); + + Etudiant e1=new EtudiantNP("césar","lycurgus"); + Etudiant e2=new EtudiantNP("denis","uranus"); + Etudiant e3=new EtudiantNP("marcel","castor"); + Etudiant e4=new EtudiantNP("marin","eurydice"); + Etudiant e5=new EtudiantNP("constantin","akoni"); + Etudiant e6=new EtudiantNP("donat","anakoni"); + Etudiant e7=new EtudiantNP("alexandre","apikalia"); + Etudiant e8=new EtudiantNP("andré","ekewaka"); + Etudiant e9=new EtudiantNP("renard","elikapeka"); + Etudiant e10=new EtudiantNP("achille","haukea"); + + System.out.print("."); + + Etudiant e11=new EtudiantNP("agathe","iakopa"); + Etudiant e12=new EtudiantNP("sabine","spartacus"); + Etudiant e13=new EtudiantNP("michel","caligula"); + Etudiant e14=new EtudiantNP("marthe","alaric"); + Etudiant e15=new EtudiantNP("juliane","hannibal"); + Etudiant e16=new EtudiantNP("anne","juvenal"); + Etudiant e17=new EtudiantNP("sophie","bede"); + Etudiant e18=new EtudiantNP("louis","hamilcar"); + Etudiant e19=new EtudiantNP("diane","ladislas"); + Etudiant e20=new EtudiantNP("christine","mahatma"); + + System.out.print("."); + + Etudiant e21=new EtudiantNP("francine","napoleon"); + Etudiant e22=new EtudiantNP("louise","lalita"); + Etudiant e23=new EtudiantNP("chantal","laxman"); + Etudiant e24=new EtudiantNP("giselle","laxmi"); + Etudiant e25=new EtudiantNP("caroline","leela"); + Etudiant e26=new EtudiantNP("claude","lila"); + Etudiant e27=new EtudiantNP("pauline","lilavati"); + Etudiant e28=new EtudiantNP("avril","lochan"); + Etudiant e29=new EtudiantNP("jacqueline","madhav"); + Etudiant e30=new EtudiantNP("denise","turlough"); + + System.out.print("."); + + Etudiant e31=new EtudiantNP("gabrielle","uaithne"); + Etudiant e32=new EtudiantNP("julie","uilleag"); + Etudiant e33=new EtudiantNP("madeleine","uilliam"); + Etudiant e34=new EtudiantNP("charlotte","uinseann"); + Etudiant e35=new EtudiantNP("bertrand","ulick"); + Etudiant e36=new EtudiantNP("lucile","ultan"); + Etudiant e37=new EtudiantNP("nicole","firdaus"); + Etudiant e38=new EtudiantNP("blanche","yasmin"); + Etudiant e39=new EtudiantNP("jeanine","javed"); + Etudiant e40=new EtudiantNP("roxane","naveed"); + + System.out.print("."); + + Etudiant e41=new EtudiantNP("adeline","shahnaz"); + Etudiant e42=new EtudiantNP("dion","ardashir"); + Etudiant e43=new EtudiantNP("liane","atefeh"); + Etudiant e44=new EtudiantNP("myriam","luigina"); + Etudiant e45=new EtudiantNP("danielle","luigino"); + Etudiant e46=new EtudiantNP("arlette","maddalena"); + Etudiant e47=new EtudiantNP("michelle","manfredo"); + Etudiant e48=new EtudiantNP("justine","manlio"); + Etudiant e49=new EtudiantNP("natalie","marcellino"); + Etudiant e50=new EtudiantNP("aline","mariangela"); + + System.out.print("."); + + Etudiant e51=new EtudiantNP("prosper","marzio"); + Etudiant e52=new EtudiantNP("mirabelle","massimiliano"); + Etudiant e53=new EtudiantNP("carine","matteo"); + Etudiant e54=new EtudiantNP("jeannine","melchiorre"); + Etudiant e55=new EtudiantNP("dianne","micaela"); + Etudiant e56=new EtudiantNP("evette","michela"); + Etudiant e57=new EtudiantNP("gisselle","michelangela"); + + System.out.println("terminé."); + + System.out.print("Création de l\'usine à groupe"); + 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); + agf.addToGroupe(agf.getPromotion(),e2); + agf.addToGroupe(agf.getPromotion(),e3); + agf.addToGroupe(agf.getPromotion(),e4); + agf.addToGroupe(agf.getPromotion(),e5); + agf.addToGroupe(agf.getPromotion(),e6); + agf.addToGroupe(agf.getPromotion(),e7); + agf.addToGroupe(agf.getPromotion(),e8); + agf.addToGroupe(agf.getPromotion(),e9); + agf.addToGroupe(agf.getPromotion(),e10); + + System.out.print("."); + + agf.addToGroupe(agf.getPromotion(),e11); + agf.addToGroupe(agf.getPromotion(),e12); + agf.addToGroupe(agf.getPromotion(),e13); + agf.addToGroupe(agf.getPromotion(),e14); + agf.addToGroupe(agf.getPromotion(),e15); + agf.addToGroupe(agf.getPromotion(),e16); + agf.addToGroupe(agf.getPromotion(),e17); + agf.addToGroupe(agf.getPromotion(),e18); + agf.addToGroupe(agf.getPromotion(),e19); + agf.addToGroupe(agf.getPromotion(),e20); + + System.out.print("."); + + agf.addToGroupe(agf.getPromotion(),e21); + agf.addToGroupe(agf.getPromotion(),e22); + agf.addToGroupe(agf.getPromotion(),e23); + agf.addToGroupe(agf.getPromotion(),e24); + agf.addToGroupe(agf.getPromotion(),e25); + agf.addToGroupe(agf.getPromotion(),e26); + agf.addToGroupe(agf.getPromotion(),e27); + agf.addToGroupe(agf.getPromotion(),e28); + agf.addToGroupe(agf.getPromotion(),e29); + agf.addToGroupe(agf.getPromotion(),e30); + agf.addToGroupe(agf.getPromotion(),e31); + agf.addToGroupe(agf.getPromotion(),e32); + agf.addToGroupe(agf.getPromotion(),e33); + agf.addToGroupe(agf.getPromotion(),e34); + agf.addToGroupe(agf.getPromotion(),e35); + agf.addToGroupe(agf.getPromotion(),e36); + agf.addToGroupe(agf.getPromotion(),e37); + agf.addToGroupe(agf.getPromotion(),e38); + agf.addToGroupe(agf.getPromotion(),e39); + + System.out.print("."); + + agf.addToGroupe(agf.getPromotion(),e40); + agf.addToGroupe(agf.getPromotion(),e41); + agf.addToGroupe(agf.getPromotion(),e42); + agf.addToGroupe(agf.getPromotion(),e43); + agf.addToGroupe(agf.getPromotion(),e44); + agf.addToGroupe(agf.getPromotion(),e45); + agf.addToGroupe(agf.getPromotion(),e46); + agf.addToGroupe(agf.getPromotion(),e47); + agf.addToGroupe(agf.getPromotion(),e48); + agf.addToGroupe(agf.getPromotion(),e49); + agf.addToGroupe(agf.getPromotion(),e50); + agf.addToGroupe(agf.getPromotion(),e51); + agf.addToGroupe(agf.getPromotion(),e52); + agf.addToGroupe(agf.getPromotion(),e53); + agf.addToGroupe(agf.getPromotion(),e54); + agf.addToGroupe(agf.getPromotion(),e55); + agf.addToGroupe(agf.getPromotion(),e56); + agf.addToGroupe(agf.getPromotion(),e57); + System.out.println("terminé."); + + System.out.println("Initialisation complète."); + + System.out.println("=========================="); + System.out.println("Le groupe promotion"); + System.out.println(agf.getPromotion().monPrint()); + + System.out.println("=========================="); + System.out.println("Partition du groupe racine en 3 groupes TD."); + 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 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 + System.out.println("== debug =="); + System.out.println(A.getName()); + System.out.println(B.getName()); + 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()); + } + } + + +}