Advertisement
Guest User

Untitled

a guest
May 29th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package Utilitaire;
  7.  
  8. import Modele.Compte;
  9. import java.io.File;
  10. import java.io.FileInputStream;
  11. import java.io.FileNotFoundException;
  12. import java.io.FileOutputStream;
  13. import java.io.IOException;
  14. import java.io.ObjectInputStream;
  15. import java.io.ObjectOutputStream;
  16. import java.io.Serializable;
  17. import java.util.List;
  18.  
  19. /**
  20. *
  21. * @author p1603766
  22. */
  23. public class Conteneur<Compte extends Serializable>{
  24. private int indiceCourant = 0;
  25. private List<Compte> lesValeurs;
  26.  
  27. public Conteneur(){
  28.  
  29. }
  30.  
  31. public Conteneur(List<Compte> m){
  32. this.lesValeurs = m;
  33. }
  34.  
  35. public void charger(String nomFic) throws FileNotFoundException, IOException, ClassNotFoundException{
  36. File CompteFile = new File(nomFic);
  37. FileInputStream fis = new FileInputStream(CompteFile);
  38. ObjectInputStream ois = new ObjectInputStream(fis);
  39. List<Compte> tab = (List<Compte>)ois.readObject();
  40. ois.close();
  41. this.lesValeurs = tab;
  42. }
  43.  
  44. public void dernier(){
  45. this.indiceCourant = this.lesValeurs.size()-1;
  46. }
  47.  
  48. public boolean estVide(){
  49. return lesValeurs.isEmpty();
  50. }
  51. public int nbElements(){
  52. return this.lesValeurs.size();
  53. }
  54.  
  55. public Compte obtenir(){
  56. return this.lesValeurs.get(indiceCourant);
  57. }
  58.  
  59. public void precedent(){
  60. this.indiceCourant--;
  61. }
  62.  
  63. public void premier(){
  64. this.indiceCourant = 0;
  65. }
  66.  
  67. public void sauvegarder(String nomFic) throws FileNotFoundException, IOException{
  68. File CompteFile = new File(nomFic);
  69. FileOutputStream fos = new FileOutputStream(CompteFile);
  70. ObjectOutputStream obs = new ObjectOutputStream(fos);
  71. obs.writeObject(this.lesValeurs);
  72.  
  73. obs.close();
  74. }
  75.  
  76. public void suivant(){
  77. this.indiceCourant++;
  78. }
  79.  
  80. public void vider(){
  81. this.lesValeurs.clear();
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement