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
@deprecatedde 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
@deprecatedde 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