From c5ee1e64959f598c8649b6d8b57d02e982eb1423 Mon Sep 17 00:00:00 2001 From: Florent Madelaine Date: Thu, 7 Oct 2021 03:24:15 +0200 Subject: [PATCH] =?UTF-8?q?MNP=20pour=20les=20pr=C3=A9r=C3=A9servation,=20?= =?UTF-8?q?test=20simple=20et=20documentation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 53 ++++++---- README.md | 13 ++- .../projetIHM2021FI2/API/Chambre.java | 26 ++++- .../projetIHM2021FI2/API/Client.java | 9 +- .../projetIHM2021FI2/API/MonPrint.java | 12 +++ .../projetIHM2021FI2/API/Prereservation.java | 16 ++- .../projetIHM2021FI2/API/TypeChambre.java | 8 +- .../projetIHM2021FI2/MNP/ChambreNP.java | 76 +++++++++++++++ .../projetIHM2021FI2/MNP/ClientNP.java | 11 ++- .../MNP/PrereservationFactoryNP.java | 97 +++++++++++++++++++ .../MNP/PrereservationNP.java | 88 +++++++++++++++++ .../projetIHM2021FI2/MNP/ReservationNP.java | 87 +++++++++++++++++ .../projetIHM2021FI2/Test/TestTexteMNP.java | 90 +++++++++++++++++ 13 files changed, 559 insertions(+), 27 deletions(-) create mode 100644 src/fr/iutfbleau/projetIHM2021FI2/API/MonPrint.java create mode 100644 src/fr/iutfbleau/projetIHM2021FI2/MNP/ChambreNP.java create mode 100644 src/fr/iutfbleau/projetIHM2021FI2/MNP/PrereservationFactoryNP.java create mode 100644 src/fr/iutfbleau/projetIHM2021FI2/MNP/PrereservationNP.java create mode 100644 src/fr/iutfbleau/projetIHM2021FI2/MNP/ReservationNP.java create mode 100644 src/fr/iutfbleau/projetIHM2021FI2/Test/TestTexteMNP.java diff --git a/Makefile b/Makefile index 006f17d..aefd043 100644 --- a/Makefile +++ b/Makefile @@ -9,20 +9,22 @@ EXEC_JAR = ${JAVA} -jar # CHEMINS RELATIFS SRC = src/fr/iutfbleau/projetIHM2021FI2 BUILD = build/fr/iutfbleau/projetIHM2021FI2 +DOC = doc/fr/iutfbleau/projetIHM2021FI2 # CHOIX NOMS JAR_MNP = test-mnp.jar # BUTS FACTICES # -.PHONY : run clean +.PHONY : run clean doc # BUT PAR DEFAUT # -run : ${BUILD}/MNP/JoueurNP.class - -# ${JAR_MNP} -# ${EXEC_JAR} ${JAR_MNP} +run : ${JAR_MNP} + ${EXEC_JAR} ${JAR_MNP} # AUTRE BUTS +doc : + javadoc -d doc src/fr/iutfbleau/projetIHM2021FI2/API/*.java src/fr/iutfbleau/projetIHM2021FI2/MNP/*.java + clean : rm -rf ${BUILD}/* *.jar @@ -30,19 +32,24 @@ clean : # REGLES DE DEPENDANCE # ## API ## +${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/Chambre.class : ${SRC}/API/Chambre.java \ - ${BUILD}/API/TypeChambre.class + ${BUILD}/API/TypeChambre.class\ + ${BUILD}/API/MonPrint.class ${JAVAC} ${JAVAC_OPTIONS} ${SRC}/API/Chambre.java -${BUILD}/API/Client.class : ${SRC}/API/Client.java +${BUILD}/API/Client.class : ${SRC}/API/Client.java \ + ${BUILD}/API/MonPrint.class ${JAVAC} ${JAVAC_OPTIONS} ${SRC}/API/Client.java ${BUILD}/API/Prereservation.class : ${SRC}/API/Prereservation.java \ ${BUILD}/API/TypeChambre.class \ - ${BUILD}/API/Client.class + ${BUILD}/API/Client.class ${JAVAC} ${JAVAC_OPTIONS} ${SRC}/API/Prereservation.java ${BUILD}/API/Reservation.class : ${SRC}/API/Reservation.java \ @@ -59,22 +66,34 @@ ${BUILD}/API/ReservationFactory.class : ${SRC}/API/ReservationFactory.java \ ## MNP ## -${BUILD}/MNP/JoueurNP.class : ${SRC}/MNP/ClientNP.java \ +${BUILD}/MNP/ClientNP.class : ${SRC}/MNP/ClientNP.java \ ${BUILD}/API/Client.class ${JAVAC} ${JAVAC_OPTIONS} ${SRC}/MNP/ClientNP.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}/API/Prereservation.class + ${JAVAC} ${JAVAC_OPTIONS} ${SRC}/MNP/PrereservationNP.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 ## TEST ## -# ${BUILD}/test/TestTexteMNP.class : ${SRC}/test/TestTexteMNP.java \ -# ${BUILD}/MNP/PassagePieceFactoryNP.class \ -# ${BUILD}/MNP/TrucFactoryNP.class \ -# ${BUILD}/MNP/JoueurNP.class -# ${JAVAC} ${JAVAC_OPTIONS} ${SRC}/test/TestTexteMNP.java - + ${BUILD}/Test/TestTexteMNP.class : ${SRC}/Test/TestTexteMNP.java \ + ${BUILD}/API/PrereservationFactory.class + ${JAVAC} -Xlint:deprecation ${JAVAC_OPTIONS} ${SRC}/Test/TestTexteMNP.java # ## JARS ## -# ${JAR_MNP} : ${BUILD}/test/TestTexteMNP.class -# ${JAR} cvfe ${JAR_MNP} fr.iutfbleau.projetIHM2020FI2.test.TestTexteMNP -C build fr + ${JAR_MNP} : ${BUILD}/Test/TestTexteMNP.class + ${JAR} cvfe ${JAR_MNP} fr.iutfbleau.projetIHM2021FI2.Test.TestTexteMNP -C build fr diff --git a/README.md b/README.md index e6b41d4..b869ea5 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,14 @@ # APIHotel -API pour le projet IHM 2021-2022. \ No newline at end of file +API pour le projet IHM 2021-2022. + +Vous avez un makefile qui permet de générer la javadoc en faisant. +$ make doc + +Vous pouvez ensuite naviguer dans la doc en commençant par le fichier doc/overview-tree.html + +Un petit fichier de test permet de mieux comprendre l'architecture. +Il faut faire +$ make run + +Ensuite vous pouvez aller lire les sources. diff --git a/src/fr/iutfbleau/projetIHM2021FI2/API/Chambre.java b/src/fr/iutfbleau/projetIHM2021FI2/API/Chambre.java index 1b91845..c7f8c79 100644 --- a/src/fr/iutfbleau/projetIHM2021FI2/API/Chambre.java +++ b/src/fr/iutfbleau/projetIHM2021FI2/API/Chambre.java @@ -3,7 +3,7 @@ package fr.iutfbleau.projetIHM2021FI2.API; * Une chambre */ -public interface Chambre { +public interface Chambre extends MonPrint { /** * permet de récupérer le numéro de la chambre. @@ -14,19 +14,43 @@ public interface Chambre { /** * permet de savoir si la chambre a un seul lit qui est simple * @return vrai si c'est le cas. + * @deprecated replaced by {@link #getType()} */ + @Deprecated public boolean unLitSimple(); /** * permet de savoir si la chambre a deux lits simples * @return vrai si c'est le cas. + * @deprecated replaced by {@link #getType()} */ + @Deprecated public boolean deuxLitsSimples(); /** * permet de savoir si la chambre a un lit double * @return vrai si c'est le cas. + * @deprecated replaced by {@link #getType()} */ + @Deprecated public boolean unLitDouble(); + /** + * @return le type de chambre (un type énuméré de l'API) + * + * NB. Les trois méthodes ci-dessus sont assez moches. + * De toute façon Chambre ou Prérerservation exposent le type énuméré TypeChambre à la vue. + * Il est donc plus simple d'ajouter des types de chambre à ce type énuméré plutôt que d'ajouter des tests ici. + * Je laisse les méthodes obsolètes pour illustrer l'annotation
@deprecated
de la javadoc. + */ + public TypeChambre getType(); + + /** + * @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("Chambre " + getNumero() + " ("+ getType() +")"); + } + } diff --git a/src/fr/iutfbleau/projetIHM2021FI2/API/Client.java b/src/fr/iutfbleau/projetIHM2021FI2/API/Client.java index 3ae2de9..e801889 100644 --- a/src/fr/iutfbleau/projetIHM2021FI2/API/Client.java +++ b/src/fr/iutfbleau/projetIHM2021FI2/API/Client.java @@ -4,7 +4,7 @@ package fr.iutfbleau.projetIHM2021FI2.API; * Un client */ -public interface Client { +public interface Client extends MonPrint{ /** * permet de récupérer l'identifiant du client (qu'on suppose être le même pour les différents systèmes, internes et externes à l'hôtel). @@ -24,4 +24,11 @@ public interface Client { */ 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/projetIHM2021FI2/API/MonPrint.java b/src/fr/iutfbleau/projetIHM2021FI2/API/MonPrint.java new file mode 100644 index 0000000..6d329b7 --- /dev/null +++ b/src/fr/iutfbleau/projetIHM2021FI2/API/MonPrint.java @@ -0,0 +1,12 @@ +package fr.iutfbleau.projetIHM2021FI2.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/projetIHM2021FI2/API/Prereservation.java b/src/fr/iutfbleau/projetIHM2021FI2/API/Prereservation.java index 01f3e94..ece8bf9 100644 --- a/src/fr/iutfbleau/projetIHM2021FI2/API/Prereservation.java +++ b/src/fr/iutfbleau/projetIHM2021FI2/API/Prereservation.java @@ -1,5 +1,5 @@ package fr.iutfbleau.projetIHM2021FI2.API; -import java.util.Date; +import java.time.LocalDate; /** * Une préréservation * @@ -7,7 +7,7 @@ import java.util.Date; * */ -public interface Prereservation { +public interface Prereservation extends MonPrint{ /** * permet de récupérer @@ -21,7 +21,7 @@ public interface Prereservation { * * A priori seule la date est importante, le reste est sans importance. */ - public Date getDateDebut(); + public LocalDate getDateDebut(); /** * permet de récupérer @@ -40,4 +40,14 @@ public interface Prereservation { * @return le client */ public Client getClient(); + + /** + * @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("Préréservation " + getReference() + ": " + getClient().monPrint() + " le " + getDateDebut().toString() + " pour " + getJours() + " nuit(s) "); + } + + } diff --git a/src/fr/iutfbleau/projetIHM2021FI2/API/TypeChambre.java b/src/fr/iutfbleau/projetIHM2021FI2/API/TypeChambre.java index f2c24bb..d1798da 100644 --- a/src/fr/iutfbleau/projetIHM2021FI2/API/TypeChambre.java +++ b/src/fr/iutfbleau/projetIHM2021FI2/API/TypeChambre.java @@ -1,4 +1,10 @@ package fr.iutfbleau.projetIHM2021FI2.API; public enum TypeChambre { - UNLS, DEUXLS, UNLD; + UNLS ("Un lit simple"), DEUXLS ("Deux lits simples"), UNLD ("Un lit double"); + + private final String name; + + private TypeChambre(String s) { + name = s; + } } diff --git a/src/fr/iutfbleau/projetIHM2021FI2/MNP/ChambreNP.java b/src/fr/iutfbleau/projetIHM2021FI2/MNP/ChambreNP.java new file mode 100644 index 0000000..16a2a47 --- /dev/null +++ b/src/fr/iutfbleau/projetIHM2021FI2/MNP/ChambreNP.java @@ -0,0 +1,76 @@ +package fr.iutfbleau.projetIHM2021FI2.MNP; +import fr.iutfbleau.projetIHM2021FI2.API.*; +import java.util.*; +/** + * Une chambre non persistante toute bête + */ + +public class ChambreNP implements Chambre{ + + private int numero; + private TypeChambre type; + + /** + * Constructeur + */ + public ChambreNP(int numero, TypeChambre t){ + Objects.requireNonNull(t,"On ne peut pas créer une chambre avec un type de chambre à null."); + this.numero=numero; + this.type=t; + } + + /** + * permet de récupérer le numéro de la chambre. + * @return le numéro. + */ + public int getNumero(){ + return this.numero; + } + + + /** + * permet de savoir si la chambre a un seul lit qui est simple + * @return vrai si c'est le cas. + */ + public boolean unLitSimple(){ + //https://stackoverflow.com/questions/1750435/comparing-java-enum-members-or-equals + return (this.type == TypeChambre.UNLS); + } + + /** + * permet de savoir si la chambre a deux lits simples + * @return vrai si c'est le cas. + */ + public boolean deuxLitsSimples(){ + return (this.type == TypeChambre.DEUXLS); + } + + /** + * permet de savoir si la chambre a un lit double + * @return vrai si c'est le cas. + */ + public boolean unLitDouble(){ + return (this.type == TypeChambre.UNLD); + } + + + /** + * @return le type de chambre (un type énuméré de l'API) + * + * NB. Les trois méthodes ci-dessus sont assez moches. + * De toute façon Chambre ou Prérerservation exposent le type énuméré TypeChambre à la vue. + * Il est donc plus simple d'ajouter des types de chambre à ce type énuméré plutôt que d'ajouter des tests ici. + * Je laisse les méthodes obsolètes pour illustrer l'annotation
@deprecated
de la javadoc. + */ + public TypeChambre getType(){ + return this.type; + } + + + // voir MonPrint dans l'interface Chambre + // @Override + // public String toString() { + // return String.format("Chambre " + this.numero + " ("+ this.type +")"); + // } + +} diff --git a/src/fr/iutfbleau/projetIHM2021FI2/MNP/ClientNP.java b/src/fr/iutfbleau/projetIHM2021FI2/MNP/ClientNP.java index 900da95..ba9ca80 100644 --- a/src/fr/iutfbleau/projetIHM2021FI2/MNP/ClientNP.java +++ b/src/fr/iutfbleau/projetIHM2021FI2/MNP/ClientNP.java @@ -2,7 +2,7 @@ package fr.iutfbleau.projetIHM2021FI2.MNP; import fr.iutfbleau.projetIHM2021FI2.API.*; import java.util.*; /** - * Un client non persistent tout bête + * Un client non persistant tout bête */ public class ClientNP implements Client { @@ -14,9 +14,9 @@ public class ClientNP implements Client { /** * Constructeur */ - public ClientNP(int id, String nom, String prenom){ + public ClientNP(int id, String prenom, String nom){ Objects.requireNonNull(nom,"On ne peut pas créer une personne avec un nom à null."); - Objects.requireNonNull(nom,"On ne peut pas créer une personne avec un prenom à null."); + Objects.requireNonNull(prenom,"On ne peut pas créer une personne avec un prenom à null."); this.id=id; this.nom=nom; this.prenom=prenom; @@ -46,4 +46,9 @@ public class ClientNP implements Client { return this.prenom; } + // voir interface MonPrint + // @Override + // public String toString() { + // return String.format("Nom " + this.nom + " Prenom " + this.prenom + " (id="+this.id+")"); + // } } diff --git a/src/fr/iutfbleau/projetIHM2021FI2/MNP/PrereservationFactoryNP.java b/src/fr/iutfbleau/projetIHM2021FI2/MNP/PrereservationFactoryNP.java new file mode 100644 index 0000000..91d0c8f --- /dev/null +++ b/src/fr/iutfbleau/projetIHM2021FI2/MNP/PrereservationFactoryNP.java @@ -0,0 +1,97 @@ +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 préréservation dans une structure de donnée permettant de simuler un ensemble. + * + * Elle permet de rechercher les préréservations à partir du numéro d'une préréservation, ou bien du nom et prenom d'un Client. + * + * La recherche par numéro devrait être plus efficace. + * + */ +public class PrereservationFactoryNP implements PrereservationFactory{ + + // plutôt que d'utiliser un ensemble, on utilise un HashMap car on suppose qu'on va devoir chercher + // plutôt les préréservations avec le numéro de référence (un String, voir Prereservation). + // Pour la recherche par nom et prenom on va devoir traverser le HashMap. + private HashMap brain =new HashMap();//Creating HashMap + + // ceci n'est pas nécessaire (ce constructeur existe par défaut). + // /** + // * Constructeur + // */ + // public PrereservationFactoryNP(){ + + // } + + /** + * Recherche une préréservation par reference + * @param r la référence du système de préréservation + * @return la préréservation. + * @throws NullPointerException si un argument est null + * @throws IllegalStateException si la Préréservation avec cette référence n'existe pas. + * + * Ne devrait pas retourner un objet null. + */ + public Prereservation getPrereservation(String r){ + Objects.requireNonNull(r,"La référence recherchée est null."); + if (this.brain.containsKey(r)){ + return this.brain.get(r); + } + else { + throw new IllegalStateException("Il n'y a pas de préréservation avec la référence : " + r); + } + } + /** + * Recherche une préréservation par nom et prenom + * @param n le nom + * @param p le prenom + * @return un ensemble de préréservations. + * @throws NullPointerException si un argument est null + * @throws IllegalStateException si aucune préréservation n'existe avec ce nom + * + * Ne devrait pas retourner un objet null ou un ensemble vide. + */ + public Set getPrereservations(String n, String p){ + Objects.requireNonNull(n,"Le nom recherché est null."); + Objects.requireNonNull(p,"Le prénom recherché est null."); + // on va extraire toutes les préréservations du cerveau + Collection c = this.brain.values(); + // on définit un prédicat sur les Préréservations : + Predicate filtre = preresa -> !preresa.getClient().getNom().equals(n) || !preresa.getClient().getPrenom().equals(p); + // on filtre la collection. + c.removeIf(filtre); + if (c.isEmpty()){ + throw new IllegalStateException("Il n'y a pas de préréservation avec un Client ayant pour nom et prenom : " + n + " et " + p); + } + // on fabrique un ensemble. + Set found = new HashSet(c); + return found; + } + + + // NB : jusqu'ici on ne dépend pas d'un choix particulier de Prereservation. + // La méthode ci-dessous utilise (de manière très marginale) PrereservationNP + // Elle assure que le cerveau (this.brain) contient au plus une prereservation pour une reference + + /** + * Utile pour faire des tests avec cette classe. + * A priori ne sert pas si on fait une version persistante + * @throws IllegalStateException si on connaît déjà une préréservation avec cette référence. + * @throws NullPointerException si un argument est null + * @throws IllegalArgumentException si jours < 1 + */ + public void ajoutePrereservation(String reference, LocalDate dateDebut, int jours, TypeChambre t, Client client){ + if (this.brain.containsKey(reference)){ + throw new IllegalStateException("Il y a déjà une préréservation avec cette référence : " + reference); + } + else { + Prereservation preresa = new PrereservationNP(reference, dateDebut, jours, t, client); + this.brain.put(reference,preresa); + } + } +} + + diff --git a/src/fr/iutfbleau/projetIHM2021FI2/MNP/PrereservationNP.java b/src/fr/iutfbleau/projetIHM2021FI2/MNP/PrereservationNP.java new file mode 100644 index 0000000..9bdde91 --- /dev/null +++ b/src/fr/iutfbleau/projetIHM2021FI2/MNP/PrereservationNP.java @@ -0,0 +1,88 @@ +package fr.iutfbleau.projetIHM2021FI2.MNP; +import fr.iutfbleau.projetIHM2021FI2.API.*; +import java.time.LocalDate; +import java.util.*; +/** + * Une préréservation non persitante toute bête + * + * e.g. utilisé par le système de réservation externe à l'hôtel. + * + */ + +public class PrereservationNP implements Prereservation { + + private String reference; + private LocalDate dateDebut; + private int jours; + private TypeChambre type; + private Client client; + + /** + * Constructeur + * + * NB. on force jours>0 et les autres attributs à ne pas être null + */ + public PrereservationNP(String reference, LocalDate dateDebut, int jours, TypeChambre t, Client client){ + Objects.requireNonNull(reference,"On ne peut pas créer une préréservation avec un reference à null."); + Objects.requireNonNull(dateDebut,"On ne peut pas créer une préréservation avec un date de début à null."); + if (jours<1) { + throw new IllegalArgumentException("On ne peut pas créer une réservation avec un nombre de jours négatif ou nul."); + } + Objects.requireNonNull(t,"On ne peut pas créer une préréservation avec un type de chambre à null."); + Objects.requireNonNull(client,"On ne peut pas créer une préréservation avec un client à null."); + this.reference=reference; + this.dateDebut=dateDebut; + + this.jours=jours; + this.type=t; + this.client=client; + } + + + /** + * permet de récupérer + * @return la référence. + */ + public String getReference(){ + return this.reference; + } + + /** + * permet de récupérer + * @return la date de début + * + * A priori seule la date est importante, le reste est sans importance. + */ + public LocalDate getDateDebut(){ + return this.dateDebut; + } + + /** + * permet de récupérer + * @return la durée en jours (mais comme un entier) + */ + public int getJours(){ + return this.jours; + } + + /** + * permet de récupérer + * @return le type de chambre + */ + public TypeChambre getTypeChambre(){ + return this.type; + } + + /** + * permet de récupérer + * @return le client + */ + public Client getClient(){ + return this.client; + } + + // @Override + // public String toString() { + // return String.format("Préréservation " + this.reference + " au nom de " + this.client + " le " + + " pour " + this.jours + " nuit(s) à partir du " + this.dateDebut); + // } +} diff --git a/src/fr/iutfbleau/projetIHM2021FI2/MNP/ReservationNP.java b/src/fr/iutfbleau/projetIHM2021FI2/MNP/ReservationNP.java new file mode 100644 index 0000000..442a324 --- /dev/null +++ b/src/fr/iutfbleau/projetIHM2021FI2/MNP/ReservationNP.java @@ -0,0 +1,87 @@ +package fr.iutfbleau.projetIHM2021FI2.MNP; +import fr.iutfbleau.projetIHM2021FI2.API.*; +import java.util.*; +/** + * Une Réservation non presistante toute bête + * + * e.g. utilisé par le système de réservation interne à l'hôtel. + * + */ + +public class ReservationNP implements Reservation { + + private String reference; + private Date dateDebut; + private int jours; + private Chambre chambre; + private Client client; + + /** + * Constructeur + * + * NB. on force jours>0 et les autres attributs à ne pas être null + */ + public ReservationNP(String reference, Date dateDebut, int jours, Chambre chambre, Client client){ + Objects.requireNonNull(reference,"On ne peut pas créer une réservation avec un reference à null."); + Objects.requireNonNull(dateDebut,"On ne peut pas créer une réservation avec un date de début à null."); + if (jours<1) { + throw new IllegalArgumentException("On ne peut pas créer une réservation avec un nombre de jours négatif ou nul."); + } + Objects.requireNonNull(chambre,"On ne peut pas créer une réservation avec une chambre à null."); + Objects.requireNonNull(client,"On ne peut pas créer une réservation avec un client à null."); + this.reference=reference; + this.dateDebut=dateDebut; + + this.jours=jours; + this.chambre=chambre; + this.client=client; + } + + + /** + * permet de récupérer + * @return la référence. + */ + public String getReference(){ + return this.reference; + } + + /** + * permet de récupérer + * @return la date de début + * + * A priori seule la date est importante, le reste est sans importance. + */ + public Date getDateDebut(){ + return this.dateDebut; + } + + /** + * permet de récupérer + * @return la durée en jours (mais comme un entier) + */ + public int getJours(){ + return this.jours; + } + + /** + * permet de récupérer + * @return le type de chambre + */ + public Chambre getChambre(){ + return this.chambre; + } + + /** + * permet de récupérer + * @return le client + */ + public Client getClient(){ + return this.client; + } +} + + + + + diff --git a/src/fr/iutfbleau/projetIHM2021FI2/Test/TestTexteMNP.java b/src/fr/iutfbleau/projetIHM2021FI2/Test/TestTexteMNP.java new file mode 100644 index 0000000..574bc9d --- /dev/null +++ b/src/fr/iutfbleau/projetIHM2021FI2/Test/TestTexteMNP.java @@ -0,0 +1,90 @@ +package fr.iutfbleau.projetIHM2021FI2.Test; +import fr.iutfbleau.projetIHM2021FI2.API.*; +import fr.iutfbleau.projetIHM2021FI2.MNP.*; +import java.time.LocalDate; +import java.util.*; + +public class TestTexteMNP{ + + + public static void main(String[] args) { + // morceaux de modèle + PrereservationFactoryNP bookingPointCom = new PrereservationFactoryNP(); + + Client c1 = new ClientNP(1,"Marine","Carpentier"); + Client c2 = new ClientNP(2, "Aaron","Dumas"); + Client c3 = new ClientNP(3, "Kimberley", "Leroux"); + Client c4 = new ClientNP(4, "Florentin", "Giraud"); + Client c5 = new ClientNP(5, "Martin", "Gillet"); + + bookingPointCom.ajoutePrereservation("4751-3708-LRFM", LocalDate.of(2018,1,5),1, TypeChambre.DEUXLS,c1); + bookingPointCom.ajoutePrereservation("2436-3909-NXLL", LocalDate.of(2018,01,07),1, TypeChambre.UNLS,c1); + bookingPointCom.ajoutePrereservation("1351-0775-BETZ", LocalDate.of(2018,01,05),2, TypeChambre.DEUXLS,c2); + bookingPointCom.ajoutePrereservation("3440-0631-NFCU", LocalDate.of(2018,01,06),2, TypeChambre.UNLD,c2); + bookingPointCom.ajoutePrereservation("1499-2254-DBIU", LocalDate.of(2018,01,04),2, TypeChambre.UNLS,c2); + bookingPointCom.ajoutePrereservation("5660-8953-YKJO", LocalDate.of(2018,01,06),2, TypeChambre.DEUXLS,c5); + + // une fois que le modèle de PrereservationFactoryNP a du contenu, je peux le caster en l'interface PreservationFactory de l'API correspondante pour que la vue s'en serve. + + PrereservationFactory bookingPointComAPISeulement = bookingPointCom; + System.out.print("Le modèle de Préréservation est prêt.\n"); + + + // TODO : Idem ici avec un modèle non persistant de Réservation. + + + // Normalement ce qu'il faut pour faire marcher la vue sont créées ci-dessous. + // Il faut probablement leur donner accès aux deux usines + // PrereservationFactory et ReservationFactory du modèle qu'on a fabriqué ci-dessus. + + // MaVue vue = new MaVue(bookingPointComAPISeulement) + + // puis démarrer la vue avec une méthode adaptée. + // vue.run(); + + System.out.print("Il n'y a pas de vue mais il faudrait le faire ici.\n"); + + // Notez que les objets du modèle créés ci-dessus sont tous castés en interfaces de l'API. + + // la vue doit donc utiliser seulement les méthodes publiques de l'API. + // On peut donc changer l'implémentation du modèle tant qu'on ne change pas l'API en préservant le bon fonctionement de la vue et du controleur. + // Pour l'instant, nous n'avons ni vue, ni controleur, mais nous pouvons faire semblant en interagissant avec le modèle via l'API. + + + System.out.print("Simulation manuelle du genre de chose que la vue pourrait faire.\n"); + + System.out.println("=========================="); + System.out.print("Hello Sir. Je cherche votre préreservation avec référence ZORGLUB\n"); + try{ + Prereservation preresa = bookingPointComAPISeulement.getPrereservation("ZORGLUB"); + } + catch(IllegalStateException e){ + System.out.print("I am sorry sir, no booking under this reference.\n"); + } + System.out.println("=========================="); + System.out.print("Hello Madam. Je cherche votre préreservation avec référence 2436-3909-NXLL\n"); + try{ + Prereservation preresa = bookingPointComAPISeulement.getPrereservation("2436-3909-NXLL"); + System.out.print("I found your booking.\n"); + System.out.println(preresa.monPrint()); + } + catch(IllegalStateException e){ + System.out.print("I am sorry sir, no booking under this reference.\n"); + } + System.out.println("=========================="); + System.out.print("Hello Madam. Vous avez oubliée votre numéro de préréservation. Ce n'est pas grave, je vais chercher avec votre nom et prénom.\n"); + System.out.print("Marine Carpentier? C-A-R-P-E-N-T-I-E-R? Un instant, je vous prie.\n"); + try{ + Set preresas = bookingPointComAPISeulement.getPrereservations("Carpentier","Marine"); + System.out.print("I found your bookings.\n"); + for(Prereservation p : preresas){ + System.out.println(p.monPrint()); + } + } + catch(IllegalStateException e){ + System.out.print("I am sorry Madam, no booking under this reference.\n"); + } + System.out.println("=========================="); + + } +}