parent
7c8c185456
commit
3f431af7a9
@ -0,0 +1 @@
|
||||
Subproject commit 53d3626c450ef57e3c5019145feb31b3b4813946
|
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_18" project-jdk-name="18" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/tp1-intro.iml" filepath="$PROJECT_DIR$/tp1-intro.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
</project>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,2 @@
|
||||
Machin Truc
|
||||
Bidule Machin
|
@ -0,0 +1,21 @@
|
||||
package fr.uca.iut.clfreville2.tp1;
|
||||
|
||||
import fr.uca.iut.clfreville2.tp1.cli.CommandLineInterface;
|
||||
import fr.uca.iut.clfreville2.tp1.io.AfficheurConsole;
|
||||
import fr.uca.iut.clfreville2.tp1.io.SaisisseurConsole;
|
||||
import fr.uca.iut.clfreville2.tp1.model.Repertoire;
|
||||
import fr.uca.iut.clfreville2.tp1.persistance.FilePersistance;
|
||||
import fr.uca.iut.clfreville2.tp1.persistance.StubLoaderPersistance;
|
||||
|
||||
public final class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new CommandLineInterface(
|
||||
new StubLoaderPersistance(),
|
||||
new FilePersistance(),
|
||||
new Repertoire(),
|
||||
new AfficheurConsole(),
|
||||
new SaisisseurConsole()
|
||||
).execute();
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package fr.uca.iut.clfreville2.tp1.cli;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public enum Action {
|
||||
AJOUTER_PATIENT('a'),
|
||||
EDITER_PATIENT('e'),
|
||||
LISTER_PATIENTS('l'),
|
||||
SUPPRIMER_PATIENT('s'),
|
||||
QUITTER('q');
|
||||
|
||||
private final char identificateur;
|
||||
|
||||
Action(char identificateur) {
|
||||
this.identificateur = identificateur;
|
||||
}
|
||||
|
||||
public static Action fromIdentificateur(char c) {
|
||||
return Arrays.stream(values()).filter(a -> a.identificateur == c).findFirst().orElse(null);
|
||||
}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
package fr.uca.iut.clfreville2.tp1.cli;
|
||||
|
||||
import fr.uca.iut.clfreville2.tp1.io.Afficheur;
|
||||
import fr.uca.iut.clfreville2.tp1.io.Saisisseur;
|
||||
import fr.uca.iut.clfreville2.tp1.model.Patient;
|
||||
import fr.uca.iut.clfreville2.tp1.model.Repertoire;
|
||||
import fr.uca.iut.clfreville2.tp1.persistance.LoaderPersistance;
|
||||
import fr.uca.iut.clfreville2.tp1.persistance.WriterPersistance;
|
||||
|
||||
public final class CommandLineInterface {
|
||||
|
||||
private final Repertoire repertoire;
|
||||
private final Afficheur afficheur;
|
||||
private final Saisisseur saisisseur;
|
||||
private final LoaderPersistance loaderPersistance;
|
||||
private final WriterPersistance writerPersistance;
|
||||
|
||||
public CommandLineInterface(LoaderPersistance loaderPersistance, WriterPersistance writerPersistance, Repertoire repertoire, Afficheur afficheur, Saisisseur saisisseur) {
|
||||
this.repertoire = repertoire;
|
||||
this.afficheur = afficheur;
|
||||
this.saisisseur = saisisseur;
|
||||
this.loaderPersistance = loaderPersistance;
|
||||
this.writerPersistance = writerPersistance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exécute l'application en ligne de commande.
|
||||
*/
|
||||
public void execute() {
|
||||
loaderPersistance.lire(repertoire);
|
||||
afficheur.afficherIntroduction();
|
||||
afficheur.afficherDemande("l'action à effectuer");
|
||||
Action action;
|
||||
while ((action = saisisseur.demanderAction()) != Action.QUITTER) {
|
||||
if (action == null) {
|
||||
afficheur.afficherErreur("Action inconnue !");
|
||||
continue;
|
||||
}
|
||||
switch (action) {
|
||||
case AJOUTER_PATIENT -> gererAjoutPatient();
|
||||
case EDITER_PATIENT -> gererModificationPatient();
|
||||
case LISTER_PATIENTS -> afficheur.afficherPatients(repertoire);
|
||||
case SUPPRIMER_PATIENT -> gererSuppressionPatient();
|
||||
}
|
||||
}
|
||||
writerPersistance.ecrire(repertoire);
|
||||
}
|
||||
|
||||
private void gererAjoutPatient() {
|
||||
Patient patient = demanderInfosPatient();
|
||||
repertoire.referencerPatient(patient.prenom(), patient.nom());
|
||||
afficheur.afficherSucces("Le patient a bien été rajouté.");
|
||||
}
|
||||
|
||||
private void gererSuppressionPatient() {
|
||||
Patient patient = demanderInfosPatient();
|
||||
if (repertoire.dereferencerPatient(patient.prenom(), patient.nom())) {
|
||||
afficheur.afficherSucces("Le patient a bien été supprimé.");
|
||||
} else {
|
||||
afficheur.afficherErreur("Le patient n'existe pas et ne peut pas être supprimé.");
|
||||
}
|
||||
}
|
||||
|
||||
private void gererModificationPatient() {
|
||||
Patient patient = demanderInfosPatient();
|
||||
if (!repertoire.dereferencerPatient(patient.prenom(), patient.nom())) {
|
||||
afficheur.afficherErreur("Le patient n'existe pas et ne peut pas être édité.");
|
||||
return;
|
||||
}
|
||||
gererAjoutPatient();
|
||||
}
|
||||
|
||||
private Patient demanderInfosPatient() {
|
||||
afficheur.afficherDemande("le prénom du patient");
|
||||
String prenom = saisisseur.demandeMot();
|
||||
afficheur.afficherDemande("le nom du patient");
|
||||
String nom = saisisseur.demandeMot();
|
||||
return new Patient(prenom, nom);
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package fr.uca.iut.clfreville2.tp1.io;
|
||||
|
||||
import fr.uca.iut.clfreville2.tp1.model.Patient;
|
||||
import fr.uca.iut.clfreville2.tp1.model.Repertoire;
|
||||
|
||||
/**
|
||||
* Affiche des informations à l'écran.
|
||||
* <p>
|
||||
* Son implémentation principale est {@link AfficheurConsole}.
|
||||
*/
|
||||
public interface Afficheur {
|
||||
|
||||
/**
|
||||
* Affiche le texte présentant les actions réalisables par l'utilisateur.
|
||||
*/
|
||||
void afficherIntroduction();
|
||||
|
||||
/**
|
||||
* Affiche les informations d'un unique patient.
|
||||
*
|
||||
* @param patient Le patient à afficher.
|
||||
*/
|
||||
void afficherPatient(Patient patient);
|
||||
|
||||
/**
|
||||
* Affiche la liste des patients contenus dans un répertoire.
|
||||
* <p>
|
||||
* Par défaut, affiche un à un les patients.
|
||||
*
|
||||
* @param repertoire Le répertoire à utiliser.
|
||||
*/
|
||||
default void afficherPatients(Repertoire repertoire) {
|
||||
repertoire.getPatients().forEach(this::afficherPatient);
|
||||
}
|
||||
|
||||
/**
|
||||
* Préparer le texte de demande d'une information à l'utilisateur.
|
||||
*
|
||||
* @param objet L'objet de la demande.
|
||||
*/
|
||||
void afficherDemande(String objet);
|
||||
|
||||
/**
|
||||
* Affiche un message de succès.
|
||||
*
|
||||
* @param message Le message de succès.
|
||||
*/
|
||||
void afficherSucces(String message);
|
||||
|
||||
/**
|
||||
* Affiche un message d'erreur.
|
||||
*
|
||||
* @param message Le message d'erreur.
|
||||
*/
|
||||
void afficherErreur(String message);
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package fr.uca.iut.clfreville2.tp1.io;
|
||||
|
||||
import fr.uca.iut.clfreville2.tp1.model.Patient;
|
||||
import fr.uca.iut.clfreville2.tp1.model.Repertoire;
|
||||
|
||||
public class AfficheurConsole implements Afficheur {
|
||||
|
||||
private static final String DESCRIPTION_MENU = """
|
||||
Système de gestion des patients 3000
|
||||
====================================
|
||||
a : Ajouter un nouveau patient
|
||||
l : Lister les patients
|
||||
s : Supprimer un patient
|
||||
q : Quitter
|
||||
""";
|
||||
|
||||
@Override
|
||||
public void afficherIntroduction() {
|
||||
System.out.print(DESCRIPTION_MENU);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afficherPatient(Patient patient) {
|
||||
System.out.println(patient.designation());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afficherPatients(Repertoire repertoire) {
|
||||
if (repertoire.getPatients().isEmpty()) {
|
||||
System.out.println("Répertoire vide !");
|
||||
} else {
|
||||
Afficheur.super.afficherPatients(repertoire);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afficherDemande(String objet) {
|
||||
System.out.println("Veuillez saisir " + objet + " : ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afficherSucces(String message) {
|
||||
System.out.println(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afficherErreur(String message) {
|
||||
System.err.println(message);
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package fr.uca.iut.clfreville2.tp1.io;
|
||||
|
||||
import fr.uca.iut.clfreville2.tp1.cli.Action;
|
||||
|
||||
public interface Saisisseur {
|
||||
|
||||
String demandeMot();
|
||||
|
||||
Action demanderAction();
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package fr.uca.iut.clfreville2.tp1.io;
|
||||
|
||||
import fr.uca.iut.clfreville2.tp1.cli.Action;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class SaisisseurConsole implements Saisisseur {
|
||||
|
||||
private final Scanner scanner;
|
||||
|
||||
|
||||
public SaisisseurConsole() {
|
||||
this(System.in);
|
||||
}
|
||||
|
||||
public SaisisseurConsole(InputStream stream) {
|
||||
scanner = new Scanner(stream);
|
||||
}
|
||||
|
||||
public SaisisseurConsole(Reader reader) {
|
||||
scanner = new Scanner(reader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String demandeMot() {
|
||||
return scanner.next();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Action demanderAction() {
|
||||
return switch (scanner.next()) {
|
||||
case "a" -> Action.AJOUTER_PATIENT;
|
||||
case "e" -> Action.EDITER_PATIENT;
|
||||
case "l" -> Action.LISTER_PATIENTS;
|
||||
case "s" -> Action.SUPPRIMER_PATIENT;
|
||||
case "q" -> Action.QUITTER;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package fr.uca.iut.clfreville2.tp1.model;
|
||||
|
||||
// Pour les curieux, un record est une classe finale qui contient déjà une redéfinition de equals() et hashCode()
|
||||
public record Patient(String prenom, String nom) {
|
||||
|
||||
public String designation() {
|
||||
return prenom + " " + nom.toUpperCase();
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package fr.uca.iut.clfreville2.tp1.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Le répertoire possède toutes les informations de contact des patients.
|
||||
*/
|
||||
public class Repertoire implements Iterable<Patient> {
|
||||
|
||||
private final List<Patient> patients = new ArrayList<>();
|
||||
|
||||
public void referencerPatient(String prenom, String nom) {
|
||||
patients.add(new Patient(prenom, nom));
|
||||
}
|
||||
|
||||
public boolean dereferencerPatient(String prenom, String nom) {
|
||||
return patients.remove(new Patient(prenom, nom));
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère l'ensemble des patients répertoriés.
|
||||
*
|
||||
* @return Une vue immuable sur les patients.
|
||||
*/
|
||||
public List<Patient> getPatients() {
|
||||
return Collections.unmodifiableList(patients);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Patient> iterator() {
|
||||
return getPatients().iterator();
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package fr.uca.iut.clfreville2.tp1.persistance;
|
||||
|
||||
import fr.uca.iut.clfreville2.tp1.io.Saisisseur;
|
||||
import fr.uca.iut.clfreville2.tp1.io.SaisisseurConsole;
|
||||
import fr.uca.iut.clfreville2.tp1.model.Patient;
|
||||
import fr.uca.iut.clfreville2.tp1.model.Repertoire;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* Une persistance écrivant et lisant un fichier.
|
||||
*/
|
||||
public class FilePersistance implements Persistance {
|
||||
|
||||
private final String fileName;
|
||||
|
||||
public FilePersistance() {
|
||||
this("repertoire.txt");
|
||||
}
|
||||
|
||||
public FilePersistance(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lire(Repertoire repertoire) {
|
||||
try (Reader lecteur = new FileReader(fileName)) {
|
||||
Saisisseur saisisseur = new SaisisseurConsole(lecteur);
|
||||
repertoire.referencerPatient(saisisseur.demandeMot(), saisisseur.demandeMot());
|
||||
} catch (FileNotFoundException ignored) {
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ecrire(Repertoire repertoire) {
|
||||
try (Writer ecrivain = new FileWriter(fileName)) {
|
||||
for (Patient patient : repertoire.getPatients()) {
|
||||
ecrivain.append(patient.nom()).append(" ").append(patient.prenom()).append("\n");
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package fr.uca.iut.clfreville2.tp1.persistance;
|
||||
|
||||
import fr.uca.iut.clfreville2.tp1.model.Repertoire;
|
||||
|
||||
/**
|
||||
* Quelque chose capable de lire des données depuis quelque part et de les référencer dans un répertoire.
|
||||
*/
|
||||
public interface LoaderPersistance {
|
||||
|
||||
void lire(Repertoire repertoire);
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package fr.uca.iut.clfreville2.tp1.persistance;
|
||||
|
||||
import fr.uca.iut.clfreville2.tp1.model.Repertoire;
|
||||
|
||||
@SuppressWarnings("unused") // oui, mieux vaut ne pas l'utiliser de toute façon
|
||||
public class NoopWriterPersistance implements WriterPersistance {
|
||||
@Override
|
||||
public void ecrire(Repertoire repertoire) {
|
||||
// noop
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package fr.uca.iut.clfreville2.tp1.persistance;
|
||||
|
||||
/**
|
||||
* Un groupe de persistance pouvant être à la fois chargée et sauvegardée.
|
||||
*/
|
||||
public interface Persistance extends LoaderPersistance, WriterPersistance {
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package fr.uca.iut.clfreville2.tp1.persistance;
|
||||
|
||||
import fr.uca.iut.clfreville2.tp1.model.Repertoire;
|
||||
|
||||
public final class StubLoaderPersistance implements LoaderPersistance {
|
||||
|
||||
@Override
|
||||
public void lire(Repertoire repertoire) {
|
||||
repertoire.referencerPatient("Truc", "Machin");
|
||||
repertoire.referencerPatient("Machin", "Bidule");
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package fr.uca.iut.clfreville2.tp1.persistance;
|
||||
|
||||
import fr.uca.iut.clfreville2.tp1.model.Repertoire;
|
||||
|
||||
/**
|
||||
* Quelque chose capable d'écrire quelque part un répertoire de patients.
|
||||
*/
|
||||
public interface WriterPersistance {
|
||||
|
||||
void ecrire(Repertoire repertoire);
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_18" default="true" project-jdk-name="18" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/tp2-zoo.iml" filepath="$PROJECT_DIR$/tp2-zoo.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1 @@
|
||||
ours bidule 9 oiseau machin SUD 5 --end--
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,17 @@
|
||||
package fr.uca.iut.clfreville2.tp2;
|
||||
|
||||
import fr.uca.iut.clfreville2.tp2.cli.CommandLineInterface;
|
||||
import fr.uca.iut.clfreville2.tp2.io.*;
|
||||
import fr.uca.iut.clfreville2.tp2.persistance.FileReaderPersistance;
|
||||
import fr.uca.iut.clfreville2.tp2.persistance.FileWriterPersistance;
|
||||
|
||||
public final class Main {
|
||||
|
||||
private Main() {}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Afficheur afficheur = new AfficheurConsole();
|
||||
Saisisseur saisisseur = new SaisisseurConsole();
|
||||
new CommandLineInterface(afficheur, saisisseur, CommandLineInterface.commandes(), AnimalFromUserInputFactory.create(), new FileReaderPersistance(), new FileWriterPersistance()).executer();
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
package fr.uca.iut.clfreville2.tp2.cli;
|
||||
|
||||
import fr.uca.iut.clfreville2.tp2.cli.cmd.AjouterCommande;
|
||||
import fr.uca.iut.clfreville2.tp2.cli.cmd.CommandRegistry;
|
||||
import fr.uca.iut.clfreville2.tp2.cli.cmd.ListerCommande;
|
||||
import fr.uca.iut.clfreville2.tp2.cli.cmd.PasserCommande;
|
||||
import fr.uca.iut.clfreville2.tp2.factory.AnimalFactory;
|
||||
import fr.uca.iut.clfreville2.tp2.io.Afficheur;
|
||||
import fr.uca.iut.clfreville2.tp2.io.Saisisseur;
|
||||
import fr.uca.iut.clfreville2.tp2.modele.Animalerie;
|
||||
import fr.uca.iut.clfreville2.tp2.persistance.ReadPersistance;
|
||||
import fr.uca.iut.clfreville2.tp2.persistance.WritePersistance;
|
||||
|
||||
/**
|
||||
* Une interface en ligne de commande.
|
||||
*/
|
||||
public final class CommandLineInterface {
|
||||
|
||||
private final Afficheur afficheur;
|
||||
private final Saisisseur saisisseur;
|
||||
private final CommandRegistry commandes;
|
||||
private final Animalerie animalerie;
|
||||
private final AnimalFactory animalFactory;
|
||||
private final ReadPersistance readPersistance;
|
||||
private final WritePersistance writePersistance;
|
||||
private boolean quitter;
|
||||
|
||||
public CommandLineInterface(Afficheur afficheur, Saisisseur saisisseur, CommandRegistry commandes, AnimalFactory animalFactory, ReadPersistance readPersistance, WritePersistance writePersistance) {
|
||||
this.afficheur = afficheur;
|
||||
this.saisisseur = saisisseur;
|
||||
this.commandes = commandes;
|
||||
this.animalerie = new Animalerie();
|
||||
this.animalFactory = animalFactory;
|
||||
this.readPersistance = readPersistance;
|
||||
this.writePersistance = writePersistance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Réalise la boucle principale de l'application.
|
||||
*/
|
||||
public void executer() {
|
||||
readPersistance.lire(animalerie, animalFactory);
|
||||
while (!quitter) {
|
||||
commandes.rechercher(saisisseur.lireMot())
|
||||
.ifPresentOrElse(
|
||||
cmd -> cmd.run(this),
|
||||
() -> afficheur.afficherErreur("Action invalide")
|
||||
);
|
||||
}
|
||||
writePersistance.ecrire(animalerie, animalFactory);
|
||||
}
|
||||
|
||||
public Animalerie getAnimalerie() {
|
||||
return animalerie;
|
||||
}
|
||||
|
||||
public Afficheur getAfficheur() {
|
||||
return afficheur;
|
||||
}
|
||||
|
||||
public Saisisseur getSaisisseur() {
|
||||
return saisisseur;
|
||||
}
|
||||
|
||||
public AnimalFactory getAnimalFactory() {
|
||||
return animalFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prépare l'arrêt de l'application.
|
||||
*/
|
||||
public void stopper() {
|
||||
quitter = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Créé le registre des commandes.
|
||||
*
|
||||
* @return Un registre complété avec des actions courantes.
|
||||
*/
|
||||
public static CommandRegistry commandes() {
|
||||
CommandRegistry.Builder builder = CommandRegistry.builder();
|
||||
builder.enregistrer("quitter", CommandLineInterface::stopper);
|
||||
builder.enregistrer(ListerCommande.NOM, new ListerCommande());
|
||||
builder.enregistrer(AjouterCommande.NOM, new AjouterCommande());
|
||||
builder.enregistrer(PasserCommande.NOM, new PasserCommande());
|
||||
return builder.construire();
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package fr.uca.iut.clfreville2.tp2.cli.cmd;
|
||||
|
||||
import fr.uca.iut.clfreville2.tp2.cli.CommandLineInterface;
|
||||
import fr.uca.iut.clfreville2.tp2.modele.impl.Animal;
|
||||
|
||||
public class AjouterCommande implements Commande {
|
||||
|
||||
public static final String NOM = "ajouter";
|
||||
|
||||
@Override
|
||||
public void run(CommandLineInterface cli) {
|
||||
cli.getAfficheur().afficher("Quel genre d'animal ?");
|
||||
String genre = cli.getSaisisseur().lireMot();
|
||||
cli.getAfficheur().afficher("Quel est son nom ?");
|
||||
Animal animal = cli.getAnimalFactory().creer(genre, cli.getSaisisseur().lireMot(), cli.getAfficheur(), cli.getSaisisseur());
|
||||
cli.getAnimalerie().ajouter(animal);
|
||||
cli.getAfficheur().afficher("Animal rajouté !");
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package fr.uca.iut.clfreville2.tp2.cli.cmd;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface CommandRegistry {
|
||||
|
||||
Optional<Commande> rechercher(String nom);
|
||||
|
||||
static Builder builder() {
|
||||
return new CommandeRegistryImpl.ThisBuilder();
|
||||
}
|
||||
|
||||
interface Builder {
|
||||
|
||||
void enregistrer(String nom, Commande commande);
|
||||
|
||||
CommandRegistry construire();
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package fr.uca.iut.clfreville2.tp2.cli.cmd;
|
||||
|
||||
import fr.uca.iut.clfreville2.tp2.cli.CommandLineInterface;
|
||||
|
||||
/**
|
||||
* Une action réalisable depuis l'interface en ligne de commande.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface Commande {
|
||||
|
||||
/**
|
||||
* Exécute l'action dans le contexte de la ligne de commande.
|
||||
*
|
||||
* @param cli Contexte d'exécution.
|
||||
*/
|
||||
void run(CommandLineInterface cli);
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package fr.uca.iut.clfreville2.tp2.cli.cmd;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
class CommandeRegistryImpl implements CommandRegistry {
|
||||
|
||||
private final Map<String, Commande> commandes;
|
||||
|
||||
private CommandeRegistryImpl(Map<String, Commande> commandes) {
|
||||
this.commandes = commandes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Commande> rechercher(String nom) {
|
||||
return Optional.ofNullable(commandes.get(nom));
|
||||
}
|
||||
|
||||
static class ThisBuilder implements Builder {
|
||||
|
||||
private final Map<String, Commande> commandes = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void enregistrer(String nom, Commande commande) {
|
||||
commandes.put(nom, commande);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandRegistry construire() {
|
||||
return new CommandeRegistryImpl(commandes);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package fr.uca.iut.clfreville2.tp2.cli.cmd;
|
||||
|
||||
import fr.uca.iut.clfreville2.tp2.cli.CommandLineInterface;
|
||||
import fr.uca.iut.clfreville2.tp2.modele.impl.Animal;
|
||||
|
||||
public class ListerCommande implements Commande {
|
||||
|
||||
public static final String NOM = "lister";
|
||||
|
||||
@Override
|
||||
public void run(CommandLineInterface cli) {
|
||||
if (cli.getAnimalerie().estVide()) {
|
||||
cli.getAfficheur().afficher("Aucun animal");
|
||||
}
|
||||
for (Animal animal : cli.getAnimalerie()) {
|
||||
cli.getAfficheur().afficher(animal.getPresentation());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package fr.uca.iut.clfreville2.tp2.cli.cmd;
|
||||
|
||||
import fr.uca.iut.clfreville2.tp2.cli.CommandLineInterface;
|
||||
import fr.uca.iut.clfreville2.tp2.modele.Climat;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PasserCommande implements Commande {
|
||||
|
||||
public static final String NOM = "passer";
|
||||
|
||||
@Override
|
||||
public void run(CommandLineInterface cli) {
|
||||
cli.getAfficheur().afficher("Quelle saison climatique (" + Arrays.stream(Climat.values()).map(Climat::name).collect(Collectors.joining("/")) + ") ?");
|
||||
Climat climat = cli.getSaisisseur().lireClimat();
|
||||
cli.getAnimalerie().passer(climat);
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
package fr.uca.iut.clfreville2.tp2.factory;
|
||||
|
||||
import fr.uca.iut.clfreville2.tp2.io.Afficheur;
|
||||
import fr.uca.iut.clfreville2.tp2.io.Saisisseur;
|
||||
import fr.uca.iut.clfreville2.tp2.modele.impl.Animal;
|
||||
|
||||
/**
|
||||
* Construit un animal d'après son genre.
|
||||
*
|
||||
* @implNote Implémentation principale {@link AnimalFactoryImpl}.
|
||||
*/
|
||||
public interface AnimalFactory {
|
||||
|
||||
/**
|
||||
* Construit un animal d'après son genre et son nom.
|
||||
* <p>
|
||||
* La factory peut éventuellement utiliser un afficheur et un saisisseur, voir les détails d'implémentations si nécessaire.
|
||||
*
|
||||
* @throws IllegalArgumentException Si le genre est inconnu.
|
||||
*/
|
||||
Animal creer(String genre, String nom, Afficheur afficheur, Saisisseur saisisseur);
|
||||
|
||||
/**
|
||||
* Associe à un animal son genre, utilisable pour créer une nouvelle instance du même type.
|
||||
*
|
||||
* @param animal L'animal pour lequel rechercher le genre.
|
||||
* @return Le type de l'animal.
|
||||
* @throws IllegalArgumentException Si le genre est inconnu.
|
||||
*/
|
||||
String trouverGenre(Animal animal);
|
||||
|
||||
/**
|
||||
* Créé un concepteur vide pour cette factory.
|
||||
*
|
||||
* @return Un concepteur vide.
|
||||
*/
|
||||
static AnimalFactory.Builder builder() {
|
||||
return new AnimalFactoryImpl.ThisBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Un concepteur de {@link AnimalFactory}.
|
||||
* <p>
|
||||
* Une factory est d'abord construite pour un certain nombre d'animaux et est ensuite figée.
|
||||
*/
|
||||
interface Builder {
|
||||
|
||||
/**
|
||||
* Enregistre une façon d'obtenir un animal d'un certain type d'après un genre.
|
||||
*
|
||||
* @param genre Le genre (s'il existe déjà, alors la précédente valeur est remplacée).
|
||||
* @param animalSupplier Le moyen d'obtenir cet animal.
|
||||
* @param animalType Le type qui sera instancié de l'animal.
|
||||
* @param <T> Le type de l'animal.
|
||||
*/
|
||||
<T extends Animal> void enregistrer(String genre, AnimalSupplier<T> animalSupplier, Class<T> animalType);
|
||||
|
||||
/**
|
||||
* Fige le concepteur et créé la factory.
|
||||
*
|
||||
* @return Une nouvelle factory.
|
||||
*/
|
||||
AnimalFactory construire();
|
||||
}
|
||||
|
||||
/**
|
||||
* Un moyen d'obtenir un animal.
|
||||
*
|
||||
* @param <T> Le type final (donc celui qui sera instancié) de l'animal.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
interface AnimalSupplier<T extends Animal> {
|
||||
|
||||
/**
|
||||
* Créé l'animal.
|
||||
*
|
||||
* @param nom Le nom à attribuer à cet animal.
|
||||
* @param afficheur L'afficheur à potentiellement utiliser.
|
||||
* @param saisisseur Le saisisseur à potentiellement utiliser.
|
||||
* @return Un nouvel animal.
|
||||
*/
|
||||
T create(String nom, Afficheur afficheur, Saisisseur saisisseur);
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package fr.uca.iut.clfreville2.tp2.factory;
|
||||
|
||||
import fr.uca.iut.clfreville2.tp2.io.Afficheur;
|
||||
import fr.uca.iut.clfreville2.tp2.io.Saisisseur;
|
||||
import fr.uca.iut.clfreville2.tp2.modele.impl.Animal;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
class AnimalFactoryImpl implements AnimalFactory {
|
||||
|
||||
private final Map<String, AnimalSupplier<?>> createur;
|
||||
private final Map<Class<? extends Animal>, String> decomposeur;
|
||||
|
||||
private AnimalFactoryImpl(Map<String, AnimalSupplier<?>> createur, Map<Class<? extends Animal>, String> decomposeur) {
|
||||
this.createur = new HashMap<>(createur);
|
||||
this.decomposeur = new HashMap<>(decomposeur);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Animal creer(String genre, String nom, Afficheur afficheur, Saisisseur saisisseur) {
|
||||
return createur.getOrDefault(genre, (a, b, c) -> {
|
||||
throw new IllegalArgumentException("Genre d'animal inconnu");
|
||||
}).create(nom, afficheur, saisisseur);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String trouverGenre(Animal animal) {
|
||||
String name = decomposeur.get(animal.getClass());
|
||||
if (name == null) {
|
||||
throw new IllegalArgumentException("Genre d'animal inconnu");
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
static class ThisBuilder implements AnimalFactory.Builder {
|
||||
|
||||
private final Map<String, AnimalSupplier<?>> createur = new HashMap<>();
|
||||
private final Map<Class<? extends Animal>, String> decomposeur = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public <T extends Animal> void enregistrer(String genre, AnimalSupplier<T> animalSupplier, Class<T> animalType) {
|
||||
createur.put(genre, animalSupplier);
|
||||
decomposeur.put(animalType, genre);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnimalFactory construire() {
|
||||
return new AnimalFactoryImpl(createur, decomposeur);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package fr.uca.iut.clfreville2.tp2.io;
|
||||
|
||||
/**
|
||||
* Quelque chose qui permet de présenter des informations à l'utilisateur.
|
||||
*/
|
||||
public interface Afficheur {
|
||||
|
||||
void afficher(String message);
|
||||
|
||||
void afficherErreur(String message);
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package fr.uca.iut.clfreville2.tp2.io;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class AfficheurConsole implements Afficheur {
|
||||
|
||||
private final PrintStream fluxStandard = System.out;
|
||||
private final PrintStream fluxErreur = System.err;
|
||||
|
||||
@Override
|
||||
public void afficher(String message) {
|
||||
fluxStandard.println(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afficherErreur(String message) {
|
||||
fluxErreur.println(message);
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package fr.uca.iut.clfreville2.tp2.io;
|
||||
|
||||
import fr.uca.iut.clfreville2.tp2.factory.AnimalFactory;
|
||||
import fr.uca.iut.clfreville2.tp2.modele.Lieu;
|
||||
import fr.uca.iut.clfreville2.tp2.modele.impl.Oiseau;
|
||||
import fr.uca.iut.clfreville2.tp2.modele.impl.Ours;
|
||||
|
||||
/**
|
||||
* Fournit une pré-selection d'animaux pour créer une {@link AnimalFactory}.
|
||||
*/
|
||||
public final class AnimalFromUserInputFactory {
|
||||
|
||||
private AnimalFromUserInputFactory() {}
|
||||
|
||||
public static AnimalFactory create() {
|
||||
AnimalFactory.Builder builder = AnimalFactory.builder();
|
||||
builder.enregistrer("ours", (nom, afficheur, saisisseur) -> {
|
||||
afficheur.afficher("Combien de poils ?");
|
||||
return new Ours(nom, saisisseur.lireInt());
|
||||
}, Ours.class);
|
||||
builder.enregistrer("oiseau", (nom, afficheur, saisisseur) -> {
|
||||
afficheur.afficher("Quel lieu actuel ?");
|
||||
Lieu lieu = saisisseur.lireLieu();
|
||||
afficheur.afficher("Combien de plumes ?");
|
||||
return new Oiseau(nom, lieu, saisisseur.lireInt());
|
||||
}, Oiseau.class);
|
||||
return builder.construire();
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package fr.uca.iut.clfreville2.tp2.io;
|
||||
|
||||
public class NoopAfficheur implements Afficheur {
|
||||
@Override
|
||||
public void afficher(String message) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afficherErreur(String message) {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package fr.uca.iut.clfreville2.tp2.io;
|
||||
|
||||
import fr.uca.iut.clfreville2.tp2.modele.Climat;
|
||||
import fr.uca.iut.clfreville2.tp2.modele.Lieu;
|
||||
|
||||
/**
|
||||
* Quelque chose qui permet de récupérer des informations.
|
||||
*/
|
||||
public interface Saisisseur {
|
||||
|
||||
String lireMot();
|
||||
|
||||
int lireInt();
|
||||
|
||||
Climat lireClimat();
|
||||
|
||||
Lieu lireLieu();
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package fr.uca.iut.clfreville2.tp2.io;
|
||||
|
||||
import fr.uca.iut.clfreville2.tp2.modele.Climat;
|
||||
import fr.uca.iut.clfreville2.tp2.modele.Lieu;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class SaisisseurConsole implements Saisisseur {
|
||||
|
||||
private final Scanner scanner;
|
||||
|
||||
public SaisisseurConsole(Reader reader) {
|
||||
scanner = new Scanner(reader);
|
||||
}
|
||||
|
||||
public SaisisseurConsole() {
|
||||
this.scanner = new Scanner(System.in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String lireMot() {
|
||||
return scanner.next();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int lireInt() {
|
||||
return scanner.nextInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Climat lireClimat() {
|
||||
return lireEnum(Climat.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Lieu lireLieu() {
|
||||
return lireEnum(Lieu.class);
|
||||
}
|
||||
|
||||
private <E extends Enum<E>> E lireEnum(Class<E> enumClass) {
|
||||
return Enum.valueOf(enumClass, lireMot());
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package fr.uca.iut.clfreville2.tp2.modele;
|
||||
|
||||
import fr.uca.iut.clfreville2.tp2.modele.comportement.SubitClimat;
|
||||
import fr.uca.iut.clfreville2.tp2.modele.impl.Animal;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class Animalerie implements SubitClimat, Iterable<Animal> {
|
||||
|
||||
private final List<Animal> animaux = new ArrayList<>();
|
||||
|
||||
public List<Animal> getAnimaux() {
|
||||
return Collections.unmodifiableList(animaux);
|
||||
}
|
||||
|
||||
public void ajouter(Animal animal) {
|
||||
animaux.add(animal);
|
||||
}
|
||||
|
||||
public boolean estVide() {
|
||||
return animaux.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void passer(Climat climat) {
|
||||
animaux.forEach(a -> a.passer(climat));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Animal> iterator() {
|
||||
return getAnimaux().iterator();
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package fr.uca.iut.clfreville2.tp2.modele;
|
||||
|
||||
public enum Climat {
|
||||
|
||||
ETE,
|
||||
AUTOMNE,
|
||||
HIVER,
|
||||
PRINTEMPS
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package fr.uca.iut.clfreville2.tp2.modele;
|
||||
|
||||
import fr.uca.iut.clfreville2.tp2.modele.comportement.SubitClimat;
|
||||
|
||||
public interface EtreVivant extends SubitClimat {
|
||||
|
||||
String getPresentation();
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package fr.uca.iut.clfreville2.tp2.modele;
|
||||
|
||||
public enum Lieu {
|
||||
|
||||
NORD,
|
||||
SUD
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue