Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. package fcul.pco.dentalclinic.persistence;
  2.  
  3. import java.io.BufferedWriter;
  4. import java.io.File;
  5. import java.io.FileNotFoundException;
  6. import java.io.FileWriter;
  7. import java.io.IOException;
  8. import java.util.ArrayList;
  9. import java.util.List;
  10. import java.util.Scanner;
  11.  
  12. import fcul.pco.dentalclinic.domain.Agenda;
  13. import fcul.pco.dentalclinic.domain.Appointment;
  14. import fcul.pco.dentalclinic.domain.Doctor;
  15. import fcul.pco.dentalclinic.main.ApplicationConfiguration;
  16.  
  17. public class AgendaPersistence {
  18.  
  19. public static void save(Doctor d) throws IOException {
  20. //metodo que grava as appointmenst da agenda de um doctor num ficheiro
  21. //na pasta data
  22. //com um appointment em cada linha do ficheiro
  23. //
  24. String id = Integer.toString(d.getId());
  25. String path = ApplicationConfiguration.ROOT_DIRECTORY;
  26.  
  27. List<Appointment> lista = new ArrayList<Appointment>();
  28. lista = d.getAgenda().getAppointements();
  29.  
  30. FileWriter fw = new FileWriter(path + id);
  31. BufferedWriter bw = new BufferedWriter(fw);
  32.  
  33. for(Appointment app : lista ) {
  34. String appointent = app.toString();
  35. bw.write(appointent);
  36. bw.newLine();
  37. }
  38. bw.close();
  39. fw.close();
  40. }
  41.  
  42. public static Agenda load (Doctor d) throws FileNotFoundException {
  43.  
  44. String id = Integer.toString(d.getId());
  45. String path = ApplicationConfiguration.ROOT_DIRECTORY;
  46. Agenda agenda = new Agenda();
  47. agenda = d.getAgenda();
  48. Scanner inputFromFile = new Scanner(new File(path + id));
  49. for (Appointment app : agenda.getAppointements()) {
  50. agenda.addAppointment(app);
  51. }
  52. inputFromFile.close();
  53. return agenda;
  54.  
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement